Engineering Guides · Module 11
Choosing process and measurement noise
The filter trusts a measurement more when Q is large relative to R. Choose R from the sensor and tune Q against the motion model’s real error.
Assumptions: Numbers in the examples are illustrative and the code is executed by the site’s tests. Facts taken from a cited source are marked; other statements are general engineering knowledge and must be confirmed on the datasheet of the part you use.
1. Engineering problem
A localisation filter blends a motion model with measurements. Q says how much the motion model can be wrong between steps; R says how noisy each measurement is. Wrong values give a filter that lags (Q too small) or jitters (Q too large).
2. When is this needed?
- Setting up robot_localization or a custom filter.
- When the pose lags the truth or jitters.
- After changing a sensor.
3. Selection and design decisions
The robot_localization documentation (read 2026-11-06) states that the process noise covariance Q “can be difficult to tune” and that “the larger the value for Q relative to the variance for a given variable in an input message, the faster the filter will converge to the value in the measurement”; it can be given as a full matrix or just the diagonal (off-diagonal values are then zero). It also offers dynamic_process_noise_covariance, which scales Q with velocity so that the covariance stops growing when the robot is stationary (default false), and initial_estimate_covariance (P), whose small values make the filter slow to trust early measurements.
| Parameter | Role | Source of the value |
|---|---|---|
| R (measurement covariance) | Noise of each sensor measurement | Sensor datasheet or measured variance; the message covariance |
| Q (process noise) | Model error per step | Tune from the difference between predicted and measured motion |
| P0 (initial covariance) | Initial confidence | Large unless the start state is known |
| Gating threshold | Rejects outliers (see the outlier guide) | Mahalanobis distance |
4. Advantages and disadvantages
- Larger Q follows measurements closely and passes their noise; smaller Q smooths and lags.
- Honest R from the sensor beats a tuned fudge factor; if a driver reports a covariance of zero, supply one.
- Dynamic Q avoids covariance growth at rest and needs a velocity-dependent model.
5. Requirements and constraints
- R reflects each sensor’s real noise at its operating conditions.
- Q is tuned on logged data, not by feel in one manoeuvre.
- Covariances in messages are consistent with the units used by the filter.
6. Architecture
motion model (Q) ──predict──▶ state, P ◀──update── measurement (R) ; gain K = P / (P + R)7. Implementation
- Set R from the sensor’s datasheet or a stationary recording.
- Start with a small diagonal Q and a large initial P.
- Record a manoeuvre and compare predicted and measured motion.
- Raise Q until the lag is acceptable and the jitter is not.
- Check the filter’s covariance against the actual error.
def steady_gain(q, r, steps=500):
p = 1.0
for _ in range(steps):
p = p + q # predict: variance grows by process noise
k = p / (p + r) # Kalman gain
p = (1 - k) * p # update
return k
r = 0.04 # measurement variance (0.2 m std)
for q in (0.0001, 0.001, 0.01, 0.1):
print(f"Q {q:<7} R {r}: steady gain {steady_gain(q, r):.3f}")
x, p, q = 0.0, 1.0, 0.01
for z in (1.0, 1.0, 1.0):
p += q; k = p / (p + r); x += k * (z - x); p *= (1 - k)
print("estimate after three measurements of 1.0:", round(x, 3))Printed (checked by the site’s tests):
Q 0.0001 R 0.04: steady gain 0.049
Q 0.001 R 0.04: steady gain 0.146
Q 0.01 R 0.04: steady gain 0.390
Q 0.1 R 0.04: steady gain 0.766
estimate after three measurements of 1.0: 0.99Reading it: with a measurement variance R of 0.04 the steady-state gain rises from 0.049 (Q = 0.0001) to 0.766 (Q = 0.1): a larger Q makes the filter follow the measurements. After three measurements of 1.0 with Q = 0.01 the estimate has moved from 0 to 0.99. Values are illustrative; real filters have more states and the gain is a matrix.
8. Real examples
- AMR with wheel odometry and a LiDAR pose: Q tuned so that the filter follows the LiDAR pose within one second after a slip.
9. Failure scenarios
- A covariance of zero in a message treated as perfect.
- Q so small that the filter ignores real pose corrections for minutes.
- Tuning on a single straight run.
10. Troubleshooting
- If the pose lags, increase Q or check the sensor delay.
- If it jitters, decrease Q or increase R.
- If the covariance shrinks to zero while the error does not, Q is too small.
11. Validation
- The example prints the lines shown (executed by the site tests).
- On a logged run the filter’s error stays within its reported covariance (consistent) most of the time.
12. Engineering checklist
13. Further references
- robot_localization documentation (ros2 branch): state_estimation_nodes.rst and params/ekf.yaml, read 2026-11-06.