150 lesson: give the driver both¶
The sticks mean the field, the way L140 left them, until the right bumper is held. While it is held they mean the robot. Let go and they mean the field again.
the steps¶
L150S010: copy the starter into mytry¶
Copy. In lessons, click L150RobotRelativeButtonOpMode 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.
mytryholdsL150RobotRelativeButtonOpMode, and the new file is open.
L150S020: 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.
L150S030: choose with the bumper¶
Field relative is the easier way to drive most of the time. It is not the easier way to line up against something. Backing straight out of a corner, or nudging along a wall, is easier when forward means the robot’s own forward.
So the driver gets both, and an if chooses. The starter already works out robotForward and
robotStrafe, L140’s turn. forward and strafe are the sticks as they are, the robot’s own
directions.
Change. In driveFromTheSticks(), find the comment that names this step. Delete the line
drivetrain.sticks(robotForward, robotStrafe, turn); under it, and type:
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);
// When on L150S030, see
// https://msb-stitt.github.io/ftc31459-26-27-biobuzz/guide/tasks/l150.html#l150s030
// for what to do here.
boolean robotRelative = gamepad1.right_bumper;
Tracker.publish("drive/robotRelative", robotRelative);
if (robotRelative) {
drivetrain.sticks(forward, strafe, turn);
} else {
drivetrain.sticks(robotForward, robotStrafe, turn);
}
When you type { and press Enter, Android Studio adds the } for you.
The bumper is read fresh every loop. Let go, and the next loop drives field relative again. The driver’s thumb tells them which way the sticks work, so there is nothing to remember in a match.
Simulator. In the Terminal, run:
./gradlew :TeamCode:simRun --args="mytry.L150RobotRelativeButtonOpMode --pad"
AdvantageScope. Connect to the simulator as in L020, click 2D Field, and open the drive
folder, then Localizer and pinPoint.
Check.
Hold the right bumper and push the left stick a little forward.
robotRelativeturns green, and the robot drives up the field, the way its nose points.y_inclimbs andx_instays at 72.Let go of the bumper and keep pushing. The robot slides to the right, along +x, and
x_inclimbs.
L150S040: drive both ways on the floor¶
Robot. Stop the simulator. Send the code, and run L150 Robot Relative Button from the Driver
Station. Stand off the robot’s left side, as in L140.
Check.
Turn the robot so its nose points to one side, and push the left stick away from you.
The robot drives away from you.
Now hold the right bumper and push the same way. The robot drives along its own nose.
Let go, and it drives away from you again.