Encoder: Measure the traveled distance of the robot.

Our team has one encoder and we plan to use it for measuring the traveled distance of the robot. We have no idea about:
-Where to put the encoder? (The side to sense the magnets)
-We used VictorSP for the motor speed controllers. Should we change all of them to CAN TalonSRX?
-How to attach the encoder to the motor (through gearbox???)?

Thanks for helping us!

We’re going to need some more information here if you want any help. What kind of drivetrain do you have? What kind of gearboxes are you using? What kind of encoders did you buy? How many encoders do you have? What do you want to accomplish with the encoders? This should at least help us get started with answering your questions.

So in general your encoder will only measure a component of how your robot is moving around the field.

At the simplest level, you want to engage an encoder on each side of your drivetrain (assuming you have tank drive, more on this later) to measure how much the wheels are rotating.

If you know the ratio of speed of what the encoder is attached to to the rotational speed of the wheels, then through some quick algebra (ratiopiradius of wheels = linear distance traveled per encoder rotation) you can get determine how far the robot travels (though mainly in a linear fashion).

By having encoders on both sides of the drivetrain, you can control turning by knowing the difference in what distance either side is moving, and can verify you’re driving (roughly) straight if both sides move the same distance.

As actually mounting the encoder goes, it depends on what specific model you’re planning on using. In general, you want to attach it somewhere in the drivetrain (within a gearbox, integrated into a drive shaft, on an extra shaft where it is engaged by a drive belt, etc) so that the encoder spins when the drive wheels do.

With respect to the electronics side of things, you have two choices for how you connect your encoders:

  1. Hook them up to the RoboRio’s DIO inputs (you’ll need two inputs per encoder, for the Channel A and Channel B signals), and set up your own code to manage and use the values from the encoders, or

  2. Hook them directly up to a motor controller that supports encoder inputs, such as the Talon SRX using one of the available breakout boards.

If you’re happy with your Victor SP’s there’s no need to swap them out just to get an encoder working. However, I’ve read that there are many advantages to having the Talon SRX’s manage their own encoders. If you’re just starting out learning how to use encoders, I wouldn’t worry about this just yet.

Here’s a good introduction to programming FRC robots to use encoders. The article shows you how to do it in Java and C++:


Once you get your encoders working you’ll see them counting “ticks” as you move the robot. You’ll want to calibrate your software - the easiest way to do this is to push your robot for a known distance, say 10 feet, and then look at the “tick” count before and after the move. Take the measured count, divide by the distance, and you’ll have a conversion factor you can start using in your code. For example, if you measure (on average) 340 ticks per foot, then you know how to command the robot to travel a certain distance. Your code will get the current tick count, add or subtract the number of ticks you want, start the motors, and stop the motors when the tick count reaches the desired value.