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 80.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.04%. Comparing base (4f9c462) to head (93806d6).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
diff_drive_controller/src/odometry.cpp 76.92% 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.26%   85.04%   -0.22%     
==========================================
  Files         143      143              
  Lines       13794    13833      +39     
  Branches     1193     1197       +4     
==========================================
+ Hits        11761    11764       +3     
- Misses       1636     1673      +37     
+ Partials      397      396       -1     
Flag Coverage Δ
unittests 85.04% <80.00%> (-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.22% <83.33%> (+0.64%) ⬆️
diff_drive_controller/src/odometry.cpp 51.30% <76.92%> (-25.02%) ⬇️
🚀 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
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.

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