130 lesson: two legs, forward then sideways

../_images/fig-l130-two-legs.png

The robot drives forward, then slides 24 inches to its right without turning, and holds where it ends up. It is the first autonomous that does more than one thing.

the steps

L130S010: copy the starter into mytry

Copy. In lessons, click L130ForwardThenStrafeOpMode once and copy it. Click mytry once and paste. In the Copy Class box, click OK. If Android Studio asks whether to add the file to Git, click Add.

Check.

  • mytry holds L130ForwardThenStrafeOpMode, and the new file is open.

L130S020: switch your copy on

Change. Delete the line @Disabled, under the comment that names this step.

Check.

  • Under the step’s comment, the next line reads // 'public' so the robot can run this OpMode. 'public' allows access from any code.

L130S030: add a second leg and a hold

A pose is a place on the field and the way the robot faces there. Near the top of the class are three poses: start, corner and end. All three face 90 degrees. corner is straight up the field from start, and end is 24 inches to the right of corner.

driveForwardThenStrafe() already holds the first leg, from start to corner. It is L125’s line, with one item on each line so there is room for more.

Change. In driveForwardThenStrafe(), type a comma at the end of the first leg. The comment that names this step is under it. Under the comment, type:

        return sequential(
                follow(follower, line(start, corner).constant(start)),
                // When on L130S030, see
                // https://msb-stitt.github.io/ftc31459-26-27-biobuzz/guide/tasks/l130.html#l130s030
                // for what to do here.
                follow(follower, line(corner, end).constant(start)),
                hold(follower, end)
        );

Each item but the last ends with a comma. The second leg holds start’s heading too, so the robot never turns. It slides sideways instead, which is what mecanum wheels are for. hold keeps the robot at end once it gets there.

hold turns red. Click it and press Option+Enter, as in L125.

Simulator. In the Terminal, run:

./gradlew :TeamCode:simRun --args="mytry.L130ForwardThenStrafeOpMode"

AdvantageScope. Connect to the simulator as in L020, click 2D Field, and open the Localizer folder, then pinPoint.

Check.

  • The robot has stopped right of the middle of the field.

  • x_in reads 96 and y_in 72.

  • heading_deg is still 90.

L130S040: drive it on the floor

Robot. Stop the simulator. The robot drives about 62 in forward, then 24 in to its right, so clear that much floor, plus room for the robot. Put the robot on the floor with a piece of tape at its front edge. Send the code, and run L130 Forward Then Strafe from the autonomous list.

Check.

  • The robot drives straight forward and stops, then slides to its right and stops again.

  • Its nose points the same way the whole time.