IMU & Inertial Navigation

An IMU never measures where you are. It measures change, and you add the change up. Sit a phone-grade IMU still for one minute and the sum says it moved 64 m. A navigation-grade IMU says 0.45 m.

Pick an IMU grade and watch a drone that never moves walk away from its pad. Then we build, piece by piece, what the sensor reads, the frames, the three strapdown stages, the drift laws, the noise, and the first cure.

You need integration as adding up and a little arithmetic. We build the rest from zero.

Lesson 13 of 22 in Sensor Fusion: Classical to Modern. It follows Data Association and leads to INS/GNSS Coupling.

Leave a drone on its pad

Illustrative, order of magnitude: constant biases only, no noise. Phone: gyro 36°/hr, accel 0.01 m/s². Tactical: 1°/hr, 0.001 m/s². Navigation: 0.01°/hr, 0.00025 m/s². The accel error runs north, the gyro error east.

Chapter 0

The Drone That Never Moved

Add up a still sensor's readings and watch the position walk away

A drone hovers over its landing pad, perfectly still. A small chip on its back reads motion a thousand times a second. You add up the motion it reports to track the drone. After ten seconds the sum says the drone is half a metre off the pad. It has not moved.

The chip is an inertial measurement unit (IMU): three accelerometers and three gyroscopes, the same parts as in your phone. Nothing is broken. An IMU measures change, never position. To get position you add the change up twice, and you add up its small errors too.

Integrate a still accelerometer

The drone is still, so the true position is the dashed zero line. The accelerometer adds a small constant error. Set it, press Run, and watch the blue estimate.

0.010 m/s²

Illustrative: a 100 Hz accelerometer with the bias you set plus small white noise, integrated twice with simple sums.

A constant error of 0.01 m/s² is one thousandth of gravity. After 60 s it becomes 18 m of position error. The curve is a parabola: the error does not only grow, it grows faster and faster.

Adding up your own motion from a known start is called dead reckoning. Sailors did it with a compass and a speed log. They fixed the growing error with a star or a lighthouse. Modern systems do the same with GPS, a camera, or a moment when they know they are still.

The idea of the lesson. An IMU is a brilliant short-term sensor and a hopeless long-term one. It updates at hundreds of hertz and works in tunnels and in the dark. Its errors grow as time squared or cubed, so every real system corrects it with something absolute.

The road

  1. What an IMU measures: rate of turn, and a force that is not acceleration.
  2. Two frames: the body the sensor rides on, and the world you report in.
  3. Strapdown: three stages turn six numbers into a pose.
  4. The drift laws: why accel bias grows as t² and gyro bias as t³.
  5. Noise and the Allan plot: random walk, and reading a datasheet.
  6. Grades: how long each class of IMU can coast.
  7. Showcase: dead-reckon a loop, then stop at each corner.
  8. Read the symptom: calibrate at rest, and diagnose a log by its shape.
  9. Field guide: the numbers, the checklist, the code.
A still drone's accelerometer has a constant bias of 0.01 m/s². Why does the dead-reckoned position end 18 m off after 60 s?

Chapter 1

What an IMU Measures

Read turn rate from the gyro, and learn why the accelerometer reads up when it sits still

The gyroscope measures angular rate: how fast the sensor turns about each of its three axes, in degrees or radians per second. Spin it at a steady 90°/s and it reads 90°/s the whole time. It gives rate, not angle. To know which way you point, you add the rate up over time.

The accelerometer is the trap. Inside it, think of a small proof mass on a spring. The chip reports how far the spring stretches. Gravity pulls on the mass and on the case equally, so gravity alone does not stretch the spring. Only a push on the case does.

Put the accelerometer somewhere

Choose a situation. Watch the spring and the three arrows: true acceleration a in yellow, gravity g in pink, the reading f in blue.

Exact physics in one dimension, up is positive, g = −9.81 m/s². The lift moves up and speeds up or slows at 2 m/s².

So the accelerometer reads the push that stops you falling. Call that push per kilogram the specific force f. Call your true acceleration through space a, and the gravity vector g. With up as positive, g is −9.81 m/s².

Say it aloud

f equals a minus g.

f
f the specific force: what the accelerometer reads, in m/s².
a
a the true acceleration of the sensor through space, in m/s². This is what navigation needs.
g
g the gravity vector: 9.81 m/s² pointing down, so −9.81 with up positive.
In plain words

Take the true acceleration a and remove gravity g. What is left is the reading f. To recover a, add g back: a = f + g.

With numbers

On a table, a = 0, so f = 0 − (−9.81) = +9.81 m/s², pointing up. In free fall a = g, so f = 0. In a lift speeding up at 2 m/s², f = 2 + 9.81 = 11.81 m/s²: you feel heavier.

Adding g back is easy only if you know which way down is. Down comes from the attitude, and the attitude comes from the drifting gyro. If the attitude is off by 0.1°, a slice of gravity leaks sideways: 9.81 × sin 0.1° = 0.017 m/s². That leak is larger than a good accelerometer's whole bias.

So an IMU gives six numbers, hundreds of times a second: three angular rates ω and three specific forces f, both in the sensor's own axes. Orientation, velocity and position are not in that list. You build them.

An accelerometer lies still on a desk. What does it read?

Chapter 2

Body Frame, World Frame

Move readings from the tumbling sensor into the steady world, and catch the sign bug

The IMU reports everything along its own axes. Those axes roll and pitch with the vehicle. You want answers along fixed world directions: north, east, down. A frame is a set of three axes, and inertial navigation uses three of them.

FrameFixed toAxesUsed for
Body (b)the sensorx forward, y right, z down (aerospace)the raw ω and f
Navigation (n)a point on EarthNED: north, east, down. Or ENU: east, north, upvelocity and position you report
Earth (e, ECEF)Earth's centre, turning with itx through 0° latitude and longitude, z through the poleGPS coordinates, long flights

The attitude is the rotation from the body frame to the navigation frame. Store it as a 3 by 3 rotation matrix C or as a four-number quaternion. Most strapdown code uses the quaternion, because it stays clean when renormalised. Multiply a body vector by C and you get the same arrow in world axes.

Tilt the vehicle, then flip an axis

The vehicle sits still. The blue arrow is its reading, always 9.81 m/s² up. Tilt it and watch the reading split across the body axes. Then feed it to code that expects the other z sign.

20°

Exact geometry in the pitch plane. "z axis flipped" feeds a z-up body frame (ROS style) into code written for z-down.

At 20° of pitch the reading splits into 3.36 m/s² along the nose and 9.22 m/s² along the body z axis. Rotate it back with the right attitude, add gravity, and the vertical acceleration is zero. The vehicle is still, and the numbers agree.

Now the most common frame bug. A z-up IMU reports +9.81 on z at rest. Code written for z-down treats that as 9.81 downward and adds gravity, another 9.81 downward. It computes 19.62 m/s²: twice gravity. After 2 s the altitude estimate has dropped 39 m.

Failure: a 2g runaway. Symptom: the vertical channel runs away at almost exactly 19.6 m/s² the moment you start. Measure: the computed vertical acceleration at rest. Fix: write the frame convention at the top of the file and check the sign of g against it.
Your altitude estimate runs away at about 19.6 m/s² the moment the vehicle starts, while it sits still. What is the likely cause?

Chapter 3

Strapdown: Six Numbers to a Pose

Run the three stages every tick, attitude first, and watch one gyro error flow through all three

Old systems held the sensors level on gimbals. Modern systems bolt them to the vehicle and level them in software. That is strapdown mechanization: three stages, run every IMU tick, in a fixed order.

  1. 1. Attitude. Add up the gyro rate to update which way the vehicle points.
  2. 2. Acceleration. Rotate the specific force into world axes with that attitude, then add gravity back.
  3. 3. Velocity and position. Add up acceleration into velocity, and velocity into position.

Stage 2 needs to know where down is, so stage 1 must come first. Work in the pitch plane to keep it small. Call the pitch angle at tick k theta-k, the gyro rate omega-k, and the time between ticks delta-t.

Say it aloud

theta-k-plus-one equals theta-k plus omega-k times delta-t.

θk+1
theta-k-plus-one the attitude angle after this tick, in degrees.
θk
theta-k the attitude angle before this tick.
ωk
omega-k the gyro reading at this tick, in degrees per second. Any bias rides along.
Δt
delta-t the time between ticks: 1 divided by the IMU rate, 0.005 s at 200 Hz.
In plain words

Multiply the gyro rate omega-k by the tick length delta-t. Add that small turn to the old angle theta-k.

With numbers

theta-k = 10°, omega-k = 30°/s, delta-t = 0.005 s. The turn is 0.15°, so theta-k-plus-one = 10.15°. A bias of 0.01°/s adds 0.00005° per tick: 0.6° after 12,000 ticks, one minute.

In 3-D the same step multiplies C by a small rotation, (I + ΩΔt), where Ω holds the three gyro rates. Next, call the reading in body axes f-b, the attitude rotation C, gravity in world axes g-n, and the world acceleration a-n.

Say it aloud

a-n equals C times f-b, plus g-n.

an
a-n the true acceleration in world axes, in m/s².
C
C the attitude: the rotation from body axes to world axes, built from stage 1.
fb
f-b the accelerometer reading in body axes.
gn
g-n gravity in world axes: (0, 0, +9.81) in NED.
In plain words

Turn the reading f-b into world axes with C. Add gravity g-n back. The result a-n is the acceleration you can add up.

With numbers

A level car speeds up at 2 m/s². It reads 2 forward and 9.81 up. Rotate with the true attitude, add gravity: a-n is 2 forward, 0 vertical. With C off by 0.6°, a-n is 2.103 forward: 0.103 m/s² of phantom push, all from gravity.

Last, call the velocity at tick k v-k and the position p-k. Two sums finish the loop.

Say it aloud

v-k-plus-one equals v-k plus a-n times delta-t. p-k-plus-one equals p-k plus v-k times delta-t.

vk+1
v-k-plus-one the velocity after this tick, in m/s.
an
a-n the world acceleration from stage 2.
pk+1
p-k-plus-one the position after this tick, in metres.
vk
v-k the velocity before this tick. Using the old value is the simplest sum, called Euler.
In plain words

Add a-n times delta-t to the velocity. Add the old velocity v-k times delta-t to the position. Repeat every tick.

With numbers

v-k = 3 m/s, a-n = 2 m/s², delta-t = 0.01 s. v-k-plus-one = 3.02 m/s and the position moves 3 × 0.01 = 0.03 m.

Step the loop with a biased gyro

The vehicle sits still. The gyro has a bias you set. Press Step to run one second of ticks and watch the error pass through the three stages.

0.50°/s

Illustrative: a bias far larger than a real gyro's, so the chain shows in seconds. 100 Hz ticks, pitch plane, exact sine of the attitude error.

The failure to watch for is fast motion. If the vehicle vibrates faster than the tick rate can follow, the simple sums under-rotate (coning) and invent velocity (sculling). Production code adds correction terms and runs at kilohertz on a drone with propeller vibration.

Why must the attitude update run before the specific force is rotated and gravity is added back?

Chapter 4

Drift Grows With Time Squared and Cubed

Derive both drift laws from the three stages and see why the gyro wins the race to ruin

Two small constant errors start everything. The accelerometer reads too much by the same amount every tick. The gyro reads a turn that is not there. Follow each one through the strapdown loop.

Call the accelerometer's constant error the accel bias b-a, and the time since the start t. Stage 3 adds it up once into a velocity error b-a times t. It adds that up again into position.

Say it aloud

delta-p equals one half times b-a times t squared.

δp
delta-p the position error, in metres.
½
one half what adding up a straight-line ramp gives: the area of a triangle.
ba
b-a the accel bias, in m/s².
t²
t squared the time since the last fix, in seconds, multiplied by itself.
In plain words

Square the time t. Multiply by the bias b-a and halve it. That is how far the estimate has walked.

With numbers

b-a = 0.01 m/s². At t = 10 s, delta-p = 0.5 × 0.01 × 100 = 0.5 m. At 60 s, 18 m. At 300 s, 450 m. The phantom speed at 60 s is 0.01 × 60 = 0.6 m/s.

Now the gyro. Call its constant error the gyro bias b-g, in radians per second, and gravity's size g. Stage 1 turns it into an attitude error b-g times t. Stage 2 then tilts gravity by that angle, so a slice g times b-g times t leaks sideways. That leak already grows with time, and stage 3 adds it up twice.

Say it aloud

delta-p equals one sixth times g times b-g times t cubed.

δp
delta-p the position error caused by the gyro bias, in metres.
(1/6)
one sixth what adding up a ramp twice gives: t, then t squared over 2, then t cubed over 6.
g
g gravity, 9.81 m/s². It amplifies the tiny angle error.
bg
b-g the gyro bias, in radians per second (degrees per second times pi over 180).
t³
t cubed the time since the last fix, multiplied by itself three times.
In plain words

Convert b-g to radians per second. Multiply by gravity g and by t cubed, then divide by 6. The gyro path has one more sum than the accel path, so it gets one more power of t.

With numbers

b-g = 0.01°/s = 0.0001745 rad/s. At 60 s the attitude error is 0.6°, and delta-p = 9.81 × 0.0001745 × 216,000 / 6 = 61.6 m. At 10 s it is only 0.29 m.

Race the parabola against the cubic

Blue is the accel-bias parabola, warm is the gyro-bias cubic, the thin line is their sum, the worst case where both push the same way. Drag the two biases and find where the cubic takes over.

0.010 m/s²
0.010°/s

Exact closed forms, constant biases only, short times. Past about 10 minutes gravity starts to pull a tilted estimate back (the Schuler effect), and these laws overstate the error.

Set the two curves equal and solve for t: the cubic passes the parabola at t = 3 b-a / (g b-g). With the default numbers that is 17.5 s. After that, gyro quality decides your error, which is why a navigation-grade IMU spends most of its cost on the gyros.

Failure: no ceiling. Symptom: the error never levels off, however long you wait. Measure: fit the error log to a t² or a t³ curve. Fix: none inside the IMU; inject an absolute fix (GPS, a landmark, a known stop) that resets the error.
Why does a constant gyro bias give a t³ position error, while a constant accel bias gives t²?

Chapter 5

Noise, Bias and the Allan Plot

Tell the error types apart, and read them all off one curve on a datasheet

One constant bias was a simplification. A real IMU axis has several errors, each with its own cure.

ErrorWhat it isCure
Turn-on biasan offset that changes at each power-upaverage at rest, subtract
In-run biasthe bias wandering slowly while you runestimate it online, as a filter state
Scale factorthe reading off by a percentage: 0.1% of a 100°/s turn is 0.1°/scalibrate on a rate table
Misalignmentaxes not square, so x motion leaks into ycalibrate a 3 by 3 correction
White noisea fresh random error on every sample, average zeronothing removes it; model it

White noise averages to zero, but its sum does not stay at zero. It wanders like a drunk walker, and the spread grows as the square root of time. For a gyro, the sum is an angle, and this wander is the angle random walk (ARW). Call the datasheet's ARW number N and the time t.

Say it aloud

sigma-theta equals N times the square root of t.

σθ
sigma-theta the spread of the heading error from noise alone: one standard deviation, in degrees.
N
N the angle random walk from the datasheet, in degrees per root-hour.
√t
the square root of t the time since the last fix, in hours, under a square root.
In plain words

Write the time t in hours. Take its square root. Multiply by N. Four times the time gives only twice the error.

With numbers

N = 0.3°/√hr. After 10 minutes, t = 1/6 hr and √t = 0.408, so sigma-theta = 0.12°. After 1 hour, 0.3°. After 4 hours, 0.6°.

The accelerometer has the same law for velocity, the velocity random walk (VRW), in m/s per root-hour. To measure all of these, log the IMU at rest for hours. Cut the log into bins of length tau, average each bin, and measure how much neighbouring averages differ. That spread against tau is the Allan deviation.

Shape an Allan curve

The purple curve is the Allan deviation of a gyro. Each dashed line is one error. Drag the three knobs and read the noise at tau = 1 s and the floor.

0.30°/√hr
5.0°/hr
10°/hr/√hr

The standard three-term model (IEEE Std 952): N²/tau, plus 0.44 B², plus K² tau / 3, under a square root. Knob values are illustrative, MEMS-like.

Part of the curveSlope on log axesError it shows
Left, short taufalls, −1/2white noise: read ARW at tau = 1 s
Bottomflat, 0bias instability: the floor is about 0.66 B
Right, long taurises, +1/2bias random walk: averaging longer now hurts
Failure: a short log. Symptom: the right arm never appears, so the sensor looks better than it is. Measure: the longest tau needs about ten bins, so a 1-hour log stops near 6 minutes. Fix: log for many hours, at a steady temperature.
A gyro lists ARW = 0.3°/√hr. About how much heading spread does noise alone add in 10 minutes?

Chapter 6

How Long Can You Coast?

Turn the cube law around to find how long each grade of IMU stays useful alone

A car enters a tunnel and loses GPS. How long can its IMU navigate alone before the error passes 10 m? The answer depends on the IMU's grade: the class it belongs to, set mostly by its gyro bias.

GradeGyro bias (rough)Where you find it
Consumer MEMS10 to 100°/hr, and worsephones, drones, headsets
Tactical1 to 10°/hrUAVs, robots, guided munitions
Navigationabout 0.01°/hrairliners, ships, submarines
Strategicbelow 0.001°/hrstrategic submarines, ballistic missiles

Call the error you can accept the budget D, in metres. Set the gyro's cube law equal to D and solve for the time. Call that time the coast time, t-c.

Say it aloud

t-c equals the cube root of six D over g times b-g.

tc
t-c the coast time: how long the IMU navigates alone before the gyro error reaches the budget, in seconds.
∛( )
the cube root of the number that, multiplied by itself three times, gives what is inside.
6 D
six D six times the error budget D, in metres.
g
g gravity, 9.81 m/s².
bg
b-g the gyro bias, in radians per second.
In plain words

Multiply the budget D by 6. Divide by gravity g times the gyro bias b-g. Take the cube root. That is how long you can coast.

With numbers

D = 10 m. A tactical gyro of 1°/hr is 0.00000485 rad/s. 60 / (9.81 × 0.00000485) = 1,262,000, and its cube root is t-c = 108 s. A phone gyro of 36°/hr gives 33 s.

Set a budget, read the coast time

Each bar is how long one grade coasts before its gyro error reaches the budget. Drag the budget and watch the bars move by only a cube root.

10 m

Illustrative: the gyro term only, constant bias. Phone 36°/hr, tactical 1°/hr, navigation 0.01°/hr, strategic 0.001°/hr. Past about 10 minutes the Schuler effect bounds the error, so the cube law is only a guide there.

The cube root is brutal. To coast twice as long at the same budget, you need a gyro eight times better. That is why each step up the ladder costs an order of magnitude more.

Failure: buying by price alone. Symptom: a costly IMU that still drifts out in the tunnel, or a cheap one that would have done. Measure: your longest gap between fixes and your error budget. Fix: solve t-c for each candidate before you buy.
You want to coast twice as long with the same error budget. How much better must the gyro bias be?

Chapter 7

Showcase: Dead-Reckon, Then Stop

Drive a loop on a biased IMU, then use each stop to reset the velocity and learn the bias

A walker's foot is flat on the ground for a moment in every stride. A car stops at a light. At that moment the true velocity is exactly zero, and you know it without any other sensor.

A zero-velocity update (ZUPT) uses that fact. At each known stop it does two things:

  1. Set the velocity estimate to zero. The phantom speed that the accel bias built is gone.
  2. Average the accelerometer while still. The true acceleration is zero, so the average is the bias. Subtract it from then on.

Drive three laps, then add ZUPT

The dashed loop is the true path; the vehicle stops at each corner. Warm is pure dead reckoning. Turn ZUPT on for the teal estimate, then raise the biases.

0.10°/s
0.020 m/s²

Illustrative toy: a 20 m by 12 m loop at 2 m/s with a 3 s stop at each corner. The 100 Hz IMU has the biases you set plus small noise. ZUPT here resets velocity and learns the accel bias; it does not touch heading. On a loop the accel bias turns with the vehicle and partly cancels; on a straight road it would not.

With the default biases, pure dead reckoning ends 19 m off after three laps (144 s). With ZUPT it ends about 3 m off. The error that remains is heading: a stop tells you the speed is zero, not which way you face.

Walking trackers with an IMU on the foot run a ZUPT at every step. That alone turns hopeless MEMS drift into metre-level tracking over hundreds of metres, with no GPS. Many also add a zero angular rate update at rest, which learns the gyro bias the same way.

Failure: a false stop. Symptom: the path jerks short and the bias estimate jumps. Measure: the stop detector's gyro and accel thresholds against a log of slow motion. Fix: require both quiet gyro and quiet accelerometer for a minimum time before you declare a stop.
A foot-mounted MEMS IMU tracks a walker to about a metre over hundreds of metres with no GPS. What makes this possible?

Chapter 8

Read the Symptom

Calibrate at rest, then name a bug from the shape of its error

The cheapest calibration is free. Before you move, hold the IMU still for a few seconds and average each axis. The gyro should read zero, so its average is the turn-on gyro bias. The accelerometer should read gravity's 9.81 m/s² upward, so its average minus that is the accel bias.

pythonimport numpy as np

def calibrate_at_rest(gyro, accel, g=9.81):
    # gyro, accel: arrays (n, 3) logged while the IMU sits still and level, z axis down
    gyro_bias  = gyro.mean(axis=0)                     # should read 0, so the mean IS the bias
    accel_bias = accel.mean(axis=0) - np.array([0, 0, -g])  # should read -g on z (support force up)
    if abs(accel_bias[2]) > g:                          # a "bias" near 2g is a frame bug, not a bias
        raise ValueError("z bias near 2g: check the z sign convention")
    return gyro_bias, accel_bias
# every live sample:  gyro_c = gyro - gyro_bias ;  accel_c = accel - accel_bias

This removes only the turn-on bias. The in-run bias keeps wandering, so a good fuser keeps estimating it as a filter state. After calibration, the shape of any remaining error names its cause.

Diagnose a still IMU

Each choice plants one fault in a 30 s log of a still IMU. Read which trace bends and how. Then calibrate at rest and see which faults survive.

Illustrative faults: accel bias 0.02 m/s², gyro bias 0.05°/s, a flipped z axis. The warm-up bias grows from 0 to 0.03 m/s². Calibration averages the first 2 s.

A straight velocity ramp at rest is an accel bias, and its slope is the bias itself.

slope = δv / t = ba  ·  a ramp of 0.6 m/s over 30 s means ba = 0.02 m/s²

SymptomCauseFix
Velocity ramps at restaccel biascalibrate at rest; the slope is the bias
Heading ramps, path curvesgyro biasaverage the gyro at rest
Vertical runs away at 2gframe or gravity signcheck the z convention and the sign of g
Bias tracks chip temperaturethermal driftwarm up first, or apply the temperature curve
Acceleration flat-tops in hard movesclipping at full scaleraise the range, such as ±16 g
Fused error grows with speedtime offset between sensorshardware timestamps, or estimate the offset
A parked car's speed estimate climbs in a straight line. What is the cause, and how do you read its size?

Chapter 9

Field Guide

Keep the equations, the numbers, the checklist and the code in one place

An IMU reads turn rate and specific force in its own axes. Strapdown adds the gyro up into attitude, uses it to rotate the reading and add gravity back, and adds the result up twice. Every constant error rides those sums into t² or t³ growth, so an IMU predicts and something absolute corrects.

QuantityFormulaNumbers from this page
Specific forcef = a − gat rest +9.81 up; free fall 0; lift 11.81
Attitude stageθk+1 = θk + ωkΔt10° + 30°/s × 0.005 s = 10.15°
Acceleration stagean = C fb + gn0.6° off: 0.103 m/s² phantom push
Integration stagevk+1 = vk + aΔt, pk+1 = pk + vkΔt3 m/s to 3.02 m/s, +0.03 m
Accel bias driftδp = ½ ba t²0.01 m/s²: 18 m at 60 s
Gyro bias driftδp = (1/6) g bg t³0.01°/s: 61.6 m at 60 s; crossover 17.5 s
Angle random walkσθ = N √t0.3°/√hr: 0.12° in 10 min
Coast timetc = ∛(6D / (g bg))10 m budget: phone 33 s, tactical 108 s

Checklist

  1. Write the frame convention (NED or ENU, body z up or down) at the top of the file.
  2. Check that a still, level IMU computes zero world acceleration.
  3. Average the gyro and accelerometer at rest; subtract the turn-on biases.
  4. Run attitude, then acceleration, then velocity and position, every tick.
  5. Sample much faster than the vibration; use coning and sculling corrections at high rates.
  6. Pick the grade by solving the coast time for your longest gap.
  7. Fuse with an absolute reference, and keep the biases as filter states.
pythonimport numpy as np

def strapdown_step(theta, v, p, gyro, f_body, dt, g=9.81):
    # pitch plane, world axes (x forward, z down); f_body = (f_x, f_z) in body axes
    theta = theta + gyro * dt                       # 1. attitude: add up the turn rate
    c, s = np.cos(theta), np.sin(theta)
    C = np.array([[c, s], [-s, c]])                  # body -> world rotation for pitch theta
    a = C @ f_body + np.array([0.0, g])          # 2. rotate, then add gravity back (+g on down)
    p = p + v * dt                               # 3. position from the OLD velocity
    v = v + a * dt                               #    velocity from the acceleration
    return theta, v, p

# still and level: f_body = (0, -g)  ->  a = (0, 0). A biased gyro tilts C and leaks g into a[0].

Where IMUs run

SystemGradeWhat corrects it
Phones, AR and VR headsetsconsumer MEMScamera, magnetometer, GPS, many times a second
Dronesconsumer MEMS, gyro read at kilohertzGPS, barometer, camera
Cars and robotsautomotive to tacticalGNSS, wheel odometry, lidar, camera
Walking trackersMEMS on the foota ZUPT at every step
Airliners, ships, submarinesnavigationoccasional GNSS or a surfacing fix

In every row the IMU does one job: it predicts motion fast and smoothly between slow absolute fixes. Only the grade and the correcting sensor change. That split is the predict and update steps of the Kalman filter.

Keep going

References

The takeaway. An IMU is a memory with no eyes. It remembers well where it was and forgets fast where it is. Attitude first, gravity back, two sums, then open its eyes as often as the coast time demands.
In a navigation filter, which role does the IMU play, and why does it need an absolute sensor?

Now press Present or Teach and derive it from memory: specific force, the three stages, both drift laws, the random walk and the coast time. Then go back to the pad and say why the phone-grade drone curves away.

Credit

Lesson 13 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The derivations follow Groves (2013) and Titterton and Weston (2004). Every toy number on this page carries the word illustrative.

Sensor Fusion: Classical to Modern · Lesson 13: IMU & Inertial Navigation
Previous: Data Association · Next: INS/GNSS Coupling · Back to Gleams