030 lesson: turn the sticks into speeds¶
Turn each stick into a wheel speed, where forward is positive. Nothing on the robot moves yet.
the steps¶
L030S010: copy the starter into mytry¶
Copy.
Open
TeamCode/java/org.firstinspires.ftc.teamcode/lessons.Click
L030SpeedsOpModeonce, and copy it: ⌘C on a Mac, Ctrl+C on Windows.Click the
mytryfolder once, and paste.The Copy Class box opens with Destination package already ending in
mytry. Click OK.If Android Studio asks whether to add the file to Git, click Add.
Check.
mytryholdsL020SticksOpModeandL030SpeedsOpMode, and the new file is open.
L030S020: switch your copy on¶
Change. Find the line @Disabled, just under the comment that names this step, and delete
the whole line, the way you did in L020.
Check.
Under the step’s comment, the next line reads
// 'public' so the robot can run this OpMode. 'public' allows access from any code.
L030S030: the left speed¶
We are working toward tank drive, where the left stick drives the left wheels and the right stick drives the right wheels. Push a stick away from you and its wheels should turn forward. We call forward speeds positive and backward speeds negative. But in L020 a stick pushed away read -1.0, so its number has to be turned around to make a speed.
The starter already has the four lines you wrote in L020. They read the sticks and write them down.
Change. Under the comment that names this step, type double leftSpeed = -leftS. The list
offers leftStickY, the name from the lines above. Press Tab, then finish the two lines:
// When on L030S030, see
// https://msb-stitt.github.io/ftc31459-26-27-biobuzz/guide/tasks/l030.html#l030s030
// for what to do here.
double leftSpeed = -leftStickY;
Tracker.publish("speed/left", leftSpeed);
The minus sign turns the number around: -1.0 becomes 1.0, and 0.5 becomes -0.5. leftStickY is
still what the stick says, and leftSpeed is how fast the wheels should go. Keeping two names for
the two ideas means each name always says what it holds.
Simulator. In the Terminal, run:
./gradlew :TeamCode:simRun --args="mytry.L030SpeedsOpMode --pad"
AdvantageScope. Connect to the simulator as in L020. Type stick in the search box. Drag
leftY from the stick folder, and left from the speed folder, into Left Axis.
Check.
Push the left stick away from you.
stick/leftYgoes to -1.0, andspeed/leftgoes to 1.0.The two lines are always mirror images of each other.
L030S040: the right speed¶
Change. Press Ctrl+C in the Terminal to stop the simulator. Under the comment that names this step, do the same for the right stick:
// When on L030S040, see
// https://msb-stitt.github.io/ftc31459-26-27-biobuzz/guide/tasks/l030.html#l030s040
// for what to do here.
double rightSpeed = -rightStickY;
Tracker.publish("speed/right", rightSpeed);
Simulator. Run the same command again.
AdvantageScope. Drag rightY from stick and right from speed into Left Axis.
Check.
Push both sticks away from you. Both speeds read 1.0.
Pull both back, and both read -1.0.
What’s happening. E035 shows why each speed has a minus sign.