Drivetrain Encoders - Blocks

We're updating this documentation!

During 2024 Summer, "Hello Robot" will be getting a refreshed look to reflect changes to the latest versions of the REV Hardware Client and Robot Controller App.

While this guide is still generally relevant, you may see differences in the naming of devices or commands along with visual updates to the guide.

In the previous section you learned about how to use Elapsed Time to allow your robot to navigate the world around it autonomously. When starting out many of the robot actions can be accomplished by turning on a motor for a specific amount of time. Eventually, these time-based actions may not be accurate or repeatable enough. Environmental factors, such as the state of battery charge during operation and mechanisms wearing in through use, can all affect time-based actions. Fortunately, there is a way to give feedback to the robot about how it is operating by using sensors; devices that are used to collect information about the robot and the environment around it.

With Elapsed Time, in order to get the robot to move to a specific distance, you had to estimate the amount of time and the percentage of duty cycle needed to get from point a to point b. However, the REV motors come with built in encoders, which provide feedback in the form of ticks ( or counts) per revolution of the motor. The information provided by the encoders can be used to move the motor to a target position, or a target distance.

Moving the motors to a specific position, using the encoders, removes any potential inaccuracies or inconsistencies from using Elapsed Time. The focus of this section is to move the robot to a target position using encoders.

There are two articles in that go through the basics of Encoders. Using Encoders goes through the basics of the different types of motor modes, as well as a few application examples of using these modes in code. In this section we will focus on using RUN_TO_POSITION.

The other article, Encoders, focuses on the general functionality of an encoder.

It is recommended that you review both articles before moving on with this guide.

Basics of Programming with Encoders

Start by creating a basic op mode called HelloRobot_EncoderAuton.

When creating an op mode a decision needs to be made on whether or not to set it to autonomous mode. For applications under 30 seconds, typically required for competitive game play changing the op mode type to autonomous is recommended. For applications over 30 seconds, setting the code to the autonomous op mode type will limit your autonomous code to 30 seconds of run time. If you plan on exceeding the 30 seconds built into the SDK, keeping the code as a teleoperated op mode type is recommended.

For information on how op modes work please visit the Introduction to Programming section.

For more information on how to change the op mode type check out the Test Bed - Blocks section.

For more information on the directionality of motor check out the Basics of Programming Drivetrains section.

Save and run the op mode two times in a row. Does the robot move as expected the second time?

Try turning the Control Hub off and then back on. How does the robot move?

For more information on the motor mode STOP_AND_RESET_ENCODERScheck out the STOP_AND_RESET_ENCODERS section of the Using Encoders guide.

Last updated