|
|
|
@ -38,7 +38,7 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define DRIVE_OFFSET 10
|
|
|
|
|
/* Defines the offset used to correct and curves while the robot is driving straight during the
|
|
|
|
|
/* Defines the offset used to correct curves while the robot is driving straight during the
|
|
|
|
|
driveTiles(float numberOfTiles, bool direction) function.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
@ -119,11 +119,10 @@ void turntoRight(float turns) {
|
|
|
|
|
}
|
|
|
|
|
stopDriving();
|
|
|
|
|
}
|
|
|
|
|
// Explicit Parameters: None
|
|
|
|
|
// Output: These three functions manage the ball lift and, conveniently, the same motors in reverse
|
|
|
|
|
// will flip a cap. flipOn() will spin the motors in the direction needed to flip caps, ballIn()
|
|
|
|
|
// will spin the motors in the direction needed to collect and pick up balls, and ballOff() will turn off the motors.
|
|
|
|
|
|
|
|
|
|
// Explicit Parameters: A floating point number turns will control how much the robot will turn to the right.
|
|
|
|
|
// When turns is set to 1, the robot will turn exactly 90 degrees. Since it is a floating point number, we can
|
|
|
|
|
// specify decimal amounts to turns to allow for any angle of a turn.
|
|
|
|
|
// Output: The robot will turn by (turns * 90) degrees to the right.
|
|
|
|
|
|
|
|
|
|
void turntoLeft(float turns) {
|
|
|
|
|
clearEnc();
|
|
|
|
@ -135,6 +134,11 @@ void turntoLeft(float turns) {
|
|
|
|
|
}
|
|
|
|
|
stopDriving();
|
|
|
|
|
}
|
|
|
|
|
// Explicit Parameters: A floating point number turns will control how much the robot will turn to the left.
|
|
|
|
|
// When turns is set to 1, the robot will turn exactly 90 degrees. Since it is a floating point number, we can
|
|
|
|
|
// specify decimal amounts to turns to allow for any angle of a turn.
|
|
|
|
|
// Output: The robot will turn by (turns * 90) degrees to the left.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void flipOn() {
|
|
|
|
@ -146,6 +150,11 @@ void ballOff() {
|
|
|
|
|
void ballIn() {
|
|
|
|
|
motor[bintake] = MAX_SPEED;
|
|
|
|
|
}
|
|
|
|
|
// Explicit Parameters: None
|
|
|
|
|
// Output: These three functions manage the ball lift and, conveniently, the same motors in reverse will
|
|
|
|
|
// flip a cap. flipOn() will spin the motors in the direction needed to flip caps, ballIn() will spin the
|
|
|
|
|
// motors in the direction needed to collect and pick up balls, and ballOff() will turn off the motors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void joystickDrive() {
|
|
|
|
|
if(abs(vexRT[Ch3]) > DEADZONE) {
|
|
|
|
@ -165,6 +174,12 @@ void joystickDrive() {
|
|
|
|
|
motor[driveRF] = STOP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Explicit Parameters: None
|
|
|
|
|
// Output: The robot will drive based on the values read from the 2 joysticks on the controller. However,
|
|
|
|
|
// if the joystick’s value is inside the DEADZONE (10) then the robot will not move. This prevents wasted
|
|
|
|
|
// battery and motor overheating when the robot is not supposed to be moving. This is necessary because when
|
|
|
|
|
// the joysticks are let go they don’t read a value of exactly zero, it’s usually off by a few.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void buttonChecks() {
|
|
|
|
|
if (vexRT[Btn5U] == 1) {
|
|
|
|
@ -180,7 +195,9 @@ void buttonChecks() {
|
|
|
|
|
shootBall();
|
|
|
|
|
} // No need for reverse on the ball launcher!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Explicit Parameters: None
|
|
|
|
|
// Output: When the corresponding buttons are pressed, various features will be activated, such as the cap
|
|
|
|
|
// flipper or the ball launcher. When the buttons are released, the action is stopped.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pre_auton() {
|
|
|
|
@ -189,6 +206,7 @@ void pre_auton() {
|
|
|
|
|
manage all user created tasks if set to false. */
|
|
|
|
|
bStopTasksBetweenModes = true;
|
|
|
|
|
}
|
|
|
|
|
// Auto-generated ROBOTC autonomous function
|
|
|
|
|
|
|
|
|
|
void driveTiles(float numberOfTiles, bool direction) {
|
|
|
|
|
// when direction is true, move forward, otherwise go in reverse
|
|
|
|
@ -233,13 +251,20 @@ void driveTiles(float numberOfTiles, bool direction) {
|
|
|
|
|
}
|
|
|
|
|
stopDriving();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Explicit Parameters: A floating point number numberOfTurns that represents the number of tiles that the
|
|
|
|
|
// robot is to drive. Since it is a floating point number, we can move by half or any fraction movement.
|
|
|
|
|
// There is also the boolean value direction that controls which way the robot is to move. true is for forward,
|
|
|
|
|
// and false is for reverse.
|
|
|
|
|
// Output: The robot will drive the specified amount of tiles, in the specified direction. If the robot is not driving
|
|
|
|
|
// straight, the speeds of the left and right motors can be offset from each other to cancel out any slight drifts
|
|
|
|
|
// to the left or right. We subtract 200 from the distance no matter what here, because the robot moves
|
|
|
|
|
// that much after it is told to stop.
|
|
|
|
|
|
|
|
|
|
task autonomous() {
|
|
|
|
|
turntoRight(0.03);
|
|
|
|
|
shootBall();
|
|
|
|
|
turntoLeft(0.03);
|
|
|
|
|
driveTiles(2, FORWARD); // Move 2 forward to hit bottom flag
|
|
|
|
|
turntoRight(0.03);
|
|
|
|
|
shootBall();
|
|
|
|
|
turntoLeft(0.03);
|
|
|
|
|
driveTiles(2, FORWARD); // Move 2 forward to hit bottom flag
|
|
|
|
|
driveTiles(1, REVERSE);
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(0.5, REVERSE); // Drive 1/3 of a tile backwards to hit the wall and align ourselves!
|
|
|
|
@ -252,11 +277,10 @@ task autonomous() {
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(0.6, REVERSE);
|
|
|
|
|
driveTiles(2.1, FORWARD); // Flip the other cap without turning on the spinner
|
|
|
|
|
flipOn();
|
|
|
|
|
flipOn(); // So we can pick up the ball that's under it!
|
|
|
|
|
driveTiles(0.5, FORWARD);
|
|
|
|
|
ballIn();
|
|
|
|
|
driveTiles(0.1, REVERSE);
|
|
|
|
|
// So we can pick up the ball!
|
|
|
|
|
wait(3);
|
|
|
|
|
driveTiles(0.1, REVERSE);
|
|
|
|
|
turntoLeft(1);
|
|
|
|
@ -267,18 +291,52 @@ task autonomous() {
|
|
|
|
|
driveTiles(0.05, REVERSE);
|
|
|
|
|
driveTiles(0.33, FORWARD);
|
|
|
|
|
wait(2);
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(2.2, REVERSE);
|
|
|
|
|
turntoLeft(1);
|
|
|
|
|
driveTiles(1, REVERSE);
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(0.25, REVERSE);
|
|
|
|
|
driveTiles(3, FORWARD);
|
|
|
|
|
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(2.2, REVERSE);
|
|
|
|
|
turntoLeft(1);
|
|
|
|
|
driveTiles(1, REVERSE);
|
|
|
|
|
turntoRight(1);
|
|
|
|
|
driveTiles(0.25, REVERSE);
|
|
|
|
|
driveTiles(3, FORWARD);
|
|
|
|
|
}
|
|
|
|
|
task usercontrol() { // In user control mode
|
|
|
|
|
/*
|
|
|
|
|
This is the autonomous task. Here’s the path of the robot, described in words instead of code:
|
|
|
|
|
|
|
|
|
|
1. Start at the red tile closest to the flags.
|
|
|
|
|
|
|
|
|
|
2. Turn a tiny bit to the right to aim, and shoot the top flag with our preload.
|
|
|
|
|
|
|
|
|
|
3. Re-align ourselves and drive to hit the bottom flag.
|
|
|
|
|
|
|
|
|
|
4. Back up 1 tile, turn right, and back into the wall to align the robot.
|
|
|
|
|
|
|
|
|
|
5. Drive forward with the flipper turned on, and flip the cap from blue to red.
|
|
|
|
|
|
|
|
|
|
6. Back up, turn left, reverse 1 tile, turn right, back into the wall again to align ourselves.
|
|
|
|
|
|
|
|
|
|
7. Drive forward, push the cap off of the ball, turn of the flipper and flip the cap.
|
|
|
|
|
|
|
|
|
|
8. Run the motors to lift the ball up to the ball launcher. We wait a few seconds for the ball.
|
|
|
|
|
|
|
|
|
|
9. Turn to the left, wait a bit more, and shoot the top flag in the middle column of flags.
|
|
|
|
|
|
|
|
|
|
10. Turn right, back up to the starting tile, then turn left.
|
|
|
|
|
|
|
|
|
|
11. Reverse for 1 tile to be perpendicular with the platforms.
|
|
|
|
|
|
|
|
|
|
12. Turn to face the parking platforms, and reverse into the wall to align ourselves again.
|
|
|
|
|
|
|
|
|
|
13. Climb to the middle parking platform and stop.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task usercontrol() {
|
|
|
|
|
while (true) {
|
|
|
|
|
joystickDrive(); // Joystick mapping function
|
|
|
|
|
buttonChecks(); // Button mapping, for lift, ball launcher, etc.
|
|
|
|
|
joystickDrive();
|
|
|
|
|
buttonChecks();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// When the driver is in control, this task runs. For the entire duration of the driver control period, we need
|
|
|
|
|
// to be able to control the robot, so we put everything in a while loop. The task calls 2 previously mentioned
|
|
|
|
|
// functions, joystickDrive() and buttonChecks().
|
|
|
|
|
|
|
|
|
|