From 3965e4a8f5bf7de8a9bbf44063e756bdfe879cf2 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Thu, 4 Apr 2019 21:06:41 -0500 Subject: [PATCH] Update 'main.c' --- main.c | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/main.c b/main.c index b25d77d..642d94b 100644 --- a/main.c +++ b/main.c @@ -18,24 +18,32 @@ #include "Vex_Competition_Includes.c" // some variable definitions -#define MAX_SPEED 127 -#define STOP 0 +#define MAX_SPEED 127 // Max speed of the motors +#define STOP 0 #define DEADZONE 10 /* - 23.4 / (2 * pi * 2.075) * 360 + 23.4 / (2 * pi * 2.075) * 672.2 23.4 = inches in a tile 2.075 = exact radius of 4" omniwheels 2 * pi * r is circumference of the wheel - 360 degrees in a circle - final calculation is the amount of degrees of rotation per tile of movement + 627.2 points in a revolution with the vex encoders + 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() { motor[shoot] = MAX_SPEED; - wait(1.25); // Shooting takes 1.25 seconds. - motor[shoot] = STOP; + wait(1.25); // Shooting takes 1.25 seconds. + // Any unwanted extra movement will be undone by the rubber bands. + motor[shoot] = STOP; } void clearEnc(); void joystickDrive() { @@ -54,7 +62,7 @@ void joystickDrive() { else { motor[driveRB] = STOP; motor[driveRF] = STOP; - } + } } void buttonChecks() { @@ -67,10 +75,9 @@ void buttonChecks() { else { motor[bintake] = STOP; } - //Flipper Code if (vexRT[Btn8D] == 1) { shootBall(); - } + } // No need for reverse on the ball launcher! } @@ -82,9 +89,10 @@ void pre_auton() { bStopTasksBetweenModes = true; } -void driveTiles(int numberOfTiles, bool direction) { +void driveTiles(int numberOfTiles, bool direction) { + // when direction is true, move forward, otherwise go in reverse clearEnc(); - while(direction && numberOfTiles * TILE > nMotorEncoder[1]) { + while(direction == FORWARD && numberOfTiles * TILE > nMotorEncoder[1]) { if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) { motor[driveLB] = 100; motor[driveLF] = 100; @@ -103,7 +111,7 @@ void driveTiles(int numberOfTiles, bool direction) { motor[driveRF] = 100; } } - while(!direction && numberOfTiles * TILE > nMotorEncoder[1]) { + while(direction == REVERSE && numberOfTiles * TILE > nMotorEncoder[1]) { if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) { motor[driveLB] = -100; motor[driveLF] = -100; @@ -129,28 +137,27 @@ void driveTiles(int numberOfTiles, bool direction) { } task autonomous() { shootBall(); - driveTiles(2, true); + driveTiles(2, true); // Move 2 forward to hit bottom flag //driveTiles(1, false); } void turnRight(int turns) { - while(turns * 360 < nMotorEncoder[1]){ + while(turns * POINTS_PER_TURN < nMotorEncoder[1]){ } } 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[2] = 0; } -task usercontrol() { +task usercontrol() { // In user control mode while (true) { - //Dual Driving - joystickDrive(); - buttonChecks(); + joystickDrive(); // Joystick mapping function + buttonChecks(); // Button mapping, for lift, ball launcher, etc. } } \ No newline at end of file