Skip to content

Drive PID from odometry stamps instead of a wall-clock poll - #22

Merged
Cruiz102 merged 5 commits into
mainfrom
sync-pid-odometry
Aug 26, 2026
Merged

Cruiz102 merged 5 commits into
mainfrom
sync-pid-odometry

Conversation

@Cruiz102

@Cruiz102 Cruiz102 commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Run the thruster PID on each /bridge/odometry message instead of polling pose every 100 ms in a separate loop. Pose is still stored on td.pose for move_to.
  • Take dt from the odometry header stamp so I/D follow sensor/sim time rather than Instant. Skip I/D on the first sample; if a later stamp is not increasing, skip I/D for that tick and log a warning.
  • Log the thruster/battery report on every control tick (no 0.5 s wall-clock throttle).
  • Fast sim is wired through stonefish.launch.py (fast_fixed_step, use_sim_time_stamps, realtime_factor_cap). Headless CI/README call that launch file with CLI args; no extra wrapper launch file.

This is the control-timing slice only. The larger mission_executor rewrite stays on the local main working tree.

Test plan

  • Launch sim and confirm /bridge/thrusters publishes at the odometry rate, not 10 Hz.
  • Confirm pose still updates for move_to (missions still see td.pose).
  • Check I/D at 1× realtime vs a faster sim rate: dt should track pose stamps, not wall clock.
  • Confirm a non-increasing odometry stamp logs go_to_goal warn and does not spike I/D.
  • Headless: ros2 launch bringup stonefish.launch.py with headless:=true, hydrus_env_headless.scn, fast_fixed_step:=true, use_sim_time_stamps:=true, realtime_factor_cap:=5.0.

Fold pose updates into the controller callback and take dt from the odometry header so I/D terms follow sensor/sim time instead of a 100 ms Instant poll.

Co-authored-by: Cursor <cursoragent@cursor.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a219aac4d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


tokio::spawn(consume_inotify_stream());
tokio::spawn(consume_map_sub(Arc::clone(&td)));
tokio::spawn(consume_odometry_sub(Arc::clone(&td)));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Deleted the consumer_odometry callback. Now we consume odometry inside go_to_goal.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would probably do it the other way around, so just do the "go to goal" stuff inside consume_odometry_sub

but really don't matter

let current_cfg = cfg.load();
let PidConfig { kp, ki, kd } = current_cfg.pid[&bridge_name];
let tam_x_y_z_roll_pitch_yaw = &current_cfg.tam;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Deleted the instant::now() inside the loop. Now we get the dt from the msg.header.stamp msg::Time

This is to gaurrantee that we are using the clock of the odometry source. That its not the same in the simulation if we increase the clock rate.

Cruiz102 and others added 3 commits August 20, 2026 22:49
…os2 fork.

Point the submodule at Rumarino-Team/stonefish_ros2, pass fast_fixed_step / sim stamps / RTF cap from bringup, and run headless CI at 5x so PID dt follows pose time.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Cruiz102
Cruiz102 merged commit c6b5963 into main Aug 26, 2026
1 check passed
@Cruiz102
Cruiz102 deleted the sync-pid-odometry branch August 26, 2026 06:33
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