195 lesson: measure the two numbers L190 trusted

../_images/fig-l195-nothing-pushed.png

Two numbers in Constants.java that came off this robot instead of somebody else’s: how many encoder ticks make an inch, and how far a wheel sits from the middle. The robot measures them while you push it and spin it by hand.

the steps

L195S010: copy the three starters into mytry

This lesson has three files. Two are OpModes, one for each measurement. The third is the drivetrain, which tells them what each wheel’s encoder has counted.

Copy. In lessons, click L195MeasureTicksPerInchOpMode once. Hold Shift and click L195TicksDriveTrain, so all three are picked. Copy them, click mytry once, and paste. In the Copy box, click OK. If Android Studio asks whether to add the files to Git, click Add.

Copy all three at once. Copied one at a time, the OpModes still point at the drivetrain in lessons, and turn red.

Check.

  • mytry holds L195MeasureTicksPerInchOpMode, L195MeasureTurnRadiusOpMode and L195TicksDriveTrain, and none of them shows red.

L195S020: switch both OpModes on

Change. In L195MeasureTicksPerInchOpMode, delete the line @Disabled, under the comment that names this step. Do the same in L195MeasureTurnRadiusOpMode.

Check.

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

L195S030: open a door to the encoders

Open L195TicksDriveTrain. A drivetrain sends four powers out to the motors. wheelTicks() is the same shape pointing the other way: it brings four numbers back.

Change. In wheelTicks(), find the comment that names this step. Under it, type:

        // When on L195S030, see
        // https://msb-stitt.github.io/ftc31459-26-27-biobuzz/guide/tasks/l195.html#l195s030
        // for what to do here.
        ticks[FL] = hardware.frontLeft.getCurrentPosition();
        ticks[FR] = hardware.frontRight.getCurrentPosition();
        ticks[BL] = hardware.backLeft.getCurrentPosition();
        ticks[BR] = hardware.backRight.getCurrentPosition();

getCurrentPosition() is how many ticks a motor’s encoder has counted since the robot started. FL, FR, BL and BR name the slots, as in L190.

Simulator. In the Terminal, run:

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

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

Check.

  • inches and ticks read 0.0.

  • ticksPerInch reads NaN, which means “not a number”.

Nobody can push a robot in the simulator, so it stays at x 72 in and y 10.5 in. And 0.0 divided by 0.0 is not a number. The measuring is for the robot.

L195S040: push the robot and measure an inch

An encoder counts small steps, called ticks, as its motor turns. Many ticks make one turn of the wheel.

The robot keeps two accounts of the same trip. The Pinpoint says how far it went in inches, since its own wheels measure the floor. The drive encoders say how many ticks they counted. One divided by the other is the number.

Robot. Stop the simulator. Send the code, and run L195 Measure ticks per inch from the Driver Station.

Push. Push the robot slowly straight forward, at least 36 in, keeping it pointing the same way. Push slowly: a wheel that slips travels without turning, and the answer comes out short.

Check.

  • The Driver Station shows ticksPerInch with a number after it.

Do it three times. Three answers a tick or two apart are a measurement.

Change. Open Constants, in the pedro folder, and put the number in ticksPerInch, which is 45.0 until you do. Send the code again and run it once more to check.

L195S050: spin the robot and measure the radius

A wheel r inches from the middle travels r inches for every radian the robot turns. So the radius is the wheel’s inches divided by the radians. This OpMode turns ticks into inches with ticksPerInch, so L195S040 comes first.

Robot. Run L195 Measure turn radius from the Driver Station.

Spin. Spin the robot on the spot by hand, at least two full turns, keeping it in about the same place.

Check.

  • The Driver Station shows a turn radius.

  • Measure from the middle of the robot to the middle of one wheel, once across the robot and once along it. Add those two lengths. The sum is close to the turn radius the Driver Station shows.

Change. Put the number in turnRadiusInches in Constants.java, which is 8.0 until you do.