-
Notifications
You must be signed in to change notification settings - Fork 3
ReRun
At the end of the 2016-17 season, VEX Starstruck, we reviewed what had we done right and what we needed to improve on for the 2017-18 season. One of the aspects we decided on improving upon was our autonomous mode. In the previous season, our autonomous was both difficult to change and inaccurate. We decided that we would implement two new methods into our autonomous. A ‘rerun’ function, and a sensor based self-correcting mode. The rerun function would feature the ability to record a user’s actions, store them, and play them back accurately. To do this, I decided to record the inputs and store them in a two-dimensional array, a vector.
int cache[6][600]The cache is the two-dimensional array. The [6] represents how many inputs it takes in. The [600] is where I store the input values. It is 600 because the values update 4 times a seccond and the autonomous is 15 secconds long.
void recordDrive() { // Record driver input while allowing driver control
delay(1);
cache[1][DriveTimer] = joystickGetAnalog(1, 2);// Get analog value of vertical axis of right stick, joystick 1
cache[2][DriveTimer] = joystickGetAnalog(1, 4); // Get analog value of vertical axis of left stick, joystick 1
cache[3][DriveTimer] = joystickGetDigital(1,5,JOY_UP); // Get boolean value of upper right bumper
cache[4][DriveTimer] = joystickGetDigital(1,5,JOY_DOWN); // Get boolean value of lower right bumper
cache[5][DriveTimer] = joystickGetDigital(1,6,JOY_UP); // Get boolean value of upper left bumper
cache[6][DriveTimer] = joystickGetDigital(1,6,JOY_DOWN); // Get boolean value of lower left bumper*/
}The recordDrive function is how the data is stored. It allows the data to be stored while also allowing driver control over the robot. The delay is for redundancy. Cache[1] specifies that I am recording the analog Y axis input of the right stick on the first controller. The [DriveTimer] is to store what time the data is recorded, so that it can be replayed in the same order and frequency.
void playbackDrive() { // Set motor to array values
delay(1);
motorSet(2, -cache[1][DriveTimer]);
motorSet(3, -cache[1][DriveTimer]);
motorSet(4, cache[2][DriveTimer]);
motorSet(5, cache[2][DriveTimer]);
}This function takes the stored input values and sets them to the corresponding motors. The delay is for redundancy.
void setMode() { // Check buttons to set mode
delay(1);
if (joystickGetDigital(1,7,JOY_DOWN) == 1){// If you push the lower button, turn on recording
RecSwitch = 1;
DriveTimer = 0;
}
if (joystickGetDigital(1,7,JOY_RIGHT) == 1){// If you push the right button, turn on normal drive
RecSwitch = 2;
DriveTimer = 0;
}
if (joystickGetDigital(1,7,JOY_LEFT) == 1){// If you push the left button, turn on playback from cache
RecSwitch = 3;
DriveTimer = 0;
setCache();
}
if (joystickGetDigital(1,7,JOY_UP)){ // If you push the upper button, turn off recording NOT USABLE
RecSwitch = 0;
}
if (RecSwitch == 1) { // Begin Record function
recordDrive();
updateDrive();
} // End Record function
if (RecSwitch == 2) { // Begin normal drive function
updateDrive();
}
if (RecSwitch == 3) { // Begin normal drive function
playbackDrive();
}
if (RecSwitch == 0) { // Begin playback function
playbackDrive();
}
}(the function was too large to fit onto the page, had to compress it) This function sets the mode of the program. The modes include record, playback, user control, and a placeholder for future functions. If a button is pushed on the controller, the RecSwitch value is changed to an integer (0,1,2,3).
void operatorControl() { //Motor documentation, 1-2 left joystick, 3-4 right joystick, Left Claw 8 Right Claw 9
while (1) {
setMode();
clawSync();
updateSensors();
//printf("Value is %d, time is %d \n", J1C2[DriveTimer], DriveTimer);
//printf("J1C2[%d] = %d \n", DriveTimer, J1C2[DriveTimer]); //Print statements formatted so that copy-paste will work
//printf("J1C3[%d] = %d \n", DriveTimer, J1C3[DriveTimer]);
printf("left value %d \n", leftencodervalue);
printf("right value %d \n", rightencodervalue);
DriveTimer =+ 1; // Record time
delay(50); // Wait for refresh
}
}This loop brings everything together. It runs all the necessary functions, in a much cleaner way than in my previous seasons. Debug code placeholders are also included.