Skip to content

Tests: IMU Bias and Noise at Rest

This page walks through the 82 tests of the tool imu_noise_at_rest.py. The tool reads a recording of the IMU's messages and prints a report with the gyroscope's remaining bias and the noise of each axis. The recording is a rosbag file, a bag for short, with the messages of the topic /diffbot/imu/data_raw from a time in which the robot stands still: 50 messages per second, each with a time stamp, the angular velocity and the acceleration. Bias and noise at rest on the BNO055 page explains how to make the recording, how to run the tool and what its report means.

The noise in the report is a baseline for the variances in the IMU's messages, which tell the EKF how much to trust each reading, as From the report to the EKF shows. A report with a wrong number looks just like a report with the right number, so a reader of the report can't see a mistake of the tool. The tests have to find such a mistake. They check two things: that the report's numbers are right, and that the tool prints one line with the reason, and no report, for a recording that it can't evaluate.

The tests are in test_imu_noise_at_rest.py. The first 59 call the tool's functions directly with prepared inputs and check a value, a line of text or the outcome of an input check. The last 23 run the whole tool as a command, most of them on a small bag that the test writes into a temporary folder, and compare what the tool prints. No test needs a robot or a ROS master. The tool's three steps says what the tool does, and The test classes shows which tests check which step. The sections after these two follow the three steps.

A pass shows that the tool's arithmetic, its checks of the input and the text of its report are right for the tests' made-up messages. What the tests don't show lists what a pass doesn't prove, such as the bias and the noise of a real IMU.

Run the tests

The tests run in the dev container, in the catkin workspace:

1
2
3
cd ~/catkin_ws
catkin run_tests diffbot_bringup
catkin_test_results build/diffbot_bringup

The last command prints the result:

1
Summary: 82 tests, 0 errors, 0 failures, 0 skipped

catkin finds the tests through the package's CMakeLists.txt, which registers the file for nose, a runner for Python's unittest tests. The excerpt shows the registration, lines 217–221 of CMakeLists.txt:

diffbot_bringup/CMakeLists.txt: the test file is registered for nose
217
218
219
220
221
if(CATKIN_ENABLE_TESTING)
  # scripts/imu_noise_at_rest.py: its statistics on readings with known results, and the tool
  # as a command on small bags that the test writes
  catkin_add_nosetests(test/test_imu_noise_at_rest.py)
endif()

CI runs the same tests with every pull request.

The tool's three steps

The tool works in three steps, and main() calls one function for each:

  1. Read and check: read_samples() opens the bag and checks that the IMU's topic holds sensor_msgs/Imu messages as ROS defines them. From each message, the function keeps the header stamp, the frame, the angular velocity and the acceleration, and leaves out a reading that the message marks as not measured. Then the function checks the number of messages, their frame and their readings. When a check fails, the tool prints one line with the reason and ends with status 1.
  2. Calculate: imu_statistics() calculates the mean and the variance of the readings for each axis of the angular velocity and of the acceleration, and counts their distinct values. The standard deviation is the root of the variance. The function also calculates the length of the mean acceleration, which is gravity as the IMU measures it, and the duration, the rate and the intervals of the header stamps.
  3. Print: format_report() writes these numbers into the report's lines, with a table for the angular velocity and a table for the acceleration, and main() prints them.

The test classes

The file holds the tests in fourteen test classes. The figure puts them onto the tool's path. Each step's card names the classes whose tests call that step's functions. The bracket marks the 23 tests that start the tool as a command. Trace the path from the bag file's card. In seven of these tests, the tool passes the three steps, prints the report on standard output (stdout) and ends with status 0. In the other sixteen, the tool leaves the first step along the dashed arrow. These tests check for one line on standard error (stderr) and status 1.

The tool's three steps from a bag file to the report, each with its test classes: Read and check with read_samples(), Calculate with imu_statistics() and Print with format_report(). A failed check leaves the first step to one line on stderr and status 1. TestToolOnBags runs the tool as a command a bag file 1 Read and check read_samples() TestMeasuredVector TestToSample TestTopicChecks TestSampleChecks a check fails ✕ one line on stderr status 1 samples 2 Calculate imu_statistics() TestAxisStatistics TestVectorStatistics TestFieldStatistics TestStampStatistics TestImuStatistics statistics 3 Print format_report() TestFormatDuration TestFormatLongestInterval TestFormatTable TestFormatReport ✓ the report on stdout status 0 TestToolOnBags runs the tool as a command The tool's three steps from a bag file to the report, each with its test classes: Read and check with read_samples(), Calculate with imu_statistics() and Print with format_report(). A failed check leaves the first step to one line on stderr and status 1. TestToolOnBags runs the tool as a command a bag file 1 Read and check read_samples() TestMeasuredVector TestToSample TestTopicChecks TestSampleChecks samples 2 Calculate imu_statistics() TestAxisStatistics TestVectorStatistics TestFieldStatistics TestStampStatistics TestImuStatistics statistics 3 Print format_report() TestFormatDuration TestFormatLongestInterval TestFormatTable TestFormatReport a check fails ✕ one line on stderr status 1 ✓ the report on stdout status 0 TestToolOnBags runs the tool as a command
The test classes in a step's card call that step's functions: 22 tests at Read and check, 26 tests at Calculate and 11 tests at Print. TestToolOnBags runs the tool as a command, most of its tests on a small bag that the test writes. 7 of its tests check the report and status 0, and 16 check the one line and status 1.

The list has the classes in the same order, with the functions that they call. Its first two entries belong to the step Read and check, the next three to Calculate, and the sixth to Print. The last entry is the class of the command tests:

  • TestMeasuredVector and TestToSample, 2 + 2 tests: they call measured_vector() and to_sample(). They check which fields of a message count as measured, and that the header stamp keeps every nanosecond.
  • TestTopicChecks and TestSampleChecks, 8 + 10 tests: they call check_topic(), the six checks of the samples and check_samples(). They check which messages the tool refuses, and the reason that it gives.
  • TestAxisStatistics, TestVectorStatistics and TestFieldStatistics, 8 + 1 + 2 tests: they call axis_statistics(), vector_statistics() and field_statistics(). They check the mean, the sample variance, the standard deviation and the distinct values of one axis, that each axis has its own statistics, and that a field needs two readings.
  • TestStampStatistics, 10 tests: they call stamp_statistics(). They check the duration, the rate and the intervals of the header stamps, and the stamps that don't advance.
  • TestImuStatistics, 5 tests: they call imu_statistics(). They check that each statistic comes from the right field, and gravity.
  • TestFormatDuration, TestFormatLongestInterval, TestFormatTable and TestFormatReport, 3 + 2 + 1 + 5 tests: they call format_duration(), format_longest_interval(), format_table() and format_report(). They check the text of the report, line by line.
  • TestToolOnBags, 23 tests: they run the script as a command. They check the report and status 0 for a good bag, and one line and status 1 for an input that the tool refuses.

Every test method has a name that says what it checks and a first docstring line that says the same as a sentence, for example test_stamp_statistics_counts_no_long_interval_at_exactly_long_interval with "Check that an interval of exactly LONG_INTERVAL isn't long: only a longer one is."

Which readings count

A sensor_msgs/Imu message has a place for the angular velocity and one for the acceleration, also when the IMU measured only one of them. The message marks a field that it didn't measure with −1 as the first element of the field's covariance. The tool's function measured_vector() reads this mark. It gets a field's vector and the field's covariance, and returns the vector as a reading, or None for a field that wasn't measured. The excerpt shows the function, lines 376–384 of imu_noise_at_rest.py:

imu_noise_at_rest.py: a field's reading, or None
376
377
378
379
380
381
382
383
384
def measured_vector(vector: Any, covariance: Sequence[float]) -> Optional[Vector]:
    """Return a field's geometry_msgs/Vector3 as a Vector, or None for a field not measured.

    Only -1 as the covariance's first element marks a field as not measured. A covariance of
    zeros means that the covariance isn't known, and the field's reading counts.
    """
    if covariance[0] == NOT_MEASURED:
        return None
    return Vector(vector.x, vector.y, vector.z)

The figure shows three messages as the test test_imu_statistics_takes_a_field_only_from_the_samples_that_measured_it builds them. The second message has no angular velocity:

Three messages. The first and the third have a covariance that starts with 0 and yaw rates of 0.2 and 0.4 rad/s: two readings. The second has a covariance that starts with −1: no reading angular_velocity_covariance[0] message 1 0.0 angular_velocity.z ✓ a reading 0.2 rad/s message 2 −1.0 angular_velocity.z ✕ not measured not used message 3 0.0 angular_velocity.z ✓ a reading 0.4 rad/s
2 readings with the mean 0.3 rad/s. Counting the unmeasured message as a reading of zero would give 3 readings with the mean 0.2 rad/s.

The tests of this part:

The stamp is an integer for a reason. A stamp of today is about 1.7 · 10⁹ s. A floating-point number of that size has steps of about 240 ns, so two stamps in seconds as floats can't tell an interval of 30 ms from one of 30 ms and 1 ns. As integers in nanoseconds, the stamps and the intervals between them are exact.

The checks of the input

Before the tool calculates anything, it checks its input. Each check is one function that raises a MessageError with the reason.

The first check, check_topic(), runs before the tool reads a message. A bag stores three things about the message type of each of a topic's connections: the type's name, the text of the type's definition, and a checksum of the definition that the recorder got from the publisher. The check asks the bag for all three and refuses three kinds of topics:

  • Another type: a topic whose type isn't named sensor_msgs/Imu. A camera's topic chosen by mistake is refused without loading its images.
  • A checksum that doesn't fit: rosbag builds a message's class from the definition's text in the bag. The check builds the class in the same way. If the class's checksum isn't the stored one, the stored checksum and the stored definition disagree, and the bag doesn't say which of the two belongs to the messages. rosbag would try to decode the messages' bytes as the fields of the stored definition, whether the definition is theirs or not. So the tool refuses the topic before it reads a message.
  • Other fields: messages that are named sensor_msgs/Imu, but whose class has other fields than ROS's. The check compares the class's fields, and the fields of its fields, with those of ROS's sensor_msgs/Imu.

TestTopicChecks gives the check stand-ins for a bag, which only know a topic's connections:

The other six checks look at the samples, and check_samples() runs them in the order of the list SAMPLE_CHECKS. The excerpt shows the list and the function, lines 544–559 of imu_noise_at_rest.py:

imu_noise_at_rest.py: the checks of the samples and their runner
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
SampleCheck = Callable[[Sequence[ImuSample]], None]
# In this order: the later checks and the statistics rely on the earlier ones
SAMPLE_CHECKS: Tuple[SampleCheck, ...] = (
    check_message_count,
    check_named_frame,
    check_one_frame,
    check_finite_readings,
    check_reading_size,
    check_reading_count,
)


def check_samples(samples: Sequence[ImuSample]) -> None:
    """Raise the MessageError of the first check in SAMPLE_CHECKS that the samples fail."""
    for check in SAMPLE_CHECKS:
        check(samples)

TestSampleChecks gives each check samples that it has to refuse, and compares the reason's text:

Check What goes in The reason that is checked
check_message_count() One sample 1 message, the statistics need at least two
check_named_frame() Two samples with an empty frame_id 2 of 2 messages have an empty frame_id. The readings need one named frame, which says what their axes are
check_one_frame() A sample in other_imu and one in imu_link the messages have more than one frame_id ("imu_link", "other_imu"), so their readings have different axes
check_finite_readings() A sample whose yaw rate is NaN, stamped 20 ms after EPOCH the message stamped 1700000000.020000000 has the angular_velocity (0.0, 0.0, nan), which isn't finite
check_finite_readings() A sample whose x acceleration is infinite A MessageError
check_finite_readings() A sample without the angular velocity Nothing is raised: a field that wasn't measured isn't looked at
check_reading_size() A sample whose z acceleration is 2,000,000 m/s², twice LARGEST_READING the message stamped 1700000000.000000000 has the linear_acceleration (0.0, 0.0, 2000000.0). The tool takes a value beyond 1e+06 m/s^2 as damaged data
check_reading_size() A sample whose x rate is −1,000,000 rad/s, exactly LARGEST_READING Nothing is raised
check_reading_count() One sample without the angular velocity and one without the acceleration angular_velocity has 1 reading and linear_acceleration has 1 reading. At least one of them needs two
check_samples() Two samples at rest in imu_link Nothing is raised

The frame matters because it says which way the axes x, y and z point. Readings in two frames, or in a frame without a name, don't belong on one axis. The mean of +9.81 and −9.81 m/s² would be a gravity of zero.

LARGEST_READING is 1,000,000, in rad/s or m/s². It is the tool's own limit for a plausible reading of a robot at rest. The tool takes a value beyond it as damaged data, for example one changed byte in a number. One such value alone would decide the mean and the variance of its axis.

The statistics of one axis

axis_statistics() gets the readings of one axis and returns their mean, their sample variance and the number of distinct values. It takes the variance from sample_variance(), which calculates with fractions instead of floating-point numbers. The mean and the variance of three readings on the BNO055 page explains the formulas. The test of the sample variance uses the four values 1, 2, 3 and 4:

The four values 1, 2, 3 and 4 on an axis. Their mean is 2.5. Their deviations from the mean are −1.5, −0.5, +0.5 and +1.5 mean 2.5 −1.5 1 2.25 −0.5 2 0.25 +0.5 3 0.25 +1.5 4 2.25 the deviations, squared
The squared deviations add up to 5. The sample variance is 5 / (4 − 1) = 1.6667. Dividing by 4 would give 1.25.

The excerpt shows this test, lines 147–154 of test_imu_noise_at_rest.py. assertAlmostEqual() compares the two numbers to seven decimal places:

test_imu_noise_at_rest.py: the sample variance divides by the number of values minus one
147
148
149
150
151
152
153
154
def test_axis_statistics_gives_the_sample_variance(self) -> None:
    """Check that the squared deviations are divided by the number of values minus one.

    The squared deviations of 1, 2, 3 and 4 from their mean 2.5 add up to 5. The sample
    variance is 5 / (4 - 1), not 5 / 4.
    """
    variance = axis_statistics([1.0, 2.0, 3.0, 4.0]).variance
    self.assertAlmostEqual(variance, 5.0 / 3.0)

The other tests of the statistics:

The header stamps

stamp_statistics() gets the header stamps in the order in which the bag stored the messages, as integers in nanoseconds. It returns the time from the first stamp to the last, the rate, the shortest and the longest interval between two consecutive stamps, and three counts: the intervals longer than LONG_INTERVAL, the stamps that repeat the stamp before, and the stamps that are earlier than the stamp before. The excerpt shows the function together with mean_rate(), lines 612–640 of imu_noise_at_rest.py:

imu_noise_at_rest.py: the rate and the statistics of the header stamps
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
def mean_rate(intervals: Sequence[int]) -> Optional[float]:
    """Return the number of intervals per second in Hz, or None when a stamp doesn't advance.

    n messages in a row span n - 1 intervals, so the rate counts the intervals, not the messages.
    The intervals add up to the time from the first stamp to the last. With a repeated or an
    earlier stamp, that time isn't the time the messages span, so they have no rate.
    """
    if min(intervals) <= 0:
        return None
    return len(intervals) * NANOSECONDS_PER_SECOND / sum(intervals)


def stamp_statistics(stamps: Sequence[int]) -> StampStatistics:
    """Return the number of header stamps, their duration, their rate and their intervals.

    The stamps are integers in ns, so the intervals are exact, and so is their comparison with
    LONG_INTERVAL. Seconds as floats can't tell 30 ms from 30 ms and 1 ns at a stamp of today's
    size. It needs at least two stamps.
    """
    intervals = [later - earlier for earlier, later in zip(stamps, stamps[1:])]
    return StampStatistics(
        message_count=len(stamps),
        duration=stamps[-1] - stamps[0],
        rate=mean_rate(intervals),
        shortest_interval=min(intervals),
        longest_interval=max(intervals),
        long_interval_count=sum(interval > LONG_INTERVAL for interval in intervals),
        repeated_stamp_count=sum(interval == 0 for interval in intervals),
        earlier_stamp_count=sum(interval < 0 for interval in intervals))

Stamps that advance

The first two tests use five stamps that advance, with one long interval:

Five header stamps on a time axis, at 0, 20, 40, 75 and 95 ms. Three intervals are 20 ms long. The interval from 40 to 75 ms is 35 ms long, more than 30 ms 20 ms 20 ms 35 ms 20 ms 1 0 2 20 3 40 4 75 5 95 ms Five header stamps on a time axis, at 0, 20, 40, 75 and 95 ms. Three intervals are 20 ms long. The interval from 40 to 75 ms is 35 ms long, more than 30 ms 20 ms 20 ms 35 ms 20 ms 1 0 2 20 3 40 4 75 5 95 ms
STAMPS_WITH_ONE_LONG_INTERVAL: 5 header stamps, 4 intervals in 95 ms. The rate is 4 / 0.095 s = 42.1 Hz. One interval is longer than LONG_INTERVAL, 30 ms.

The limit of a long interval

LONG_INTERVAL is 30 ms: one and a half periods of the 20 ms at which the firmware takes its samples. Three tests put two stamps around this limit, at the size of a real stamp:

Stamps that don't advance

A clock that is set back during a recording gives stamps that go back. The fixture has one repeated stamp and one earlier stamp:

Five messages in the order of the recording, each at its header stamp. The third message repeats the stamp of the second, 20 ms. The fourth is stamped 10 ms, earlier than the third. The fifth is stamped 80 ms message, in the order of the recording repeated 10 ms earlier 1 2 3 4 5 0 10 20 80 ms header stamp Five messages in the order of the recording, each at its header stamp. The third message repeats the stamp of the second, 20 ms. The fourth is stamped 10 ms, earlier than the third. The fifth is stamped 80 ms message, in the order of the recording repeated 10 ms earlier 1 2 3 4 5 0 10 20 80 ms header stamp
STAMPS_WITH_A_REPEAT_AND_A_STEP_BACK: the last stamp is 80 ms after the first, and 4 intervals in 80 ms would be 50 Hz. The dashed red lines mark stamps that don't advance, so the tool gives no rate.

The statistics of a recording

imu_statistics() puts the parts together: the stamps' statistics, the frame, the statistics of the two fields and gravity. Its tests check that each number comes from the right place:

The test of gravity uses a tilted IMU. The mean of its two accelerations is (2, 3, 6) m/s², and the length of that vector is a whole number:

The mean acceleration of a tilted IMU as an arrow from the origin to the point x = 2, y = 3, z = 6 m/s². The arrow is 7 m/s² long x y z mean acceleration (2, 3, 6) m/s² length 7 m/s² √(2² + 3² + 6²)
A tilted IMU measures gravity on all three axes. The length of the mean acceleration doesn't depend on the tilt.

The excerpt shows the test, lines 524–529 of test_imu_noise_at_rest.py. sample() is the test file's helper for a sample of a level robot at rest, and known() fails the test if gravity is None:

test_imu_noise_at_rest.py: gravity is the length of the mean acceleration
524
525
526
527
528
529
def test_imu_statistics_gives_gravity_as_the_length_of_the_mean_acceleration(
        self) -> None:
    """Check that a tilted IMU's mean acceleration (2, 3, 6) has the length 7."""
    samples = [sample(linear_acceleration=Vector(1.0, 3.0, 5.0)),
               sample(stamp=EPOCH + IMU_PERIOD, linear_acceleration=Vector(3.0, 3.0, 7.0))]
    self.assertAlmostEqual(known(imu_statistics(samples).gravity), 7.0)

The report's text

The functions whose names start with format_ turn the statistics into the report's lines. Their tests compare text:

  • TestFormatDuration: 179.78 s reads 179.8 s, and 40 ms reads 40.0 ms. A duration below one second is given in milliseconds, so that a short recording doesn't read 0.0 s. The unit follows the rounded value: 999.96 ms reads 1.0 s, not 1000.0 ms.
  • TestFormatLongestInterval: format_longest_interval() gives the longest interval. An interval 40 µs longer than LONG_INTERVAL reads 30.040000 ms, with ns, because one decimal would read 30.0 ms next to a count that calls it longer. An interval 1 ms longer reads like any duration, 31.0 ms.
  • TestFormatTable: each column of a table is as wide as its widest cell, with the first column aligned left and the others right.
  • TestFormatReport: one test compares all 18 lines of a report with both fields' statistics. One compares the stamps' lines of a recording with a repeated and an earlier stamp, which read "no rate (some stamps don't advance)". One compares the two lines that a field without statistics gets instead of its table, and checks that the report then has no line about gravity. One checks that a frame_id with a line break in it stays on the report's first line, with the line break shown as \n. One checks the intervals' line with a longest interval of 30.04 ms: longest 30.040000 ms, 1 longer than 30 ms.

The tool as a command

The 23 tests of TestToolOnBags run the script the way a user does. Each test prepares an input in a temporary folder: a bag, a file that isn't a bag, or no file at all. It starts the script as a new process and compares what the process prints.

write_bag() stores the messages in the order of its list, each with the time at which a recorder would have received it. The excerpt shows the function, lines 712–721 of test_imu_noise_at_rest.py:

test_imu_noise_at_rest.py: write the messages to a bag
712
713
714
715
716
717
718
719
720
721
def write_bag(bag_path: str, topic: str, messages: Sequence[Any],
              arrival_stamps: Sequence[int] = REGULAR_STAMPS,
              compression: str = rosbag.Compression.NONE) -> None:
    """Write the messages to a new bag in their order, as a recorder stores them.

    Each message gets the time at which the recorder got it, by the recorder's clock.
    """
    with rosbag.Bag(bag_path, 'w', compression=compression) as bag:
        for message, arrival_stamp in zip(messages, arrival_stamps):
            bag.write(topic, message, to_ros_time(arrival_stamp))

run_tool() starts the script and returns a ToolRun: the process's exit status and what it wrote to its standard output and its standard error. The class's helpers run the tool on the test's bag and check what it did. run_on_bag() runs it and returns the ToolRun. assert_tool_printed_a_report() expects status 0 with nothing on the standard error, and the test then reads the report's lines from run.stdout. assert_tool_ends_with() expects status 1, nothing on the standard output and exactly one given line on the standard error. assert_tool_ends_with_a_reason_after() expects the same, for a line of which the test fixes only the start. The excerpt shows ToolRun, run_tool(), the class's setUp() and the helpers, lines 761–807 of test_imu_noise_at_rest.py:

test_imu_noise_at_rest.py: run the tool and compare what it prints
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
class ToolRun(NamedTuple):
    """What the tool did as a command: its exit status, its stdout and its stderr."""

    status: int
    stdout: str
    stderr: str


def run_tool(arguments: Sequence[str]) -> ToolRun:
    """Run the tool as a command and return what it did."""
    result = subprocess.run([sys.executable, TOOL] + list(arguments), stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE, universal_newlines=True)
    return ToolRun(result.returncode, result.stdout, result.stderr)


class TestToolOnBags(unittest.TestCase):
    """The tool as a command: a report and status 0, or one line on stderr and status 1."""

    def setUp(self) -> None:
        """Make a temporary folder for the test's bag."""
        folder = tempfile.TemporaryDirectory()
        self.addCleanup(folder.cleanup)
        self.bag_path = os.path.join(folder.name, 'imu_still.bag')

    def run_on_bag(self, arguments: Sequence[str] = ()) -> ToolRun:
        """Run the tool on the test's bag and return what it did."""
        return run_tool([self.bag_path] + list(arguments))

    def assert_tool_printed_a_report(self, run: ToolRun) -> None:
        """Check that the tool ended with status 0 and printed nothing on stderr."""
        self.assertEqual((run.status, run.stderr), (0, ''))

    def assert_tool_ends_with(self, message: str, arguments: Sequence[str] = ()) -> None:
        """Check that the tool prints only the message, on stderr, and ends with status 1."""
        self.assertEqual(self.run_on_bag(arguments), ToolRun(1, '', message + '\n'))

    def assert_tool_ends_with_a_reason_after(self, line_start: str) -> None:
        """Check that the tool ends with status 1 and one line: the start, then a reason.

        For reasons whose words come from rosbag or from Python, so that the test doesn't
        depend on them. An empty reason or "None" fails.
        """
        run = self.run_on_bag()
        self.assertEqual((run.status, run.stdout), (1, ''))
        self.assertEqual(run.stderr.count('\n'), 1)
        self.assertTrue(run.stderr.startswith(line_start), run.stderr)
        self.assertNotIn(run.stderr[len(line_start):].strip(), ('', 'None'))

The whole report for three messages

test_tool_prints_the_report_of_three_readings_one_output_step_apart writes three messages 20 ms apart, in the frame imu_link, with gravity on z. Their yaw rates are 0, 1 and 2 output steps of 1/900 rad/s:

Three yaw-rate readings on an axis: zero, one output step and two output steps. Their mean is one step. The outer readings deviate from the mean by one step each mean −Δ +Δ 0 0.00000 Δ 0.00111 2Δ 0.00222 angular_velocity.z in rad/s
Three readings one output step Δ = 1/900 rad/s apart. Their mean is Δ. The arrows are the deviations from the mean: −Δ, 0 and +Δ.

The mean is one step, 0.00111 rad/s, and the sample variance one step squared, 1.235 · 10⁻⁶ (rad/s)². The test compares all 18 lines of the report, as the excerpt shows, lines 809–837 of test_imu_noise_at_rest.py:

test_imu_noise_at_rest.py: every line of the report for three readings
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
def test_tool_prints_the_report_of_three_readings_one_output_step_apart(self) -> None:
    """Check every line for yaw rates of 0, 1 and 2 steps: a variance of one step squared.

    One step is 1/900 rad/s, so the mean and the standard deviation read 0.00111 rad/s and
    the variance 1.235e-06 (rad/s)^2. The covariances of zeros don't hide the readings.
    """
    write_bag(self.bag_path, DEFAULT_TOPIC, messages_one_step_apart())
    run = self.run_on_bag()
    self.assert_tool_printed_a_report(run)
    self.assertEqual(run.stdout.splitlines(), [
        '/diffbot/imu/data_raw: 3 messages, frame_id "imu_link"',
        'Header stamps: 40.0 ms from the first to the last, 50.00 Hz',
        'Header intervals: shortest 20.0 ms, longest 20.0 ms, 0 longer than 30 ms',
        "Stamps that don't advance: 0 repeated, 0 earlier than the one before",
        '',
        'angular_velocity  mean (bias)     variance  std dev  distinct',
        '3 readings            [rad/s]  [(rad/s)^2]  [rad/s]    values',
        'x                    +0.00000    0.000e+00  0.00000         1',
        'y                    +0.00000    0.000e+00  0.00000         1',
        'z                    +0.00111    1.235e-06  0.00111         3',
        '',
        'linear_acceleration  mean (gravity + bias)     variance  std dev  distinct',
        '3 readings                         [m/s^2]  [(m/s^2)^2]  [m/s^2]    values',
        'x                                 +0.00000    0.000e+00  0.00000         1',
        'y                                 +0.00000    0.000e+00  0.00000         1',
        'z                                 +9.81000    0.000e+00  0.00000         1',
        '',
        'Gravity, the length of the mean acceleration: 9.810 m/s^2',
    ])

The messages show both meanings of a covariance. Their angular_velocity_covariance and linear_acceleration_covariance are all zeros, which means "not known", and the report has these fields' statistics. Their orientation_covariance starts with −1, as the firmware's does, which means that the messages have no orientation.

Reports for other bags

Each test varies the input and checks selected lines of the report:

The last two tests differ in the recorder's clock. rosbag's reader returns the messages sorted by the time at which the recorder received each one. If that clock is set back together with the IMU's stamps, for example because the robot's computer corrects its time, the sorted stamps advance again and the step back would be invisible. The tool restores the order in which the bag stored the messages, so the step back is visible in both tests.

Inputs that the tool refuses

For these inputs the tool prints one line and ends with status 1. The line starts with the file's name. For a problem with the messages, the topic follows. All tests but the last two of the list compare the whole line. The list gives the line's reason:

In the last two tests, the reason at the line's end comes from rosbag or from Python. These tests don't fix its words. They compare the line's start and check that a reason follows it, and that the line is the only one.

What the tests don't show

  • No real IMU: the tests' messages are made up. That the BNO055's readings on Remo have the bias and the noise of the results is a measurement, not a test.
  • No recorder: the tests write their bags with rosbag's Python interface. They don't run rosbag record, and they don't cover a recording that was cut off.
  • No long recording: the largest test bag has three messages. A recording of 180 s has about 9,000.
  • Nothing about driving: the tool describes a robot at rest. How much noise driving adds is a separate check.

Comments

Comments are GitHub Discussions, shown with giscus. Loading them connects to giscus.app (hosted by Vercel, USA) and GitHub (USA); you need a GitHub account to comment.