Example Autonomous Routines
Assumed Constants​
These are default speeds that we can use throughout our autonomous routines to make it easier to modify them retroactively.
const int DRIVE_SPEED = 110;
const int TURN_SPEED = 90;
const int SWING_SPEED = 90;
Drive​
This autonomous routine will have the robot go forwards for 24 inches with slew enabled, come back -12 inches, then come back another -12 inches to where it started. It will do all of this at the predefined DRIVE_SPEED
.
void drive_example() {
// The first parameter is target inches
// The second parameter is max speed the robot will drive at
// The third parameter is a boolean (true or false) for enabling/disabling a slew at the start of drive motions
// for slew, only enable it when the drive distance is greater then the slew distance + a few inches
chassis.set_drive_pid(24, DRIVE_SPEED, true);
chassis.wait_drive();
chassis.set_drive_pid(-12, DRIVE_SPEED);
chassis.wait_drive();
chassis.set_drive_pid(-12, DRIVE_SPEED);
chassis.wait_drive();
}
Turn​
This autonomous routine will turn 90 degrees, then back 45 degrees, and finally to 0 where it started. It will do all of this at the predefined TURN_SPEED
.
void turn_example() {
// The first parameter is target degrees
// The second parameter is max speed the robot will drive at
chassis.set_turn_pid(90, TURN_SPEED);
chassis.wait_drive();
chassis.set_turn_pid(45, TURN_SPEED);
chassis.wait_drive();
chassis.set_turn_pid(0, TURN_SPEED);
chassis.wait_drive();
}
Drive and Turn​
This autonomous routine will combine driving and turning in a single function.
void drive_and_turn() {
chassis.set_drive_pid(24, DRIVE_SPEED, true);
chassis.wait_drive();
chassis.set_turn_pid(45, TURN_SPEED);
chassis.wait_drive();
chassis.set_turn_pid(-45, TURN_SPEED);
chassis.wait_drive();
chassis.set_turn_pid(0, TURN_SPEED);
chassis.wait_drive();
chassis.set_drive_pid(-24, DRIVE_SPEED, true);
chassis.wait_drive();
}