Skip to content

Bringup: a tool for an IMU's bias and noise at rest - #178

Merged
fjp merged 25 commits into
noetic-develfrom
feat/imu-noise-at-rest
Nov 24, 2026
Merged

fjp merged 25 commits into
noetic-develfrom
feat/imu-noise-at-rest

Conversation

@fjp

@fjp fjp commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What and why

Before: noetic-devel has no tool for an IMU's bias and noise. The bench checks on Remo (#169) measured both with a script that isn't in the repository. Bench check 3 in diffbot_firmware/lib/imu/README.md and the comment on the variances in diffbot_base_config.h tell the reader to replace the covariances' starting values with "the variance and the bias" of a stationary recording, without saying how to measure them.

With this pull request:

  1. diffbot_bringup/scripts/imu_noise_at_rest.py reads a rosbag recorded with the robot at rest and prints a report: rosrun diffbot_bringup imu_noise_at_rest.py <bag>, with --topic for another sensor_msgs/Imu topic than /diffbot/imu/data_raw.
  2. The report has four lines about the messages: their number and frame_id, the time from the first header stamp to the last with the rate, the shortest and the longest interval between two header stamps with the number of intervals over 30 ms, and the number of stamps that repeat the stamp before or are earlier than it. The longest interval is printed with ns when one decimal would read as the 30 ms limit.
  3. For the angular velocity and for the acceleration, the report has a table with one row per axis: the mean, the sample variance, the standard deviation and the number of distinct values, and the number of readings under the field's name. The last line is the length of the mean acceleration, gravity as the IMU measures it.
  4. For an input that the tool can't interpret, it prints one line with the file, the topic where it matters and the reason, and ends with status 1.
  5. The firmware's configuration header says what the tool's two results are for. The IMU README names the tool and links the IMU page's section that explains them.
  6. The IMU README says that its bench checks ran on Remo, with a Teensy 3.2 and with Remo's own Teensy 4.0, and links their results in Bench check: Remo with the IMU firmware and command timeout #169. Its table says that the covariances' starting values are larger than the noise at rest measured there.
  7. An install rule, a nose test file registered with catkin_add_nosetests, exec_depend on genpy, rosbag and sensor_msgs, test_depend on python3-nose, rospy and std_msgs.

What the numbers are: at rest, the mean of the angular velocity estimates the bias that remains in the published readings. With the BNO055 in its IMU mode, the chip has corrected these readings for its offset already. The mean of the acceleration is gravity's share on each axis plus the accelerometer's remaining error. The variances are the noise at rest, a baseline for the diagonal of the message's covariances, which the EKF uses to weigh the readings. Driving adds vibration, so a setting changes only after a check while driving.

Why not an Allan-deviation tool: the bench check uses a three-minute recording to measure the variance of the 50 Hz IMU readings and flag repeated or backward header stamps and gaps over 30 ms, while Allan-deviation tools such as allan_variance_ros and imu_utils use hours of data to estimate noise density and drift.

How the tool reads a bag (main() calls read_samples(), imu_statistics() and format_report()):

  1. open_bag() checks that the file starts as a bag file does and opens the file with rosbag. A recording that was cut off has no index and gets a hint to rosbag reindex.
  2. check_topic() asks for the message type of each of the topic's connections before a message is read: the type's name, its checksum and the text of its definition, which the bag stores. A topic with another type than sensor_msgs/Imu, such as a camera's, is refused without loading its messages. For a topic named sensor_msgs/Imu, the tool builds the messages' class from the bag's definition, as rosbag does. The class's checksum has to be the stored one, and its fields have to be those of ROS's sensor_msgs/Imu, down to the fields of its fields.
  3. recorded_samples() reads the messages, converts each to an ImuSample when it is read and sorts the samples by their position in the file. rosbag's reader returns the messages sorted by the recorder's time. A clock that is set back for the recorder and the IMU alike would hide in that order.
  4. to_sample() keeps the header stamp as an integer in nanoseconds, so the intervals and their comparison with 30 ms are exact. A field counts as measured unless the first element of its covariance is −1, which sensor_msgs/Imu defines as "no measurement". A covariance of zeros means "not known" and keeps the reading.
  5. check_samples() runs six checks in the order of SAMPLE_CHECKS: at least two messages, no empty frame_id, one frame_id, finite readings, readings within the tool's limit for a plausible reading (1,000,000 rad/s or m/s²), and two readings of at least one field.
  6. imu_statistics() calculates the stamps' statistics and each field's statistics from the messages that measured the field. The mean and the sample variance come from Python's statistics module. The variance gets the readings as fractions, so that no rounding of the mean or of a squared deviation changes the result. A field with fewer than two readings gets two lines instead of its table, and the tool still ends with status 0.

Limits:

  • The header stamps: the firmware takes a message's stamp before it reads the IMU. The intervals show how regularly the recorded samples were stamped. They don't show when a message arrived, so the report can't show a late delivery. A recording with a repeated or an earlier stamp gets no rate.
  • The 30 ms: one and a half periods of the firmware's 50 Hz. The limit doesn't adapt to a topic with another rate. The report then still has the shortest and the longest interval.
  • At rest only: the variances describe one recording of a standing robot.
  • Damaged files: a file with a changed byte in a reading's digits can still give a report with a wrong number. Uncompressed bags have no checksum.
  • The two recordings of Bench check: Remo with the IMU firmware and command timeout #169 weren't available when this pull request was reworked, so the tool at this head has not run on them. Their numbers in the documentation are those of the tool's first version (de659f8). On the bags that were available, both versions print the same numbers (see the tests).
  • diffbot_base_config.h gains four comment lines above IMU_PUBLISHER_CONFIG. A documentation page that links one of the lines below them by number needs the new number when its pin moves: angular_velocity_variance moves from line 71 to line 75.

How it was tested

The branch's head is afe2e15. It builds on 78616d5, the merge of noetic-devel at 8c83f53 (#217 and #221) into 4ef85e8. That merge had one conflict, in diffbot_firmware/lib/imu/README.md: the unit tests' line keeps noetic-devel's command with both PlatformIO environments and this branch's sentence on the bench checks. 0a26e49, d459abe and afe2e15 then change the tool's docstring on the fractions and the report's two display edges, the tests' helpers and one test value, add five tests, and shorten the README's bench check 3 to a link.

  • At afe2e15:

    • The tool's tests with nose in the dev container's image (Python 3.8.10): 82 tests, OK. These are the 77 tests before, one for a repeated stamp among stamps that advance, one for the unit at 999.96 ms, two for format_longest_interval() and one for the report's intervals line just above the 30 ms limit.
    • With <= 0 changed to < 0 in mean_rate(), the new test of a repeated stamp fails, besides the error of the test with three stamps of zero. With format_duration() instead of format_longest_interval() in the report's intervals line, the new report test fails.
    • Lint as Contributing: document the rules and add local code checks #207's AGENTS.md asks, with the pinned tools of scripts/requirements-lint.txt in a python:3.12-slim container: flake8 . finds nothing, and mypy . reports no issues in 17 source files.
    • CI passed: industrial_ci (run 45302201191), the dev container (run 45302201011), both firmware builds and the firmware's unit tests (run 45302201267), and the Robot container's builds on arm64 and amd64 (run 45302201080).
  • At 4ef85e8: CI passed: industrial_ci (run 45198721727), the dev container (run 45198722120), both firmware builds and the firmware's unit tests (run 45198721497), and the Robot container's builds on arm64 and amd64 (run 45198721827).

  • At c9a39f9, in the dev container's image (ROS Noetic, Python 3.8.10):

    • catkin build succeeds for all 13 packages.
    • catkin run_tests for diffbot_bringup and diffbot_control, and catkin_test_results build: 111 tests, 0 errors, 0 failures, 0 skipped. These are the tool's 77 tests, the IMU sample validator's 30 and the EKF's two stepped-clock tests, each counted once by rostest and once by its test node.
    • Lint: flake8 7.5.0 with ament_flake8's settings and plugins, and mypy 1.10.1 with --python-version 3.8 --disallow-untyped-defs on the tool and its test in one call: no findings.
  • CI at c9a39f9: industrial_ci builds the workspace and runs its tests with the released and with the testing ROS packages (CI run 44611799352). The dev container (run 44611799376), both firmware builds and the firmware's unit tests, and the Robot container's builds and smoke tests pass.

The items below ran before the merge. Tested commit: 6bf992f, except where an item names its parent 13f77a7. The two differ in one line of the report's first line. 9b3f336, the head before the merge, differs from 6bf992f in the words of two docstrings: the tool's 77 tests, flake8 and mypy were rerun on it.

  • The tool's tests, in the dev container's image (ROS Noetic, Python 3.8.10), without network:
    • catkin build diffbot_bringup: no warnings.
    • catkin run_tests diffbot_bringup and catkin_test_results build/diffbot_bringup: 77 tests, 0 errors, 0 failures, 0 skipped. 54 tests call the tool's functions with values whose results can be calculated by hand. 23 run the script as a command on small bags that they write.
  • Lint: flake8 7.1.2 with ament_flake8's settings and plugins, and mypy 1.10.1 with --python-version 3.8 --disallow-untyped-defs: no findings in the tool and its test.
  • The first version (de659f8) against this head: both ran on a generated bag of 8,990 messages like a 180 s recording and on two IMU topics of six recorded bags of the EKF's stepped-clock test. 12 of the 13 reports have the same numbers in every line. On the generated bag, the first version prints the shortest interval of 14,049,979 ns as 14.1 ms, this head as 14.0 ms: the first version subtracted stamps as floating-point seconds.
  • Inputs that the first version got wrong, through the installed command:
    • A gyroscope marked as not measured: the first version printed a bias and a noise of zero. This head prints "0 readings".
    • Stamps 0, 20, 20, 10 and 80 ms: the first version printed 50.00 Hz. This head prints no rate, one repeated and one earlier stamp.
    • Stamps 0, 40, 20, 60 and 80 ms with a recorder's clock that goes back together with them: the first version printed 50.00 Hz and no interval over 30 ms. This head prints no rate and one earlier stamp.
    • Two frames with gravity on +z and −z: the first version printed a gravity of 3.270 m/s². This head refuses the bag, also when the frame_ids are empty.
    • A NaN reading, a std_msgs/String topic, messages named sensor_msgs/Imu with other fields than ROS's or with a checksum that doesn't fit their definition, a missing file, a text file, a gzip-packed bag, a recording without its index, a bag with a damaged chunk and a message that lacks its last byte: the first version printed NaN statistics or a traceback. This head prints one line and ends with status 1.
    • The readings 7 · 10⁻³⁰⁴, 0 and 0: the first version ended with Python 3.8's AssertionError "negative sum of square deviations". This head prints a variance of 0.
    • A camera topic in a bag of 211 MiB: this head refuses the topic with a peak memory of 45 MiB.
    • Every byte of an uncompressed, a BZ2 and an LZ4 bag of three messages inverted in turn, at 13f77a7: each of the 28,489 files gives a report or one line, never a traceback.
    • A line break in a stored checksum, in a frame_id and in the topic's name: the line break is shown as \n, and the line stays one line.
  • The recording command of the documentation, at 13f77a7: rosbag record -o imu_still --duration=3 /diffbot/imu/data_raw twice against a 50 Hz publisher writes two files with the date and time in their names, and the tool reads the first: 137 messages at 50.00 Hz. A third run with the capital -O and no publisher replaces a recording of 61 kB with an empty bag, which the tool refuses with "0 messages".
  • Firmware: .docker/firmware/run.sh pio run -e teensy31, pio run -e teensy40 and pio test -e native (93 tests) pass with the changed comment in diffbot_base_config.h, at 3ae3b50. After that, the firmware's files changed only in lib/imu/README.md.

Documentation

ros-mobile-robots/ros-mobile-robots.github.io#83 adds the section "Bias and noise at rest" to the IMU page and the page "Tests: IMU Bias and Noise at Rest", which walks through the tool's tests. The IMU library's README links that section for the tool's results. The link works once #83 is merged, which follows this pull request.

Part of #160.

imu_noise_at_rest.py reads the sensor_msgs/Imu messages of a rosbag recorded with the robot at rest. For each axis of the angular velocity and the acceleration, it prints the mean, the sample variance, the standard deviation and the number of distinct values. At rest, the angular velocity's mean estimates the bias that remains in the published readings, and the acceleration's mean is gravity plus the accelerometer's remaining error. It also prints the rate and the gaps between the stamps, and the length of the mean acceleration, gravity as the IMU measures it.

The bench checks on Remo (#169) measured the IMU's bias and noise with an ad-hoc script. This tool makes the measurement reproducible. The variances at rest are a baseline for the EKF's IMU variances, to be checked while driving too. A unit test checks the statistics on readings with known results, without a bag. On the two recordings at rest from the bench checks, with the Teensy 3.2 and the Teensy 4.0, the tool prints the same numbers as the ad-hoc script.
fjp added 18 commits November 18, 2026 13:40
format_report() builds the report, and main() prints it. A test reads
the whole report for a small set of statistics: the stamps' lines, a
table for the angular velocity, one for the acceleration, and gravity.
The printed text is the same.
IMU_PERIOD names the firmware's 20 ms, and LONG_GAP is one and a half
periods of it. Its value is 0.030 s as before.
The variance test expects a variance of zero, and the gap test counts
the gaps longer than LONG_GAP, whatever its value is.
The tool takes a field's readings only from the messages that measured
the field. sensor_msgs/Imu marks a field without a measurement with -1
as the first element of the field's covariance. A field with fewer than
two readings gets the reason instead of a bias and a noise of zero, and
each table shows its field's reading count.

The header stamps are integers in nanoseconds, so the intervals between
them and their comparison with 30 ms are exact. The report calls them
header intervals: they show how regularly the samples were taken, not
when the messages arrived. Repeated and earlier stamps are counted, and
a recording with one of them has no rate. A duration below one second is
printed in milliseconds.

The tool ends with one line and status 1 for a file that can't be opened
or isn't a rosbag, for messages of another type, for more than one
frame_id and for a reading that isn't finite.

The count of distinct values is described as the output levels that the
recording took, not as the sensor's resolution. Each test has a
docstring, and new tests run the tool as a command on small bags that
they write.
Bench check 3 in lib/imu/README.md and the comment on the variances in
diffbot_base_config.h name imu_noise_at_rest.py and say what its two
results are. The variances at rest are a baseline for the settings. The
mean angular velocity is the remaining bias in rad/s, which is no
variance. Before a setting changes, a recording while driving has to
tell the vibration apart from the robot's real motion.
The tool reads the header stamps in the order in which the bag stored
the messages. rosbag's reader sorts by the recorder's time, so a clock
that was set back for the recorder and the IMU alike looked like stamps
that advance, with a steady rate.

The topic's message types are checked before a message is read, and
each message is converted when it is read. A camera topic chosen by
mistake no longer loads its images.

Messages with an empty frame_id are refused: nothing says that their
readings share axes. A file whose first line isn't text, such as a bag
packed with gzip, gives one line instead of a traceback. When no field
has two readings, the message gives each field's count. The text about
long header intervals names possible reasons instead of one cause, and
--help says that the 30 ms belong to the firmware's 50 Hz.
The command for the noise tool in lib/imu/README.md ended in a
placeholder in angle brackets, which a shell reads as a redirection.
It shows an example of the name that the recorder prints.
A bag whose index is intact opens, also when the data of its messages
is damaged. Reading then failed with a traceback. The error of rosbag
or of the chunk's decompression is now the reason of the one line that
the tool prints, with the bag and the topic.

For a topic with messages of another type, the line names all the
topic's types, because rosbag info shows only one type for a topic with
several. The text about long header intervals gives a regular 10 Hz
topic as the example of a source whose intervals are all long.
rosbag's parser and a message's deserialization fail on damaged data
with their own errors and with others, such as a KeyError. Each of
them is now the reason of the one line that the tool prints. The file's
first bytes are checked before rosbag opens the file, and a recording
that was cut off gets a hint to rosbag reindex.

A reading beyond 1e6 rad/s or m/s^2 is refused: no IMU measures it, and
its square left a float's range. The sample variance has its own
function, because Python 3.8's statistics.variance() stops on
deviations whose squares are zero as floats.

With every byte of an uncompressed, a BZ2 and an LZ4 bag of three
messages inverted in turn, the tool prints a report or one line for
each of the 28,489 files.
The sample variance comes from statistics.variance() with the readings
as fractions. A mean that is rounded to a float can double the variance
of two neighbouring floats, and Python 3.8 stops on deviations whose
squares are zero as floats. Fractions hold every float exactly.

Before a message is read, the tool compares the checksum of the topic's
message definition with that of ROS's sensor_msgs/Imu. Messages that
carry the type's name with another definition can lack the fields that
the tool reads. An error of rosbag's reader while the tool asks for the
topic's types is the reason of the tool's one line.

The line about a reading beyond the tool's limit has the field's unit.
A bag stores the definition of each message type, and rosbag builds the
messages' class from it. The checksum of a definition doesn't tell
whether the class has the fields that the tool reads: an array of one
vector has the checksum of the vector. Before a message is read, the
tool builds the class from the bag's definition and compares its
fields, and the fields of its fields, with ROS's sensor_msgs/Imu. A
definition that differs in its comments passes.

The limit for a reading's size is described as the tool's limit for a
plausible reading of a robot at rest.
A bag stores a checksum and a definition text for a topic's message
type. rosbag reads the messages as the text says. When the text isn't
the definition with which the messages were written, one field's bytes
are read as another field. The tool builds the class from the text and
refuses a topic whose stored checksum isn't the class's.

The reason for a field of a field names the field's path without a
stray period.
A checksum or a frame_id that a bag stores can hold a line break. In
the tool's one line about an input that it refuses, and in the first
line of the report, a line break is shown as a backslash and an n.
The report's first line shows a line break in the topic's name as a
backslash and an n, as it does for the frame_id.
The docstrings of the checksum check and of its test said that the
definition's text is the wrong one. The stored checksum and the stored
text disagree, and the bag doesn't say which of them belongs to the
messages.
The docstring says that the tool refuses the topic before it decodes a
message, instead of what rosbag would read. The test's docstring says
that rosbag would try to read the bytes.
fjp added 6 commits November 21, 2026 22:46
The README said that the bench checks were still open and still needed, and
its table called the covariances not measured yet. The checks ran on Remo
with a Teensy 3.2 and with Remo's own Teensy 4.0 (diffbot#169). The first
section now says so and links the results, and the paragraph on the unit
tests says what the bench checks test. The table's covariance cell points
to the comment that explains the starting values, and says that they are
larger than the noise at rest measured on Remo. The first sentence names
what is published instead of "it".
noetic-devel brings GoogleTest for the firmware (#217) and the IMU tests (#221). The IMU library's README keeps the new test command with both environments and this branch's sentence on the bench checks.
… edges

The variance takes the values as fractions because Python 3.8 stops with
"negative sum of square deviations" on deviations whose squares are zero
as floats. The docstring no longer gives the neighbouring floats as the
reason: their variance is exact with floats too.

A new test checks one repeated stamp among stamps that advance: no rate
and one repeat. The tests' helper returns what the tool did as a
ToolRun, and assert_tool_printed_a_report() checks it.

The report reads 999.96 ms as "1.0 s", and gives the longest interval
with ns when one decimal would read as the 30 ms limit while the count
calls it longer. The IMU library's bench check links the IMU page's
section instead of explaining the results itself.
format_report() gives the longest interval of 30.04 ms as "30.040000 ms" next to "1 longer than 30 ms". With format_duration() in format_stamps() instead of format_longest_interval(), this test fails.
The report test for the longest interval just above LONG_INTERVAL writes its 40 µs as 40 * MILLISECOND // 1000, as the tests of format_longest_interval() do.
@fjp
fjp merged commit 22d4d28 into noetic-devel Nov 24, 2026
13 checks passed
@fjp
fjp deleted the feat/imu-noise-at-rest branch November 24, 2026 06:49
@github-project-automation github-project-automation Bot moved this from In review to Done in DiffBot & Remo roadmap Nov 24, 2026
fjp added a commit to ros-mobile-robots/ros-mobile-robots.github.io that referenced this pull request Nov 26, 2026
## What and why

**Before:** The BNO055 bench checks suggested measuring the stationary gyroscope's bias and variance but gave only the recording command.

**With this PR:** [Bias and noise at rest](https://ros-mobile-robots.com/packages/imu/driver-bno055/#bias-and-noise-at-rest) shows how to make a recording, read the report and compare Remo's measured yaw-rate variance with the firmware setting that reaches the EKF. The [tests walkthrough](https://ros-mobile-robots.com/packages/imu/noise-at-rest-tests/) traces accepted and refused inputs through the command and explains the checks against known readings.

**Limits:**

- The report that the page shows is the tool's output for a bag of three messages, which the tool's test `test_tool_prints_the_report_of_three_readings_one_output_step_apart` writes and compares line by line. The two Remo recordings weren't run through the tool again. Remo's numbers are those of the tool's first version.
- The trace figure shows a made-up gyroscope whose bias is about 30 times Remo's. Remo's bias of +0.00005 rad/s would lie on the zero line at the figure's scale.
- The commands of the tab "Robot container" and the `sftp` copy weren't run on a robot. The page says so. The recording command and the tool ran in the dev container's image against a 50 Hz publisher.
- The tests page has seven figures for 82 tests, not one per test. The checks of the input, the report's text and the refused inputs have no figure of their own. The flow figure in "The test classes" shows where on the tool's path their tests check.
- Some text in code font stays without a link: the report's labels and lines, the tool's reasons, commands and their options, example names, folders on the reader's computers, values and symbols inside display formulas.

**Merge order:** ros-mobile-robots/diffbot#178 is merged as `22d4d28`, and the pin names that commit. This pull request and #89 can be squash-merged in either order. The second one points the measured-noise link on From Measurement to Message to `#bias-and-noise-at-rest`.

## How it was checked

At `3064a25c`, the head, with the excerpts from GitHub at `22d4d28`, the merge commit of ros-mobile-robots/diffbot#178:

- **Build and spelling:** `mkdocs build --strict`, `codespell` and the repository's 161 tests pass in Python 3.12. flake8 with the repository's settings and mypy (`--disallow-untyped-defs`) report nothing for the figure script and its test. A test checks that the trace legend's mean label stands next to the solid mean line, and it fails when the label gets the output step's mark.
- **Figure tests:** six tests of the figure script were run on broken copies of what they check: drawings outside their wrapper or in a second figure, the stamp figures without their marks, marks with wrong numbers or without numbers, the mean line dashed or at the mean plus s, a signed value with a hyphen, one decimal more, no plus sign or the decimals ignored, both spread lines above the mean, and an extra test count on the page. Each test fails on its broken copies and passes on the head.
- **Excerpts:** each of the ten excerpts starts and ends at a whole function, test or block at `22d4d28`, and its code block's first line number is the excerpt's first line.
- **Line links:** a script fetched the pinned file of every GitHub line link and excerpt on the changed lines. No range leaves its file, and every link text that names lines names the linked ones.
- **The figures:** the script writes the eight includes byte for byte as they are in the repository, and each starts with the comment that names the script.
- **Numbers:** Remo's numbers against the reports of the two recordings. The three-message report against the tool's test at the pin, which passes there. The worked example by hand: Δ = 1/900 rad/s gives 0.00111 rad/s and 1.235 · 10⁻⁶ (rad/s)². Gravity: the root of 0.0536 + 0.0053 + 95.8181 is 9.792.
- **Rendering,** in Chrome from a local build, light and dark, 390 and 1440 px wide: the IMU page, the tests page and the Localization page have no horizontal page overflow and no formula error, and their Mermaid diagrams are drawn. The flow figure has no text outside its drawing, no overlapping text and no text that leaves its card. The trace, flow and two stamp figures show their wide layout at 1440 px and their narrow layout at 390 px, with no text outside a drawing, over other text or outside its card. The three figures with numbered stamps and steps, light and dark, 390 and 1440 px: every number lies inside its disc. The rendering was checked at `2fc20e4b`. All 12 SVG drawings at this head are byte for byte identical to those at `2fc20e4b`. The flow, measured-field and backward-stamp captions have different wording.
- **Preview:** the deployed preview serves this head, and the description's preview links open their page and section.
- No changed line joins sentences with a semicolon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant