Skip to content

Editing the PER Autonomous Code

Noxilus edited this page Feb 21, 2018 · 1 revision

Editing the auto code:

The autonomous Routines are written as std::vector<std::vector<double>> which is to say lists of lists of numbers. The Routine vector is iterated through, using each inside list as a Step. Each Step's contents are its parameters. In order, these are type number, measurementA, ... , measurementN (as applicable), speedA, ... , speedN (as applicable). Some Steps require no measurements or speeds, such as Step 8, which shifts down the drive gears. When the robot is initialized in Autonomous, it reads in the FMS data and the position switch values to set the autoSteps vector to be equal to the correct Routine.

Editing or adding an existing Step in a Routine:

If you need to change the speed or measurement of any Step, just replace the corresponding number in the corresponding Step. Refer to the guidelines in Robot::RunSteps() or below for more information on what each number means for each existing Step type.

If you need to add an entirely new Step, create a new line within the Routine and fill in curly braces with the correct values. See the guidelines for more information on how to change each Step. Make sure that all Steps in a Routine (except for the last one) are followed by a comma, because these are lists and not separate commands. Do not include any semicolons except at the very end of a Routine definition (i.e. after the very last curly brace in the set).

How all the steps work:

0: Test Lifter {0} -> Was only for testing, do not use this

1: Gyro Turn {1, angle, speed} -> Turns the robot to the target angle at speed. The speed should be positive, the angle should realistically be between -90 and 90 degrees.

2: Encoder Move {2, distance, speed} -> Moves the robot towards the specified distance relative to its current position. The speed should be positive. The distance is measured in inches.

3: Run Lifter {3, stage} -> Moves the lifter from its current position to the specified stage. 0 = bottom, 1 = switch height, 2 = max height.

4: LIDAR Approach {4, distance, speed} -> Moves the robot forwards until the LIDAR reads a distance less than or equal to the specified parameter. Useful against solid surfaces only. The distance is measured in centimeters.

5: IO (Timed) {5, time, speed} -> Runs the IO at speed for the specified time. Speed should be positive for out and negative for in. Time is measured in seconds. 0.5 seems to be a good value for spitting out cubes.

6: IO (Set) {6, speed} -> Sets the IO to run at speed. Must be stopped with a separate IO Set or an IO Time. Speed works like in Step 5.

7: Auto Aim at Cube {7, minX, maxX, speed} -> Turns the robot at speed until it sees the center of the cube between the specified minX and maxX. The measurements are in pixels, and the camera is in 480p. Best values tested so far are between 256 and 384, centering to the center fifth of the camera's FOV.

8: Shift Drive Gears Down {8} -> Self-explanatory. Run at the beginning of every Routine.

9: Combination Drive and Run Lift {9, stage, distance, speed} -> Runs lifter to specified stage and moves robot at speed to distance. Only continues to next step when both are complete.

97: IO Hold {97, distance, speed} -> Runs the IO inwards at speed if the LIDAR detects the cube beyond the specified distance.

98: Loop Prior Steps {98} -> Resets the current Step to the beginning to run everything in a loop. Putting this in the middle of a routine will only loop the Steps before and the Steps after will never execute.\

99: Go to Step {99, step} -> Goes to the target step. Can be used to loop a specific range of Steps or to skip a set of Steps.