140 lesson: make the sticks mean the field¶
Push the stick away from you and the robot goes away from you. It does that whichever way the robot happens to be facing, so a driver never has to think about which end of the robot is the front.
the steps¶
L140S010: copy the starter into mytry¶
Copy. In lessons, click L140FieldRelativeOpMode 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.
mytryholdsL140FieldRelativeOpMode, and the new file is open.
L140S020: 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.
L140S030: drive and turn at once, the L110 way¶
The starter drives the way L110 did. Forward on the stick is forward for the robot.
Simulator. In the Terminal, run:
./gradlew :TeamCode:simRun --args="mytry.L140FieldRelativeOpMode --pad"
AdvantageScope. Connect to the simulator as in L020, click 2D Field, and open the
Localizer folder, then pinPoint.
Check.
Push the left stick a little forward and the right stick left, and hold both.
The robot drives in a small circle, and
x_inandy_instay close to where they started.It goes where its nose points, and its nose keeps turning.
L140S040: turn the stick backwards through the heading¶
From now on, forward on the stick means away from the driver, along the field’s x. strafe means
to the driver’s left, along the field’s y. On AdvantageScope’s 2D Field, +x runs to the right and
+y runs up.
The wheels only know the robot’s own forward and sideways. L120 turned a step on the robot into a
step on the field, through the heading. This turns the other way, from the field to the robot, so
the signs on sin swap.
Change. Press Ctrl+C in the Terminal to stop the simulator. In driveFromTheSticks(), find the
comment that names this step. Delete the line drivetrain.sticks(forward, strafe, turn); under it,
and type:
// When on L140S040, see
// https://msb-stitt.github.io/ftc31459-26-27-biobuzz/guide/tasks/l140.html#l140s040
// for what to do here.
double heading = follower.pose().heading();
double robotForward = forward * Math.cos(heading) + strafe * Math.sin(heading);
double robotStrafe = -forward * Math.sin(heading) + strafe * Math.cos(heading);
drivetrain.sticks(robotForward, robotStrafe, turn);
The follower knows which way the robot faces. The drivetrain does not. So the OpMode asks the follower, and does the turn itself.
Simulator. Run the same command again, and connect AdvantageScope.
Check.
Hold the same two sticks. The robot spins, and at the same time it travels to the right on the 2D Field, along +x.
x_inclimbs whileheading_deggoes around and around.
L140S050: drive it facing you¶
Robot. Stop the simulator. Send the code, and run L140 Field Relative from the Driver
Station. Stand off the robot’s left side, so that away from you is the field’s +x.
Check.
Push the right stick until the robot’s nose points at you.
Then push the left stick away from you. The robot drives away from you while it faces you.
Turn it a quarter turn and try again, and the stick still means the same way on the field.