|
|
|
@ -19,9 +19,10 @@
|
|
|
|
|
|
|
|
|
|
// some variable definitions
|
|
|
|
|
#define MAX_SPEED 127 // Max speed of the motors
|
|
|
|
|
#define MAX_AUTO_SPEED 100 // Max speed of the driving motors during the autonomous code
|
|
|
|
|
#define STOP 0
|
|
|
|
|
#define DEADZONE 10
|
|
|
|
|
|
|
|
|
|
#define DRIVE_OFFSET 10
|
|
|
|
|
/*
|
|
|
|
|
23.4 / (2 * pi * 2.075) * 672.2
|
|
|
|
|
23.4 = inches in a tile
|
|
|
|
@ -39,6 +40,13 @@
|
|
|
|
|
#define FORWARD true
|
|
|
|
|
#define REVERSE false
|
|
|
|
|
|
|
|
|
|
void stopDriving() { // Stop all driving motors
|
|
|
|
|
motor[driveLB] = STOP;
|
|
|
|
|
motor[driveLF] = STOP;
|
|
|
|
|
motor[driveRB] = STOP;
|
|
|
|
|
motor[driveRF] = STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearEnc() { // Reset driving motor encoder values to 0
|
|
|
|
|
nMotorEncoder[driveRB] = 0;
|
|
|
|
|
nMotorEncoder[driveLB] = 0;
|
|
|
|
@ -53,28 +61,22 @@ void shootBall() {
|
|
|
|
|
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] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveLF] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRB] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRF] = -MAX_AUTO_SPEED;
|
|
|
|
|
}
|
|
|
|
|
motor[driveLB] = 0;
|
|
|
|
|
motor[driveLF] = 0;
|
|
|
|
|
motor[driveRB] = 0;
|
|
|
|
|
motor[driveRF] = 0;
|
|
|
|
|
stopDriving();
|
|
|
|
|
}
|
|
|
|
|
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] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveLF] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRB] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRF] = MAX_AUTO_SPEED;
|
|
|
|
|
}
|
|
|
|
|
motor[driveLB] = 0;
|
|
|
|
|
motor[driveLF] = 0;
|
|
|
|
|
motor[driveRB] = 0;
|
|
|
|
|
motor[driveRF] = 0;
|
|
|
|
|
stopDriving();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -82,7 +84,7 @@ void flipOn() {
|
|
|
|
|
motor[bintake] = -MAX_SPEED;
|
|
|
|
|
}
|
|
|
|
|
void ballOff() {
|
|
|
|
|
motor[bintake] = 0;
|
|
|
|
|
motor[bintake] = STOP;
|
|
|
|
|
}
|
|
|
|
|
void ballIn() {
|
|
|
|
|
motor[bintake] = MAX_SPEED;
|
|
|
|
@ -135,48 +137,47 @@ void driveTiles(float numberOfTiles, bool direction) {
|
|
|
|
|
// when direction is true, move forward, otherwise go in reverse
|
|
|
|
|
clearEnc();
|
|
|
|
|
while(direction == FORWARD && numberOfTiles * TILE - 200 > nMotorEncoder[driveRB]) {
|
|
|
|
|
if(abs(nMotorEncoder[driveRB]) - 10 > nMotorEncoder[driveLB]) {
|
|
|
|
|
motor[driveLB] = 100;
|
|
|
|
|
motor[driveLF] = 100;
|
|
|
|
|
motor[driveRB] = 90;
|
|
|
|
|
motor[driveRF] = 90;
|
|
|
|
|
if(abs(nMotorEncoder[driveRB]) - DRIVE_OFFSET > nMotorEncoder[driveLB]) {
|
|
|
|
|
motor[driveLB] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveLF] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRB] = MAX_AUTO_SPEED - DRIVE_OFFSET;
|
|
|
|
|
motor[driveRF] = MAX_AUTO_SPEED - DRIVE_OFFSET;
|
|
|
|
|
}
|
|
|
|
|
if(abs(nMotorEncoder[driveLB]) - 10 > nMotorEncoder[driveRB]) {
|
|
|
|
|
motor[driveLB] = 90;
|
|
|
|
|
motor[driveLF] = 90;
|
|
|
|
|
motor[driveRB] = 100;
|
|
|
|
|
motor[driveRF] = 100;
|
|
|
|
|
if(abs(nMotorEncoder[driveLB]) - DRIVE_OFFSET > nMotorEncoder[driveRB]) {
|
|
|
|
|
motor[driveLB] = MAX_AUTO_SPEED - DRIVE_OFFSET;
|
|
|
|
|
motor[driveLF] = MAX_AUTO_SPEED - DRIVE_OFFSET;
|
|
|
|
|
motor[driveRB] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRF] = MAX_AUTO_SPEED;
|
|
|
|
|
} else {
|
|
|
|
|
motor[driveLB] = 100;
|
|
|
|
|
motor[driveLF] = 100;
|
|
|
|
|
motor[driveRB] = 100;
|
|
|
|
|
motor[driveRF] = 100;
|
|
|
|
|
motor[driveLB] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveLF] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRB] = MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRF] = MAX_AUTO_SPEED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while(direction == REVERSE && numberOfTiles * TILE - 200 > -nMotorEncoder[driveRB]) {
|
|
|
|
|
if(abs(nMotorEncoder[driveRB]) - 10 > nMotorEncoder[driveLB]) {
|
|
|
|
|
motor[driveLB] = -100;
|
|
|
|
|
motor[driveLF] = -100;
|
|
|
|
|
motor[driveRB] = -90;
|
|
|
|
|
motor[driveRF] = -90;
|
|
|
|
|
if(abs(nMotorEncoder[driveRB]) - DRIVE_OFFSET > nMotorEncoder[driveLB]) {
|
|
|
|
|
motor[driveLB] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveLF] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRB] = -MAX_AUTO_SPEED + DRIVE_OFFSET;
|
|
|
|
|
motor[driveRF] = -MAX_AUTO_SPEED + DRIVE_OFFSET;
|
|
|
|
|
}
|
|
|
|
|
if(abs(nMotorEncoder[driveLB]) - 10 > nMotorEncoder[driveLB]) {
|
|
|
|
|
motor[driveLB] = -90;
|
|
|
|
|
motor[driveLF] = -90;
|
|
|
|
|
motor[driveRB] = -100;
|
|
|
|
|
motor[driveRF] = -100;
|
|
|
|
|
if(abs(nMotorEncoder[driveLB]) - DRIVE_OFFSET > nMotorEncoder[driveLB]) {
|
|
|
|
|
motor[driveLB] = -MAX_AUTO_SPEED + DRIVE_OFFSET;
|
|
|
|
|
motor[driveLF] = -MAX_AUTO_SPEED + DRIVE_OFFSET;
|
|
|
|
|
motor[driveRB] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRF] = -MAX_AUTO_SPEED;
|
|
|
|
|
} else {
|
|
|
|
|
motor[driveLB] = -100;
|
|
|
|
|
motor[driveLF] = -100;
|
|
|
|
|
motor[driveRB] = -100;
|
|
|
|
|
motor[driveRF] = -100;
|
|
|
|
|
motor[driveLB] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveLF] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRB] = -MAX_AUTO_SPEED;
|
|
|
|
|
motor[driveRF] = -MAX_AUTO_SPEED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
motor[driveLB] = 0;
|
|
|
|
|
motor[driveLF] = 0;
|
|
|
|
|
motor[driveRB] = 0;
|
|
|
|
|
motor[driveRF] = 0;
|
|
|
|
|
stopDriving();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task autonomous() {
|
|
|
|
|
turntoRight(0.03);
|
|
|
|
|
shootBall();
|
|
|
|
@ -207,8 +208,7 @@ task autonomous() {
|
|
|
|
|
ballOff();
|
|
|
|
|
shootBall();
|
|
|
|
|
driveTiles(0.05, REVERSE);
|
|
|
|
|
driveTiles(0.33, FORWARD); // Hit middle column bottom flag
|
|
|
|
|
//driveTiles(2, REVERSE);
|
|
|
|
|
driveTiles(0.33, FORWARD);
|
|
|
|
|
wait(2);
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(2.2, REVERSE);
|
|
|
|
|