Update 'main.c'

master
Cole Deck 6 years ago
parent f72cd3546c
commit 3965e4a8f5

@ -18,23 +18,31 @@
#include "Vex_Competition_Includes.c" #include "Vex_Competition_Includes.c"
// some variable definitions // some variable definitions
#define MAX_SPEED 127 #define MAX_SPEED 127 // Max speed of the motors
#define STOP 0 #define STOP 0
#define DEADZONE 10 #define DEADZONE 10
/* /*
23.4 / (2 * pi * 2.075) * 360 23.4 / (2 * pi * 2.075) * 672.2
23.4 = inches in a tile 23.4 = inches in a tile
2.075 = exact radius of 4" omniwheels 2.075 = exact radius of 4" omniwheels
2 * pi * r is circumference of the wheel 2 * pi * r is circumference of the wheel
360 degrees in a circle 627.2 points in a revolution with the vex encoders
final calculation is the amount of degrees of rotation per tile of movement final calculation is the amount of points of rotation per tile of movement
*/ */
#define TILE 646 #define TILE 1206
// How much the wheels should spin in a 90 degree turn
#define POINTS_PER_TURN 360
// definitions for driveTiles()
#define FORWARD true
#define REVERSE false
void shootBall() { void shootBall() {
motor[shoot] = MAX_SPEED; motor[shoot] = MAX_SPEED;
wait(1.25); // Shooting takes 1.25 seconds. wait(1.25); // Shooting takes 1.25 seconds.
// Any unwanted extra movement will be undone by the rubber bands.
motor[shoot] = STOP; motor[shoot] = STOP;
} }
void clearEnc(); void clearEnc();
@ -67,10 +75,9 @@ void buttonChecks() {
else { else {
motor[bintake] = STOP; motor[bintake] = STOP;
} }
//Flipper Code
if (vexRT[Btn8D] == 1) { if (vexRT[Btn8D] == 1) {
shootBall(); shootBall();
} } // No need for reverse on the ball launcher!
} }
@ -83,8 +90,9 @@ void pre_auton() {
} }
void driveTiles(int numberOfTiles, bool direction) { void driveTiles(int numberOfTiles, bool direction) {
// when direction is true, move forward, otherwise go in reverse
clearEnc(); clearEnc();
while(direction && numberOfTiles * TILE > nMotorEncoder[1]) { while(direction == FORWARD && numberOfTiles * TILE > nMotorEncoder[1]) {
if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) { if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) {
motor[driveLB] = 100; motor[driveLB] = 100;
motor[driveLF] = 100; motor[driveLF] = 100;
@ -103,7 +111,7 @@ void driveTiles(int numberOfTiles, bool direction) {
motor[driveRF] = 100; motor[driveRF] = 100;
} }
} }
while(!direction && numberOfTiles * TILE > nMotorEncoder[1]) { while(direction == REVERSE && numberOfTiles * TILE > nMotorEncoder[1]) {
if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) { if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) {
motor[driveLB] = -100; motor[driveLB] = -100;
motor[driveLF] = -100; motor[driveLF] = -100;
@ -129,28 +137,27 @@ void driveTiles(int numberOfTiles, bool direction) {
} }
task autonomous() { task autonomous() {
shootBall(); shootBall();
driveTiles(2, true); driveTiles(2, true); // Move 2 forward to hit bottom flag
//driveTiles(1, false); //driveTiles(1, false);
} }
void turnRight(int turns) { void turnRight(int turns) {
while(turns * 360 < nMotorEncoder[1]){ while(turns * POINTS_PER_TURN < nMotorEncoder[1]){
} }
} }
void turnLeft(int turns) { void turnLeft(int turns) {
while(turns * 360 < nMotorEncoder[1]){ while(turns * POINTS_PER_TURN < nMotorEncoder[1]){
} }
} }
void clearEnc() { void clearEnc() { // Reset driving motor encoder values to 0
nMotorEncoder[1] = 0; nMotorEncoder[1] = 0;
nMotorEncoder[2] = 0; nMotorEncoder[2] = 0;
} }
task usercontrol() { task usercontrol() { // In user control mode
while (true) { while (true) {
//Dual Driving joystickDrive(); // Joystick mapping function
joystickDrive(); buttonChecks(); // Button mapping, for lift, ball launcher, etc.
buttonChecks();
} }
} }
Loading…
Cancel
Save