Skip to content
Tactiverge

Sensing position and motion

How robots measure their own joints and movement with potentiometers, encoders, accelerometers and gyroscopes, and why integrated measurements drift.

Lesson 2 of 6 · 35 min · Self-paced · Free

Knowing where you are

Before a robot can control a joint, it has to know the joint's angle. Before a mobile robot can follow a path, it needs some idea of how far it has driven and which way it is facing. Sensors that measure a robot's own state, rather than the outside world, are called proprioceptive sensors, after the human sense that tells you where your limbs are with your eyes closed.

This lesson covers the four you will meet most: potentiometers, encoders, accelerometers and gyroscopes.

Potentiometers: angle as a voltage

A rotary potentiometer (often shortened to "pot") is a resistive track with a sliding contact, the wiper, attached to a shaft. Put a fixed voltage across the ends of the track and the wiper's voltage is proportional to how far round the shaft has turned.

Suppose a pot has 270° of travel and is supplied with 3.3 V. If the wiper reads 1.10 V:

angle = (1.10 / 3.3) × 270° = 90°

Pots are cheap, simple and absolute: the moment the robot powers on, the voltage says where the joint is. Their weaknesses are a limited angle (most cannot spin continuously), wear of the sliding contact, and electrical noise that limits resolution. A typical hobby servo uses a pot inside it to sense its own output angle.

Encoders: counting steps of rotation

An encoder turns rotation into digital pulses. A common design is a disc with a ring of slots and a light shining through it onto a detector: as the disc turns, the light flickers on and off, and electronics count the flickers. Magnetic encoders do the same with a rotating magnet and a sensor that detects its field.

Incremental encoders

An incremental encoder reports changes in angle. Two detectors placed slightly out of step, called quadrature channels A and B, let the electronics tell which way the shaft is turning: if A changes before B, it is going one way; if B leads, the other. Counting every rising and falling edge of both channels gives four counts per slot.

Worked example: an encoder with 500 slots per revolution gives 4 × 500 = 2000 counts per revolution, so each count is:

360° / 2000 = 0.18°

Put that encoder on a wheel 6.5 cm in diameter. One revolution moves the robot one circumference, π × 6.5 ≈ 20.42 cm, so each count is about 0.1 mm of travel. After 15,000 counts:

15000 / 2000 = 7.5 revolutions
7.5 × 20.42 cm ≈ 153.2 cm

The catch is the word incremental. The encoder knows only how far it has moved since it started counting. After power-up, the robot must home each joint, for example by moving slowly until it touches a limit switch, to establish where zero is.

Absolute encoders

An absolute encoder reports the actual angle directly, using a disc with a unique pattern at every position. It knows where it is at power-up, which is why many industrial arms use them, at higher cost.

What encoders cannot tell you

A wheel encoder measures how far the wheel turned, not how far the robot moved. If the wheel slips on a dusty floor or the robot is pushed, the count and reality disagree. Estimating position by adding up wheel motion is called odometry, and its errors grow with distance travelled.

Inertial sensors: accelerometers and gyroscopes

An inertial measurement unit (IMU) packages motion sensors into a small chip, usually tiny micro-machined structures etched in silicon. The two core sensors are the accelerometer and the gyroscope.

Accelerometers

An accelerometer measures acceleration along each of its axes. The surprising detail is that it also measures gravity. An accelerometer sitting still on a table reports about 9.81 m/s² pointing up, because the table is pushing it up against gravity. In free fall it reads nearly zero.

That makes an accelerometer a good tilt sensor when it is not otherwise accelerating. If a robot is tilted by 30°, gravity splits between two axes:

along x: 9.81 × sin 30° ≈ 4.905 m/s²
along z: 9.81 × cos 30° ≈ 8.496 m/s²
tilt = atan2(4.905, 8.496) ≈ 30.0°

But once the robot moves, the accelerometer cannot tell the difference between tilting and accelerating. Vibration from motors also makes accelerometer readings noisy.

Gyroscopes

A gyroscope (gyro) measures angular velocity: how fast the sensor is rotating, in degrees or radians per second. To get an angle, you add up rate × time at every step, a process called integration:

angle_new = angle_old + rate × Δt

Gyros are smooth and respond quickly, and they do not care about linear acceleration. Their weakness is bias: a small, slowly changing offset in the rate reading. Even when the sensor is perfectly still, it might report 0.5 °/s. Integration adds that error up every step.

Drift: why integrated sensors wander

Here is that effect in Python, with a made-up bias of 0.5 °/s and the robot sitting perfectly still:

bias = 0.5      # deg/s, made-up gyro bias for illustration
dt = 0.01       # 100 readings per second
angle = 0.0
for step in range(1, 6001):   # 60 seconds with the robot perfectly still
    true_rate = 0.0
    measured = true_rate + bias
    angle += measured * dt
    if step % 1500 == 0:
        print(f"t = {step * dt:4.0f} s   estimated angle = {angle:5.1f} deg")
t =   15 s   estimated angle =   7.5 deg
t =   30 s   estimated angle =  15.0 deg
t =   45 s   estimated angle =  22.5 deg
t =   60 s   estimated angle =  30.0 deg

The robot has not moved, yet after a minute it believes it has turned 30°. This steady growth of error is called drift.

It is worse for position from an accelerometer, because position needs two integrations (acceleration → velocity → position). A constant acceleration bias b produces a position error of ½ · b · t². With b = 0.01 m/s², that is 0.5 m after 10 s and 18 m after 60 s. This is why a phone cannot track your walk around a building using its accelerometer alone.

Combining strengths

Notice how the weaknesses complement each other. The gyro is smooth and fast but drifts over time. The accelerometer is noisy and confused by motion, but on average it always knows which way is down, so it does not drift. Combining them, trusting the gyro over short times and the accelerometer over long times, gives a tilt estimate better than either. This idea, sensor fusion, is developed in the embedded systems pathway. Similarly, wheel odometry is often corrected by an absolute reference such as a camera recognising landmarks.

Recap

Potentiometers give absolute angle as a voltage but wear and have limited travel. Incremental encoders count fine steps of rotation but need homing; absolute encoders know their angle at power-up. Accelerometers sense acceleration plus gravity, making them tilt sensors when still. Gyros sense rotation rate; integrating them drifts because bias accumulates. Any estimate built by adding up small changes will drift unless something absolute corrects it.

Knowledge check

Check your understanding

  1. 1. An incremental encoder has 1000 slots and is read in quadrature (4 counts per slot). What angle does one count represent?
  2. 2. Why must a robot with incremental encoders usually home its joints after power-up?
  3. 3. An accelerometer lying flat and still on a table reads about 9.81 m/s² upward. Why?
  4. 4. A still gyro has a bias of 0.2 °/s. After integrating for 2 minutes, roughly how wrong is the angle estimate?
  5. 5. Why do engineers often combine a gyroscope with an accelerometer to estimate tilt?

Go further