Skip to content

Added covariance calculation to rs-imu-calibration.py - #14512

Merged
remibettan merged 5 commits into
realsenseai:developmentfrom
mbloechli:feature/covariance
Sep 1, 2026
Merged

remibettan merged 5 commits into
realsenseai:developmentfrom
mbloechli:feature/covariance

Conversation

@mbloechli

Copy link
Copy Markdown
Contributor

This pull requests adds calculation of the diagonal covariance matrix for linear acceleration and angular velocity to rs-imu-calibration.py

Closes #14511

@sysrsbuild-gh

Copy link
Copy Markdown

Can one of the admins verify this patch?

@Nir-Az
Nir-Az requested a review from alexkunin-gh June 30, 2026 09:40
…tion.json

Addresses review feedback on PR realsenseai#14512:
- Initialize gyro=None so file mode without --gyro_file no longer NameErrors
  in the newly-added covariance block.
- Guard against empty accel buckets and missing/malformed gyro so partial
  captures print a skip message instead of crashing on IndexError.
- Average accel variance across all populated buckets instead of using
  bucket 0 only; the noise floor should be pose-independent, and this is
  less sensitive to a single shaky pose.
- Document the still-window preconditions used by each mode (file: first
  ~4 s already trimmed for gyro-bias; interactive: last bucket's
  stability window returned by imu_wrapper.get_measurements) so a reader
  knows what the numbers actually represent.
- Rename the print label from "Covariance (diagonal values)" to "Variance
  (per-axis, ...)" for consistency with the accel_var / gyro_var variable
  names; formatting is explicit scientific + decimal.
- Serialize the noise variances into calibration.json under
  imus[0]["accelerometer"]["noise_variances"] and ["gyroscope"]
  ["noise_variances"] so downstream tooling can consume them without
  scraping stdout.

Tracked by: RSDSO-21809
Addresses rs-agentic bot feedback on PR realsenseai#14512:

The gyro guard previously accepted any 2-D non-empty `gyro`. If a file-mode
CSV had a different column count (e.g. no timestamp column, or extra
columns), `gyro[:, 1:]` would silently produce a wrong-width variance
vector - either crashing the three-element format string with IndexError,
or worse, printing values from the wrong axes.

The expected shape is (N, 4) with columns [timestamp, x, y, z]:
  - file mode: np.loadtxt on the gyro CSV (existing convention)
  - interactive mode: imu_wrapper appends timestamp + xyz per sample
    (see imu_callback L132)

Now the guard requires `shape[1] == 4` and falls through to an explicit
"unexpected gyro shape ... expected (N, 4) with columns [timestamp, x,
y, z]" message when the assumption is violated, distinct from the
"no gyro samples available" path.

Tracked by: RSDSO-21809
… call

Self-review polish, no behavior change:
- Drop redundant np.stack around np.mean(per_bucket_var, axis=0); a list
  of shape-(3,) arrays already averages correctly.
- Replace a magic line-number reference ("see imu_callback L132") with
  the symbolic form "imu_wrapper.imu_callback" so the comment doesn't
  rot when the file changes.
- Drop PX4 from the sensor-fusion example list; PX4 doesn't typically
  consume rs-imu-calibration output, and the remaining examples cover
  the intended audience.

Tracked by: RSDSO-21809
@remibettan
remibettan self-requested a review August 31, 2026 10:33
@remibettan

Copy link
Copy Markdown
Contributor

ok to test

@remibettan
remibettan merged commit 3623ec0 into realsenseai:development Sep 1, 2026
34 of 35 checks passed
alexkunin-gh pushed a commit to alexkunin-gh/librealsense that referenced this pull request Sep 2, 2026
…tion.json

Addresses review feedback on PR realsenseai#14512:
- Initialize gyro=None so file mode without --gyro_file no longer NameErrors
  in the newly-added covariance block.
- Guard against empty accel buckets and missing/malformed gyro so partial
  captures print a skip message instead of crashing on IndexError.
- Average accel variance across all populated buckets instead of using
  bucket 0 only; the noise floor should be pose-independent, and this is
  less sensitive to a single shaky pose.
- Document the still-window preconditions used by each mode (file: first
  ~4 s already trimmed for gyro-bias; interactive: last bucket's
  stability window returned by imu_wrapper.get_measurements) so a reader
  knows what the numbers actually represent.
- Rename the print label from "Covariance (diagonal values)" to "Variance
  (per-axis, ...)" for consistency with the accel_var / gyro_var variable
  names; formatting is explicit scientific + decimal.
- Serialize the noise variances into calibration.json under
  imus[0]["accelerometer"]["noise_variances"] and ["gyroscope"]
  ["noise_variances"] so downstream tooling can consume them without
  scraping stdout.

Tracked by: RSDSO-21809
alexkunin-gh pushed a commit to alexkunin-gh/librealsense that referenced this pull request Sep 2, 2026
Addresses rs-agentic bot feedback on PR realsenseai#14512:

The gyro guard previously accepted any 2-D non-empty `gyro`. If a file-mode
CSV had a different column count (e.g. no timestamp column, or extra
columns), `gyro[:, 1:]` would silently produce a wrong-width variance
vector - either crashing the three-element format string with IndexError,
or worse, printing values from the wrong axes.

The expected shape is (N, 4) with columns [timestamp, x, y, z]:
  - file mode: np.loadtxt on the gyro CSV (existing convention)
  - interactive mode: imu_wrapper appends timestamp + xyz per sample
    (see imu_callback L132)

Now the guard requires `shape[1] == 4` and falls through to an explicit
"unexpected gyro shape ... expected (N, 4) with columns [timestamp, x,
y, z]" message when the assumption is violated, distinct from the
"no gyro samples available" path.

Tracked by: RSDSO-21809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants