Update 'main.c'

master
Cole Deck 6 years ago
parent bd3601271d
commit 79b42cae9a

123
main.c

@ -33,19 +33,61 @@
#define TILE 1206 #define TILE 1206
// How much the wheels should spin in a 90 degree turn // How much the wheels should spin in a 90 degree turn
#define POINTS_PER_TURN 360 #define POINTS_PER_TURN 320
// definitions for driveTiles() // definitions for driveTiles()
#define FORWARD true #define FORWARD true
#define REVERSE false #define REVERSE false
void clearEnc() { // Reset driving motor encoder values to 0
nMotorEncoder[driveRB] = 0;
nMotorEncoder[driveLB] = 0;
}
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. // Any unwanted extra movement will be undone by the rubber bands.
motor[shoot] = STOP; motor[shoot] = STOP;
} }
void clearEnc(); void turntoRight(float turns) {
clearEnc();
while(turns * POINTS_PER_TURN > nMotorEncoder[driveLB]){
motor[driveLB] = 100;
motor[driveLF] = 100;
motor[driveRB] = -100;
motor[driveRF] = -100;
}
motor[driveLB] = 0;
motor[driveLF] = 0;
motor[driveRB] = 0;
motor[driveRF] = 0;
}
void turntoLeft(float turns) {
clearEnc();
while(turns * POINTS_PER_TURN > nMotorEncoder[driveRB]){
motor[driveLB] = -100;
motor[driveLF] = -100;
motor[driveRB] = 100;
motor[driveRF] = 100;
}
motor[driveLB] = 0;
motor[driveLF] = 0;
motor[driveRB] = 0;
motor[driveRF] = 0;
}
void flipOn() {
motor[bintake] = -MAX_SPEED;
}
void ballOff() {
motor[bintake] = 0;
}
void ballIn() {
motor[bintake] = MAX_SPEED;
}
void joystickDrive() { void joystickDrive() {
if(abs(vexRT[Ch3]) > DEADZONE) { if(abs(vexRT[Ch3]) > DEADZONE) {
motor[driveLB] = vexRT[Ch3]; motor[driveLB] = vexRT[Ch3];
@ -89,17 +131,17 @@ void pre_auton() {
bStopTasksBetweenModes = true; bStopTasksBetweenModes = true;
} }
void driveTiles(int numberOfTiles, bool direction) { void driveTiles(float numberOfTiles, bool direction) {
// when direction is true, move forward, otherwise go in reverse // when direction is true, move forward, otherwise go in reverse
clearEnc(); clearEnc();
while(direction == FORWARD && numberOfTiles * TILE > nMotorEncoder[1]) { while(direction == FORWARD && numberOfTiles * TILE - 200 > nMotorEncoder[driveRB]) {
if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) { if(abs(nMotorEncoder[driveRB]) - 10 > nMotorEncoder[driveLB]) {
motor[driveLB] = 100; motor[driveLB] = 100;
motor[driveLF] = 100; motor[driveLF] = 100;
motor[driveRB] = 90; motor[driveRB] = 90;
motor[driveRF] = 90; motor[driveRF] = 90;
} }
if(abs(nMotorEncoder[2]) - 10 > nMotorEncoder[1]) { if(abs(nMotorEncoder[driveLB]) - 10 > nMotorEncoder[driveRB]) {
motor[driveLB] = 90; motor[driveLB] = 90;
motor[driveLF] = 90; motor[driveLF] = 90;
motor[driveRB] = 100; motor[driveRB] = 100;
@ -111,14 +153,14 @@ void driveTiles(int numberOfTiles, bool direction) {
motor[driveRF] = 100; motor[driveRF] = 100;
} }
} }
while(direction == REVERSE && numberOfTiles * TILE > nMotorEncoder[1]) { while(direction == REVERSE && numberOfTiles * TILE - 200 > -nMotorEncoder[driveRB]) {
if(abs(nMotorEncoder[1]) - 10 > nMotorEncoder[2]) { if(abs(nMotorEncoder[driveRB]) - 10 > nMotorEncoder[driveLB]) {
motor[driveLB] = -100; motor[driveLB] = -100;
motor[driveLF] = -100; motor[driveLF] = -100;
motor[driveRB] = -90; motor[driveRB] = -90;
motor[driveRF] = -90; motor[driveRF] = -90;
} }
if(abs(nMotorEncoder[2]) - 10 > nMotorEncoder[1]) { if(abs(nMotorEncoder[driveLB]) - 10 > nMotorEncoder[driveLB]) {
motor[driveLB] = -90; motor[driveLB] = -90;
motor[driveLF] = -90; motor[driveLF] = -90;
motor[driveRB] = -100; motor[driveRB] = -100;
@ -136,54 +178,43 @@ void driveTiles(int numberOfTiles, bool direction) {
motor[driveRF] = 0; motor[driveRF] = 0;
} }
task autonomous() { task autonomous() {
turntoRight(0.05);
shootBall(); shootBall();
turntoLeft(0.05);
driveTiles(2, FORWARD); // Move 2 forward to hit bottom flag driveTiles(2, FORWARD); // Move 2 forward to hit bottom flag
driveTiles(1, REVERSE); driveTiles(1, REVERSE);
turnRight(1); turntoRight(1);
driveTiles(0.33, REVERSE); // Drive 1/3 of a tile backwards to hit the wall and align ourselves! driveTiles(0.5, REVERSE); // Drive 1/3 of a tile backwards to hit the wall and align ourselves!
flipOn(); // Turn on the ball intake in reverse, which is what we can use to flip the caps flipOn(); // Turn on the ball intake in reverse, which is what we can use to flip the caps
driveTiles(1.25, FORWARD); // flip cap driveTiles(1.5, FORWARD); // flip cap
ballOff(); ballOff();
driveTiles(1.25, REVERSE);
turntoLeft(1);
driveTiles(1, REVERSE); driveTiles(1, REVERSE);
turnLeft(1); turntoRight(1);
driveTiles(1, REVERSE); driveTiles(0.6, REVERSE);
turnRight(1);
driveTiles(0.33, REVERSE);
driveTiles(2.5, FORWARD); // Flip the other cap without turning on the spinner driveTiles(2.5, FORWARD); // Flip the other cap without turning on the spinner
flipOn();
driveTiles(0.5, FORWARD);
driveTiles(0.1, FORWARD);
ballIn(); // So we can pick up the ball! ballIn(); // So we can pick up the ball!
delay(1000); wait(3);
driveTiles(0.1, FORWARD); driveTiles(0.1, FORWARD);
turnLeft(1); turntoLeft(1);
driveTiles(0.33, REVERSE); driveTiles(0.25, REVERSE);
delay(1000); wait(3);
ballOff(); ballOff();
shootBall(); shootBall();
driveTiles(2.2, FORWARD); // Hit middle column bottom flag driveTiles(0.25, FORWARD); // Hit middle column bottom flag
//driveTiles(2, REVERSE);
} turntoRight(1);
void turnRight(int turns) { driveTiles(2.5, REVERSE);
while(turns * POINTS_PER_TURN < nMotorEncoder[1]){ turntoLeft(1);
driveTiles(1, REVERSE);
} turntoRight(1);
} driveTiles(0.25, REVERSE);
void turnLeft(int turns) { driveTiles(3, FORWARD);
while(turns * POINTS_PER_TURN < nMotorEncoder[1]){
}
}
void clearEnc() { // Reset driving motor encoder values to 0
nMotorEncoder[1] = 0;
nMotorEncoder[2] = 0;
}
void flipOn() {
motor[bintake] = -MAX_SPEED;
}
void ballOff() {
motor[bintake] = 0;
}
void ballIn() {
motor[bintake] = MAX_SPEED;
} }
task usercontrol() { // In user control mode task usercontrol() { // In user control mode
while (true) { while (true) {

Loading…
Cancel
Save