Chapter 07 · Build a repeatable robot laboratory in Gazebo
Today in the field story
One problem, then the next
The Rainy-Day Simulator Lab now adds one imperfection at a time: random spread, bias, rate reduction, delay, and frozen source time. Preserve seed, original measurement, arrival time, and consumer age. Compare precision with accuracy and repeat fixed seeds plus a declared seed set, while admitting that a seed does not freeze callback order, GPU behavior, or every plugin.
- Why now
Consumers need named imperfection models and timestamps before they can make health decisions.
- Ignore today
Ignore claims that Gaussian noise alone makes a sensor realistic.
- Unlocks next
Repeatable bad cases for recording and degraded-mode tests.
Understand
Build the physical picture first
Sensor data is a delayed, imperfect stream of measurements; useful simulation makes each imperfection named, measured, and repeatable.
Noise is not one slider labelled realism. Random noise makes repeated measurements spread around a value. Bias shifts their centre away from truth. Drift changes that bias over time. Quantization rounds a continuous value into steps. Saturation clips values outside a limit. Dropout removes samples, and latency delivers an old observation later. A real sensor can contain several of these at once. Add them one at a time with values justified by a datasheet or measured dataset so you can recognize each signature.
Update rate says how often a sensor is intended to produce data. Its nominal period is one divided by rate: a 20 Hz lidar has a 0.05 s or 50 ms period. Actual arrival intervals can vary; that variation is jitter. Timestamp, receipt time, and processing time answer different questions. Sensor age at use is the current simulation time minus the measurement stamp, not the time since the callback began. A message can arrive rapidly yet carry a frozen old stamp, so rate and freshness need separate checks.
Sensors observe at different moments. A 200 Hz IMU may produce ten measurements during one 20 Hz lidar period, while a 30 Hz camera follows another schedule. Exact-time matching can discard nearly everything when clocks do not align; approximate synchronization accepts a declared time window but introduces alignment error. Geometry must use the transform for each measurement time. Applying the newest robot pose to an older scan bends the reconstructed world whenever the robot moved between observation and processing.
Random seeds help reproduce supported random processes, but a seed does not freeze thread scheduling, GPU behavior, callback order, or every plugin. Run several seeds to learn a distribution, and pin one or more named seeds for regression cases. Record mean error, spread, maximum gap, invalid count, and age rather than showing only a smooth plot. The aim is not to make simulation look messy; it is to verify that the system detects and handles the specific imperfections expected at its interfaces.
Words you need
Name each idea precisely
- Bias
A systematic offset that moves the average measurement away from the reference value.
Physical example:A scale reads 0.15 kg when empty, so every load appears about 0.15 kg too heavy until corrected.
- Precision
How closely repeated measurements agree with one another, which is different from agreement with truth.
Physical example:Ten readings all near 2.20 m are precise even if the actual distance is 2.00 m.
- Jitter
Variation in the time interval or delay from one sensor sample to the next.
Physical example:A nominal 50 ms lidar period alternates among 42, 53, and 61 ms.
- Sensor age
Current experiment time minus the timestamp of the physical observation being used.
Physical example:At simulation time 8.35 s, using a scan stamped 8.10 s means the scan is 250 ms old.
- Random seed
An initial value used to reproduce a supported pseudo-random noise sequence.
Physical example:Two runs with seed 17 may produce the same configured range-noise sequence while OS callback ordering can still differ.
Math, one line at a time
Work through today’s relationship
Prerequisite rescue · optionalSimulation time, real-time factor, and sensor noise
A simulator is useful only when time and uncertainty are measured honestly.
- RTF
- simulated elapsed time divided by real elapsed timeUnit: unitless
- μ
- average sensor valueUnit: sensor unit
- σ
- typical spread around the averageUnit: sensor unit
A run simulates 20 s but takes 25 s of wall time.
RTF = 20/25 = 0.8.
The simulator is slower than real time; compare timestamps in simulated time and report RTF with every performance result.
A test clock can be mocked in web software; robot sensor timestamps must still stay mutually consistent.
Ten simulated seconds take five real seconds. What is RTF?
10/5 = 2.0, so simulation runs twice as fast as real time.
For samples ,
At , a alignment error corresponds to of motion. That motion estimate is not a noise model.
Audit a nominal 20 Hz lidar stream
During a 2 s simulation interval, a lidar should publish at 20 Hz. The newest scan is stamped 8.10 s and is processed at simulation time 8.35 s.
Calculate nominal period: 1 ÷ 20 Hz = 0.05 s = 50 ms.
Calculate expected intervals in 2 s: 20 × 2 = 40, allowing boundary counting to be declared consistently.
Measure actual inter-stamp intervals rather than relying only on topic-reported average frequency.
Calculate current sensor age: 8.35 − 8.10 = 0.25 s = 250 ms.
Express age in nominal periods: 250 ms ÷ 50 ms = five periods old.
Apply the declared freshness policy even if callbacks are still arriving quickly.
The data being used is 250 ms, or five nominal lidar periods, old and should be classified according to an explicit age limit.
Rate, arrival, timestamp progression, and age are different health signals.
Physical examples
Where this appears in real life
Kitchen scale test
An empty scale repeatedly shows values around 15 g, with readings varying by a few grams and jumping in 1 g increments.
Separate bias, random spread, and quantization instead of calling the whole pattern noise.
Delayed sports commentary
A live video and internet commentary describe the same match, but the commentary arrives later and with uneven delays.
Receiving frequent words does not make them current; label event time, arrival time, delay, and jitter separately.
Hands-on exercise
Make the idea observable
Use one fixed target at a known lidar distance and a saved straight-drive scenario with simulation time enabled everywhere.
Capture a clean baseline of measurement value, stamp interval, receipt interval, age, invalid count, and transform lookup result.
Add a documented random range-noise standard deviation with a fixed seed and run enough samples to calculate mean and spread.
Add one separate bias, then one separate update-rate reduction; predict each signature before running.
Inject a delayed or frozen timestamp without stopping message arrival and verify that freshness detection differs from rate detection.
Restore the baseline, rerun it, and preserve configuration, seed, raw samples, plots, and a table of expected versus observed effects.
Random spread, shifted mean, slower period, late arrival, and frozen time produce distinguishable evidence when captured separately.
A second engineer can reproduce all four imperfection signatures and your consumer rejects or degrades each according to a written contract.
Build today
Simulate a ros2_control differential-drive robot in Gazebo Harmonic with lidar, RGB-D camera, IMU, noise, bridges, and MCAP replay.
Evidence to save
DONE when the integrated “Sensor noise, update rate, and timestamp alignment” path is observable, cancelable, and leaves the prior baseline reproducible.
Common mistakes
Catch the wrong mental model
Adding large Gaussian noise and calling the sensor realistic.
Model justified random spread, bias, drift, quantization, saturation, latency, and dropout as separate documented mechanisms.
Checking callback frequency but not whether message timestamps advance.
Track stamp progression, arrival intervals, and age at use independently.
Using one fixed random seed as the only reliability test.
Keep fixed seeds for reproducible regressions and also run a declared set of seeds to measure outcome variation.
Job connection
How this becomes employable evidence
Turn a lidar datasheet and field sample into a Gazebo fault profile, then prove a ROS consumer handles noise, bias, low rate, delay, and frozen timestamps without frame-time corruption.
Relevant target roles
- Robotics Deployment, Integration & Validation Engineer
- Robotics Application / ROS 2 Integration Engineer
- Robotics Software Engineer — ROS 2 / AMR
Chapter 07 interview drill
Interview questions: Sensor noise, update rate, and timestamp alignment
Practise a 60–90 second answer: define the idea, connect it to a physical robot, state assumptions, frames, and units when relevant, then finish with the failure signal or evidence you would inspect.
Primary interview scenario
A sensor monitor reports 20 Hz, but navigation steers from an old scene. Explain how high callback rate can coexist with stale observations and what timestamps and ages you would capture.
Answer shape: clarify the situation → trace the physical and software path → test the most likely boundaries → name the evidence that would confirm the result.
Technical follow-up questions
Q1What is the nominal period of a 40 Hz sensor?
1 ÷ 40 s = 0.025 s, or 25 ms.
Q2Can a measurement stream be precise but inaccurate?
Yes. Repeated values can cluster tightly while a bias places that cluster far from truth.
Q3Why is receipt time not enough to calculate observation age?
Receipt time says when data arrived; age requires the original measurement timestamp and the current time in the same clock domain.