Encoders in Robotics

Spread the love

Robots use encoders to measure how far and how fast their motors actually turn. Two motors are never perfectly matched, so wheeled robots need encoder feedback to drive straight and hold speed on slopes, while robotic arms use joint position feedback to know where they sit in 3D space. A motor controller reads these signals to close the loop.

A motor without feedback runs blind: the controller applies power and hopes the mechanism does what was intended. Encoders remove the guesswork by reporting position, speed, and direction back to the motor controller. This article looks at how encoders are used in practice on wheeled robots and robotic arms, the two places robot builders rely on them most. If you are new to encoders, Encoders Explained covers the fundamentals, including the difference between incremental and absolute types.

What Does an Encoder Do on a Robot?

An encoder converts shaft rotation into electrical pulses that a motor controller can count. On most robots the encoder is mounted on the drive motor, either on the rear motor shaft or built into the gearbox. The controller counts pulses to track position, measures the pulse rate to calculate speed, and reads the signal phase to determine direction. It then compares the measured values against the commanded ones and corrects the difference many times per second. That correction loop is a PID controller, covered in PID Control and Motor Controllers.

RoboClaw motor controllers decode quadrature encoder signals in hardware, tracking the counts as full 32 bit values, and read analog absolute encoders directly over a 0 to 2 volt input range resolved into 2048 steps. The official Arduino, Python, and ROS 2 libraries read counts and speeds from either encoder type directly in user code.

How Do Wheeled Robots Use Encoders?

Wheeled robots use encoders for two jobs: measuring how far the robot has traveled and keeping it moving in a straight line at a constant speed. Rarely are two motors created equal. Commanded with the same power, one always spins a little faster than the other, so without encoder feedback a wheeled robot has a hard time driving straight or maintaining a constant speed through slopes and inclines, load changes, and battery sag.

Velocity feedback fixes the drift. The controller compares each wheel’s measured speed against its commanded speed and adjusts power continuously, so both wheels hold their commanded speeds regardless of slope, load, or battery state, and the robot tracks straight. Turns become predictable too, since a commanded speed difference between the wheels produces the same arc every time.

Distance measurement, called odometry, works because each encoder count represents a fixed fraction of a wheel revolution. Divide the wheel circumference by the counts per revolution and the robot knows how far each wheel rolls per count:

Wheel diameter:              100 mm
Wheel circumference:         100 mm x 3.1416 = 314 mm
Counts per wheel revolution: 3200

Distance per count = 314 mm / 3200
Distance per count = 0.098 mm

A robot counting 3,200 counts per revolution resolves wheel travel to about a tenth of a millimeter. In practice wheel slip and tire compression limit real accuracy, but encoder odometry remains the foundation of robot dead reckoning and feeds navigation software such as the ROS 2 differential drive controller.

Quadrature encoders are directional. On a differential drive robot one motor turns clockwise and the other counterclockwise, so the A and B wires on one encoder must be swapped to make both counts increase when the robot drives forward. If one counts up and the other counts down, mixed drive functions will not operate correctly.

How Do Robotic Arms Use Encoders?

Robotic arms depend on knowing the true position of every joint, which makes absolute encoders a natural fit for arm joints: they report the real shaft position the moment power is applied, even if the arm was moved while powered off. Quadrature encoders work too and often cost less, but they only report movement relative to where the shaft started, so the arm must be homed after every power-up by driving each joint to a known reference such as a limit switch or a hard stop. The tradeoffs between the two types are covered in Encoders Explained. In either case, position limits must be set inside each joint’s real travel range, with a safety margin before each physical stop, so the controller never drives the arm into its own frame. The same position control approach applies to linear actuators, gearmotor driven grippers, and pan and tilt mechanisms.

True joint positions are also the foundation of inverse kinematics, the math that commands an arm. To place a gripper at a point in 3D space, inverse kinematics computes the joint angles that put it there, and the controller drives each joint to its computed angle. The calculation is only as good as the feedback behind it: one unhomed or miscounted joint makes every calculated gripper position wrong. Absolute encoders guarantee the real angle of every joint from the moment power is applied, which is why they are the standard foundation for inverse kinematics driven arms.

How Does a Motor Controller Use Encoder Feedback?

The motor controller is where encoder signals become motion. RoboClaw controllers support three closed loop modes: velocity control, position control, and a cascaded mode that combines position with velocity. Supported feedback devices are quadrature encoders, analog absolute encoders that output 0 to 2 volts, and potentiometers.

Tuning connects the encoder to the motor. The auto-tune function in Motion Studio measures the motor and encoder combination and produces working PID values, and it typically gives usable results with quadrature encoders. The key parameter is QPPS, the maximum quadrature pulses per second the motor and encoder can produce, found by running the motor at full duty and reading the encoder speed. Auto Tuning with Motion Studio walks through the procedure.

Encoder feedback is available across the entire line of RoboClaw motor controllers, from the dual channel 2x7A up to single channel 300A models, so the same closed loop setup scales from a desktop robot to a heavy platform. The table below summarizes where encoders fit on a typical robot.

Application What the encoder provides Control mode
Drive wheels Straight tracking, speed under load, distance traveled Velocity control
Robotic arm joints Joint angles for 3D positioning, held against load Position or cascaded control
Linear actuators Position within the travel range Position control
Pan and tilt mechanisms Pointing angle and smooth motion Position or cascaded control

Next Steps

Pololu Encoder Wiring shows how to connect a typical hobby encoder to a RoboClaw. Once wired, Using Encoders with the Arduino Library and Using Encoders with the Python Library cover reading counts and speeds in code, and Auto Tuning with Motion Studio gets velocity and position control tuned and running. For a deeper look at the signals themselves, Quadrature Encoders: How They Work breaks down the A and B channels in detail.