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?

Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 79.72973% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.75%. Comparing base (a01fd0b) to head (fe3a568).

Files with missing lines Patch % Lines
diff_drive_controller/src/odometry.cpp 76.31% 8 Missing and 1 partial ⚠️
...iff_drive_controller/src/diff_drive_controller.cpp 83.33% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1854      +/-   ##
==========================================
- Coverage   85.98%   85.75%   -0.24%     
==========================================
  Files         129      129              
  Lines       13112    13150      +38     
  Branches     1144     1148       +4     
==========================================
+ Hits        11275    11277       +2     
- Misses       1469     1506      +37     
+ Partials      368      367       -1     
Flag Coverage Δ
unittests 85.75% <79.72%> (-0.24%) ⬇️

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.22% <83.33%> (+0.64%) ⬆️
diff_drive_controller/src/odometry.cpp 50.87% <76.31%> (-25.44%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

bool updateFromVelocity(double left_vel, double right_vel, const rclcpp::Time & time);
[[deprecated(
"Replaced by bool updateOpenLoop(const double & linear_vel, const double & angular_vel, const "
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
"Replaced by bool updateOpenLoop(const double & linear_vel, const double & angular_vel, const "
"Replaced by bool tryUpdateOpenLoop(const double & linear_vel, const double & angular_vel, const "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 629cf5e,

Copy link
Contributor

@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.

bool Odometry::updateFromVel(
const double & left_vel, const double & right_vel, const rclcpp::Time & time)
{
const double dt = time.seconds() - timestamp_.seconds();
Copy link
Contributor

Choose a reason for hiding this comment

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

this is exactly the pattern mentioned with #271 to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I should have explained this in the PR description.
The reasoning here is the same as that of this #260 (comment).
Additionally, timestamp_ records the last time an update was run; therefore, the correct value of dt can only be obtained from there.
It is used in this function despite (std::fabs(dt) < 1e-6) not being used, as it is also called from updateFromPos() which uses the timestamp_ variable.

linear_ = linear_vel;
angular_ = angular_vel;

return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

why a return value, which is always true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is there to maintain consistency with other update methods, make it easier to add code to this function in the future that may return false, and make the diff_drive_controller.cpp code simpler.
updateFromVel() also has this line for the same reason.
I can change everything back to the normal updateOpenLoop() function if needed, though.

odometry_.updateFromVelocity(
left_feedback_mean * left_wheel_radius * period.seconds(),
right_feedback_mean * right_wheel_radius * period.seconds(), time);
odometry_updated = odometry_.updateFromVel(left_feedback_mean, right_feedback_mean, time);
Copy link
Contributor

Choose a reason for hiding this comment

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

where did the wheel_radius go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad! This was meant to be multiplied in the updateFromVel() function. Fixed with d387750.

Amronos and others added 4 commits August 20, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants