Skip to content

Nav2 AMCL: add random_seed param for deterministic replay; remove hidden time seeding in PF#5856

Merged
SteveMacenski merged 7 commits intoros-navigation:mainfrom
StanByriukov02:amcl-random-seed-replayability
Jan 13, 2026
Merged

Nav2 AMCL: add random_seed param for deterministic replay; remove hidden time seeding in PF#5856
SteveMacenski merged 7 commits intoros-navigation:mainfrom
StanByriukov02:amcl-random-seed-replayability

Conversation

@StanByriukov02
Copy link
Contributor

Today nav2_amcl seeds RNG internally from wall-clock time (srand48(time(NULL))) and uses drand48() during resampling / pose sampling. That makes AMCL runs non-replayable even with identical inputs.

This PR makes randomness explicit:

  • Adds random_seed parameter (default -1 keeps legacy behavior, >=0 enables deterministic replay).
  • Moves seeding to the node layer.
  • Adds pf_seed() API and removes hidden seeding from pf_alloc().

Owner-routing ask: who owns AMCL replayability / regression reproducibility for Nav2? If there’s an existing preferred pattern (e.g., use rclcpp random / parameter naming), I’ll align.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
nav2_amcl/src/amcl_node.cpp 86.63% <100.00%> (+0.07%) ⬆️
nav2_amcl/src/pf/pf.c 91.62% <ø> (-0.04%) ⬇️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
@StanByriukov02 StanByriukov02 force-pushed the amcl-random-seed-replayability branch from c6abf3c to 7508a89 Compare January 9, 2026 21:11
Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
// Deterministic replay knob:
// - set random_seed >= 0 to make AMCL replayable under dispute (same inputs -> same outputs),
// - keep default (-1) to preserve time-seeded behavior.
random_seed_ = this->declare_or_get_parameter("random_seed", -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this to the configuration guide page for AMCL at docs.nav2.org

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — added random_seed (default: -1) to nav2_bringup/params/nav2_params.yaml so it shows up in the canonical config surface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated on docs.nav2.org: https://docs.nav2.org/configuration/packages/configuring-amcl.html

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
// Deterministic replay knob:
// - set random_seed >= 0 to make AMCL replayable under dispute (same inputs -> same outputs),
// - keep default (-1) to preserve time-seeded behavior.
random_seed_ = this->declare_or_get_parameter("random_seed", -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated on docs.nav2.org: https://docs.nav2.org/configuration/packages/configuring-amcl.html

@SteveMacenski
Copy link
Member

Small details and then happy to merge!

@StanByriukov02 StanByriukov02 force-pushed the amcl-random-seed-replayability branch from 4992b86 to 9656061 Compare January 13, 2026 10:24
Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
@StanByriukov02 StanByriukov02 force-pushed the amcl-random-seed-replayability branch from 9656061 to 142ce09 Compare January 13, 2026 10:29
@StanByriukov02
Copy link
Contributor Author

Done.

Can we merge?

@SteveMacenski
Copy link
Member

SteveMacenski commented Jan 13, 2026

Please see https://github.com/ros-navigation/navigation2/pull/5856/files#r2683965698 -- we still need the docs PR opened to add this to the configuration guide

Otherwise, the code changes are approved!

@StanByriukov02
Copy link
Contributor Author

Docs PR opened in docs.nav2.org to document random_seed and update the example YAML: ros-navigation/docs.nav2.org#848

@SteveMacenski SteveMacenski merged commit a17d7d8 into ros-navigation:main Jan 13, 2026
17 checks passed
@StanByriukov02
Copy link
Contributor Author

Great - this will be useful.

Quick favor: could you reply confirming (in plain text) that my AMCL random_seed determinism/replayability changes were reviewed and merged?

Refs:

One sentence is enough, with your name + role/affiliation + today’s date. If you’d rather do this over email, tell me the best address and I’ll send the exact text.

Thank you - time sensitive.

@SteveMacenski
Copy link
Member

I'm sorry - what is this regarding?

@StanByriukov02
Copy link
Contributor Author

This is for a time-sensitive attorney/immigration evidence packet.

I need a single plain-text confirmation from you that you reviewed and merged my AMCL random_seed change.

One sentence like this is enough:

“I reviewed and merged ros-navigation/navigation2 PR #5856 (AMCL random_seed). — Steve Macenski, Nav2 maintainer, YYYY-MM-DD”

This will be enough if it is not difficult.

Lotusymt pushed a commit to Lotusymt/navigation2 that referenced this pull request Jan 16, 2026
…den time seeding in PF (ros-navigation#5856)

* nav2_amcl: add random_seed for deterministic replay

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: avoid long in pf_seed signature

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: avoid long cast when seeding RNG

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: add gtest to cover random_seed deterministic branch

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: fix whitespace for pre-commit

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: address review feedback for random_seed

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: remove random_seed comments; document parameter

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

---------

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Co-authored-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Lotusymt pushed a commit to Lotusymt/navigation2 that referenced this pull request Jan 16, 2026
…den time seeding in PF (ros-navigation#5856)

* nav2_amcl: add random_seed for deterministic replay

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: avoid long in pf_seed signature

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: avoid long cast when seeding RNG

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: add gtest to cover random_seed deterministic branch

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: fix whitespace for pre-commit

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: address review feedback for random_seed

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: remove random_seed comments; document parameter

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

---------

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Co-authored-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Signed-off-by: lotusymt <mengtiy5@uci.edu>
Pana1v pushed a commit to Arnav-panjla/navigation2 that referenced this pull request Feb 21, 2026
…den time seeding in PF (ros-navigation#5856)

* nav2_amcl: add random_seed for deterministic replay

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: avoid long in pf_seed signature

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: avoid long cast when seeding RNG

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: add gtest to cover random_seed deterministic branch

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: fix whitespace for pre-commit

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: address review feedback for random_seed

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

* nav2_amcl: remove random_seed comments; document parameter

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>

---------

Signed-off-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Co-authored-by: StanByriukov02 <StanByriukov02@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants