🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Sensors: Encoders, IMU, and Force/Torque

Robotics & MechatronicsHardware and AutomationđŸŸĸ Free Lesson

Sensors: Encoders, IMU, and Force/Torque

What You'll Learn

  • 1Convert encoder counts per revolution and gearing into angular resolution and count rate
  • 2Bound quantization error and derive angular velocity from counted increments
  • 3Explain gyro bias drift and merge gyro and accelerometer data with a complementary filter
  • 4Trace a strain-gauge bridge through amplification to a digital force reading

Control quality is bounded by sensing quality: a servo loop cannot hold tighter than the smallest change its encoder can report, and a force-limited cobot cannot trust contact values noisier than its bridge. Each sensor family has one arithmetic chain that converts its raw output into engineering units, and those chains are short enough to compute by hand. This lesson works three of them: encoder counts to degrees and millimeters, gyro bias to drift in degrees, and microstrain to newtons.

Theory and Foundations

An incremental optical encoder passes light through a coded disk and produces two square waves in quadrature, so a counter can register every edge of both channels. The chain from pulses to angle includes the quadrature multiplier and any gearbox between motor and load.

Quantization then sets a floor on both measurement and control: a reading is rounded to the nearest count, so the true angle lies inside a window of width one count.

Velocity is obtained by differencing counts over a fixed sample interval, which trades resolution for bandwidth because a short window contains few counts.

Inertial sensing has a different failure mode. A MEMS gyro reports angular rate with a slowly varying bias, and integrating that rate turns a small offset into an unbounded angle error.

An accelerometer has no such drift, but it cannot distinguish rotation from gravity and is noisy, so tilt is computed from the gravity vector only when the device is quiescent.

The standard fix blends the two: trust the gyro over short intervals and pull gently back toward the accelerometer.

With and , a fused angle of 10.0 deg, a gyro reading of 2 deg/s, and an accelerometer tilt of 12 deg give deg: the gyro carries the motion and the accelerometer removes the drift one percent at a time.

Force sensing starts with strain gauges bonded to a flexure. A gauge changes resistance in proportion to strain, and a Wheatstone bridge converts that small change into a voltage proportional to applied load.

Here is the gauge factor, typically about 2.0, and is strain in dimensionless units, where 500 microstrain is 0.0005. The millivolt-level signal then needs amplification before an analog-to-digital converter can resolve it.

Key Formulas

Worked Examples

SensorResolution or rangeOutputDrift or noiseTypical use
Incremental encoder, 1000 CPR quad0.0009 deg geared 100:1pulsescount quantizationjoint feedback
Absolute encoder, 21 bit0.00017 deg single turnposition wordnone on power-upsafety and homing
MEMS gyro0.01 to 0.5 deg/s biasrate (deg/s)bias drift over timeIMU stabilization
MEMS accelerometerabout 1 mgacceleration (g)noise floortilt, impact detect
Strain-gauge force sensorabout 0.2 N after gainmillivolts then voltstemperature span errorgrip and insertion
Inductive proximity1 to 4 mm gapdigitalnonehome and end stops

Real-World Examples

  • 17-bit joint encoders - Industrial arms often use 131,072 counts per revolution, giving 0.00275 deg per count before gearing, which is finer than the 0.02 mm repeatability it must support.
  • Absolute single-turn disks - A 21-bit absolute encoder reports 2,097,152 positions per revolution, 0.00017 deg, and eliminates the homing move after every power cycle.
  • Six-axis force/torque sensors - Wrist-mounted units resolve roughly 0.02 N and 0.003 N m, enough to detect a 5 N contact during an insertion task.
  • Temperature compensation - Bridge output shifts about 0.02 percent of full scale per degree C, so a 10 C swing can inject 1 N of error into a 500 N reading without compensation.

💡Resolution is not accuracy

Quadrature decoding and gearing may report 0.0009 deg, but disk eccentricity, bearing play, and mounting alignment decide where that reading sits; spec sheets quote resolution, calibration delivers accuracy.

From Counts to Millimeters in Python

Every encoder figure that reaches a human passes through the same chain: cycles to quadrature counts, counts through the gearbox, counts to angle, angle to whatever the machine actually measures. Working it once in a function keeps the gear ratio from being forgotten on one screen and applied twice on another, and it makes the count rate explicit, which is the figure that decides whether the counter peripheral can keep up. A joint resolution of 0.0009 degrees looks impressive until it is projected to the tool tip, where it becomes sixteen microns of arc.

python
import math

def encoder_chain(counts, cpr=1000, gear=100, window_s=0.01, tip_m=1.0):
    per_rev = cpr * 4 * gear                 # quadrature decoding
    deg_per_count = 360.0 / per_rev
    omega = (counts / per_rev) * 2 * math.pi / window_s
    rate = counts / window_s                 # counts per second
    tip_mm = math.radians(deg_per_count) * tip_m * 1000.0
    return deg_per_count, omega, rate, tip_mm

deg, omega, rate, tip = encoder_chain(2000)
print(round(deg, 4), round(omega, 2), int(rate), round(tip, 3))
# 0.0009 3.14 200000 0.016

The Complementary Filter as a C Loop

Drift cannot be tuned away after the fact; it has to be prevented inside the update that runs every sample. The filter costs three floating-point operations on any modern core, and its weight decides how quickly the absolute reference corrects the integrated rate: at 100 Hz a weight of 0.98 leaves a time constant near half a second, long enough that accelerometer noise never reaches the output and short enough that a residual bias cannot walk the heading off over a shift.

typedef struct {
    float theta;    /* fused tilt estimate (deg) */
    float alpha;    /* gyro trust, 0.98 typical   */
} fusion_t;

float fusion_update(fusion_t *f, float gyro_dps, float acc_deg, float dt_s)
{
    f->theta = f->alpha * (f->theta + gyro_dps * dt_s)
             + (1.0f - f->alpha) * acc_deg;
    return f->theta;
}

Starting from 10.0 deg with a rate of 2 deg/s, an accelerometer tilt of 12 deg, and a 10 ms step, the update returns 10.06 deg: the gyro carries the motion while the accelerometer contributes its two percent.

Common Mistakes

Quoting encoder counts without the gear ratio

Fix: Motor-side counts are meaningless at the joint; multiply by the gear ratio first, which turns 4000 into 400,000 counts per output revolution.

Integrating a raw gyro for heading

Fix: A 0.02 deg/s bias becomes 6 deg in five minutes, so blend an accelerometer, a magnetometer, or a kinematic constraint to arrest the drift.

Ignoring quantization when tuning a loop

Fix: If the error sits inside plus or minus half a count, the integrator will chatter; either raise resolution or add a deadband.

Key Takeaways

  • Encoder chain: 1000 CPR times 4 times a 100:1 gear gives 400,000 counts per revolution and 0.0009 deg per count.
  • Velocity is differenced counts over time: 2000 counts in 10 ms equals 3.14 rad/s at the joint.
  • Gyro bias integrates without bound, theta err equals b times t, so a complementary filter with alpha near 0.98 is mandatory.
  • A 62.5 N reading is 512 ADC counts and 500 microstrain, resolving 0.122 N per count before noise.

Frequently Asked Questions

Why is the quadrature multiplier four?

Two channels offset by 90 degrees produce four distinct edge events per disk cycle, so decoding both edges of both channels multiplies the base resolution by four with no extra hardware.

Why does a gyro drift while an accelerometer does not?

The gyro reports rate, so any bias accumulates during integration. The accelerometer measures an absolute reference, gravity, so its error stays bounded even though it is noisy and blind to rotation.

Does a fine encoder make a robot accurate?

No. Encoder resolution sets the smallest move you can command, while accuracy depends on link lengths, frame calibration, and thermal growth. A 0.00275 deg encoder can still point 1 mm off if the tool frame is wrong.

Interview Questions

Q1: How many counts per second does a 1000 CPR quadrature encoder produce at 3000 rpm?

3000/60 = 50 rev/s, times 1000 cycles, times 4 for quadrature, gives 200,000 counts per second, which the counter must handle without overrun.

Q2: What angular resolution does a 21-bit absolute encoder give?

360 divided by 2^21 = 360/2,097,152 = 0.00017 deg per position bit.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-16

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Robotics & Mechatronics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement