Skip to content

Conversation

@Amronos
Copy link
Contributor

@Amronos Amronos commented Aug 6, 2025

Fixes #271.
Fixes #357.

I have updated the odometry implementation of the diff_drive_controller to fix the above two issues alongside improving the code's readability. This implementation is similar to that of omni_wheel_drive_controller.
I have created some new methods and deprecated the older ones.

Should I also make similar changes to other controllers? If yes, should I do that in a separate PR?

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 79.71014% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.91%. Comparing base (ec198b1) to head (b474fde).

Files with missing lines Patch % Lines
...iff_drive_controller/src/diff_drive_controller.cpp 80.00% 4 Missing and 3 partials ⚠️
diff_drive_controller/src/odometry.cpp 79.41% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1854      +/-   ##
==========================================
- Coverage   85.13%   84.91%   -0.22%     
==========================================
  Files         144      144              
  Lines       13968    14002      +34     
  Branches     1201     1204       +3     
==========================================
- Hits        11891    11890       -1     
- Misses       1670     1705      +35     
  Partials      407      407              
Flag Coverage Δ
unittests 84.91% <79.71%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...troller/include/diff_drive_controller/odometry.hpp 100.00% <ø> (ø)
...iff_drive_controller/src/diff_drive_controller.cpp 83.00% <80.00%> (+0.32%) ⬆️
diff_drive_controller/src/odometry.cpp 50.90% <79.41%> (-25.41%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

Let's discuss my points first, and merge the outcome. If necessary, let's open a new PR afterwards for the other controllers.

@Amronos
Copy link
Contributor Author

Amronos commented Sep 4, 2025

Sorry for the delay in fixing the failing checks here! I was busy shifting Linux distros and had tried to make the commits that caused the checks to fail through the web.

Copy link
Member

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

Still not sure about the tryUpdateOpenLoop method, maybe @saikishor or anyone else has an opinion about that.

@Amronos
Copy link
Contributor Author

Amronos commented Sep 24, 2025

@christophfroehlich pre-commit isn't working for me for some reason, but besides that I have made the changed you requested. If possible, could you clone the pr, and push a fix for the pre-commit? Thanks!

@mergify
Copy link
Contributor

mergify bot commented Oct 3, 2025

This pull request is in conflict. Could you fix it @Amronos?

@Amronos
Copy link
Contributor Author

Amronos commented Oct 3, 2025

Sorry for the delay on this! All requested changes have been made now, please review!

Copy link
Member

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

Thanks for your patience. This is almost good to be merged, two minor comments only

Copy link
Member

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

Thanks for the latest cleanup! LGTM

Comment on lines +42 to +44
[[deprecated(
"Replaced by bool update_from_pos(double left_pos, double right_pos, const "
"rclcpp::Time & time).")]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[[deprecated(
"Replaced by bool update_from_pos(double left_pos, double right_pos, const "
"rclcpp::Time & time).")]]
[[deprecated(
"Replaced by bool update_from_pos(double left_pos, double right_pos, double "
"dt).")]]

Comment on lines +46 to +48
[[deprecated(
"Replaced by bool update_from_vel(double left_vel, double right_vel, const "
"rclcpp::Time & time).")]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[[deprecated(
"Replaced by bool update_from_vel(double left_vel, double right_vel, const "
"rclcpp::Time & time).")]]
[[deprecated(
"Replaced by bool update_from_vel(double left_vel, double right_vel, double "
"dt).")]]

Comment on lines +50 to +53
[[deprecated(
"Replaced by bool try_update_open_loop(double linear_vel, double angular_vel, const "
"rclcpp::Time "
"& time).")]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[[deprecated(
"Replaced by bool try_update_open_loop(double linear_vel, double angular_vel, const "
"rclcpp::Time "
"& time).")]]
[[deprecated(
"Replaced by bool try_update_open_loop(double linear_vel, double angular_vel, double "
"dt).")]]


bool Odometry::update_from_vel(double left_vel, double right_vel, double dt)
{
// Compute linear and angular velocities of the robot:
Copy link
Contributor

@Juliaj Juliaj Nov 29, 2025

Choose a reason for hiding this comment

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

Let's add this check back

  if (dt < 0.0001)
  {
    return false;  // Interval too small to integrate with
  }


void Odometry::integrate(double linear_vel, double angular_vel, double dt)
{
const double dx = linear_vel * dt;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const double dx = linear_vel * dt;
// Skip integration for invalid time intervals
if (std::fabs(dt) < 1e-6)
{
return;
}
const double dx = linear_vel * dt;

{
previous_publish_timestamp_ += publish_period_;
should_publish = true;
if (previous_publish_timestamp_ + publish_period_ < time)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (previous_publish_timestamp_ + publish_period_ < time)
if (previous_publish_timestamp_ + publish_period_ <= time)

Comment on lines +230 to 235
catch (const std::runtime_error &)
{
odometry_message_.header.stamp = time;
odometry_message_.pose.pose.position.x = odometry_.getX();
odometry_message_.pose.pose.position.y = odometry_.getY();
odometry_message_.pose.pose.orientation.x = orientation.x();
odometry_message_.pose.pose.orientation.y = orientation.y();
odometry_message_.pose.pose.orientation.z = orientation.z();
odometry_message_.pose.pose.orientation.w = orientation.w();
odometry_message_.twist.twist.linear.x = odometry_.getLinear();
odometry_message_.twist.twist.angular.z = odometry_.getAngular();
realtime_odometry_publisher_->try_publish(odometry_message_);
// Handle exceptions when the time source changes and initialize publish timestamp
previous_publish_timestamp_ = time;
should_publish = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this block meant to catch the error of previous_publish_timestamp as unintialized ? if so, we should initialize it in on_configure. If not, this block may not be reachable.

@Juliaj
Copy link
Contributor

Juliaj commented Nov 29, 2025

@Amronos, thanks for working on this PR. It would be great to add some tests for the odometry changes. If you can't accommodate this within this PR, please consider creating a GitHub issue so the community can pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants