All pages
Powered by GitBook
1 of 1

Loading...

Converting Encoder Ticks to a Distance

In the previous section, the basic structure needed to use RUN_TO_POSITIONwas created. The placement ofwithin the code, set the target position to 1000 ticks.

But how far is a tick and how can we use them to help our robot navigate an area? We could attempt to estimate the distance the robot moves per tick or we can convert the amount of ticks per revolution of the encoder into a unit like millimeters or inches! For instance, if you work through the conversion process and find out that a drivetrain takes 700 ticks to move an inch, this can be used to find the total number of ticks need to move the robot 24 inches.

Reminder that the basis for this guide is the . The REV DUO Build System is a metric system. Since part of the conversion process references the diameter of the wheels, this section will convert to ticks per mm.

What's Needed for the Conversion

This process will take a bit of math to achieve so let's break it down.

When using encoders built into motors, converting from ticks per revolution to ticks per unit of measure moved requires the following information:

The amount of ticks per revolution of the encoder shaft is dependent on the motor and encoder. Manufacturers of motors with built-in encoders will have information on the amount of ticks per revolution.

For HD Hex Motors the encoder counts 28 ticks per revolution of the motor shaft.

Since ticks per revolution of the encoder shaft is before any gear reduction calculating the total gear reduction is needed. This includes the gearbox and any addition reduction from motion transmission components. To find the total gear reduction use the .

For the Class Bot V2 there are two UltraPlanetary Cartridges, 4:1 and 5:1, and an additional gear reduction from the UltraPlanetary Output to the wheels, 72T:45T ratio.

Using the compound gearing formula for the Class Bot V2 the total gear reduction is:

The Class Bot V2 uses the 90mm Traction Wheels. 90mm is the diameter of the wheel. To get the appropriate circumference use the following formula

You can calculate this by hand, but for the purpose of this guide, this can be calculated within the code.

To summarize, for the Class Bot V2 the following information is true:

Each of these pieces of information will be used to find the number of encoder ticks (or counts) per mm that the wheel moves. Rather than worry about calculating this information by hand, these values can be added to the code as constant variables. To do this create three variables:

  • COUNTS_PER_MOTOR_REV

  • DRIVE_GEAR_REDUCTION

  • WHEEL_CIRCUMFERENCE_MM

We'll add the to the initialization section of the OpMode:

Once the variables are created and added to the OpMode, use the blocks to set the variables to the respective values.

For WHEEL_CIRCUMFERENCE_MM a combination of the , , and blocks will be used to get the circumference of the wheel.

Now that these three variables have been defined, we can use them to calculate two other variables: the amount of encoder counts per rotation of the wheel and the number of counts per mm that the wheel moves.

To calculate counts per wheel revolution multiply COUNTS_PER_MOTOR_REV by DRIVE_GEAR_REDUCTION Use the following formula:

Where:

  • = COUNTS_PER_MOTOR_REV

  • = DRIVE_GEAR_REDUCTION

  • = COUNTS_PER_WHEEL_REV

Again math blocks need to be used to define these variables. Lets start with the COUNTS_PER_WHEEL_REV variable. Add a to the block. Add the and blocks to either side of the block.

Once the COUNTS_PER_WHEEL_REV is calculated, it can be used to calculate the counts per mm that the wheel moves. To do this divide the COUNTS_PER_WHEEL_REV by the WHEEL_CIRCUMFERENCE_MM. Use the following formula.

Where,

  • = COUNTS_PER_MOTOR_REV

  • = DRIVE_GEAR_REDUCTION

  • = WHEEL_CIRCUMFERENCE_MM

Since COUNTS_PER_WHEEL_REV has been calculated it can be used to calculate COUNTS_PER_MM add the to the . On the left side of the add the block. On the right side of the add the .

Once COUNTS_PER_WHEEL_MM is set, this completes the conversion process, and all constant variables are set.

Make sure to save your OpMode here to prevent any progress being lost in the event of a disconnect!

= COUNTS_PER_WHEEL_REV

  • = COUNTS_PER_MM

  • 3.611∗5.231∗7245=30.21\frac{3.61}{1} * \frac{5.23}{1} * \frac{72}{45} = 30.2113.61​∗15.23​∗4572​=30.21
    circumference=diameter∗πcircumference = diameter * \pi circumference=diameter∗π

    Ticks per revolution

    28 ticks

    Total gear reduction

    30.21

    Circumference of the wheel

    y=a∗by = a *by=a∗b
    aa a
    bbb
    yyy
    x=(a∗b)c=ycx = \frac{(a*b)}{c} = \frac{y}{c}x=c(a∗b)​=cy​
    aa a
    bbb
    ccc

    Ticks per Revolution

    Visit the manufacturers website for your motor or encoders for more information on encoder counts. For HD Hex Motors or Core Hex Motors visit the documentation.

    Total Gear Reduction

    The UltraPlanetary Cartridges use the nominal gear ratio as a descriptor. The actual gear ratios can be found in the .

    Unlike the spur gears used to transfer motion to the wheels, the UltraPlanetary Gearbox Cartridges are planetary gear systems. To make calculations easier the gear ratios for the Cartridges are already reduced.

    Circumference of the Wheel

    Due to wear and manufacturing tolerances, the diameter of some wheels may be nominally different. For the most accurate results consider measuring your wheel to confirm that the diameter is accurate.

    Quick Summary

    Translating the Conversion to Code

    Setting up Variables

    The common naming convention for constant variables is known as CONSTANT_CASE, where the variable name is in all caps and words are separated by and underscore.

    Calculating COUNTS_PER_WHEEL_REV

    Calculating COUNTS_PER_MM

    COUNTS_PER_WHEEL_REVwill be created as a separate variable from COUNTS_PER_MM as it is used in calculating a target velocity.

    Final Variables

    Compound Gearing formula
    variables
    Class Bot V2
    Adding our new variables to initialization
    yyy
    xxx
    90mm∗π90mm * \pi90mm∗π
    Motor
    UltraPlanetary Users Manual's Cartridge Details