-
Notifications
You must be signed in to change notification settings - Fork 505
Omni wheel drive odometry update #2286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Devdoot57
wants to merge
6
commits into
ros-controls:master
Choose a base branch
from
Devdoot57:omni-drive-odom-update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−9
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e8849e
Omni wheel update: replaced rclcpp::Time with dt
Devdoot57 61bc1a3
Added Omni wheel odometry tests
Devdoot57 99fc48e
Merge branch 'master' into omni-drive-odom-update
Devdoot57 0f1d589
Suppress compiler warnings
Devdoot57 f714380
Merge branch 'master' into omni-drive-odom-update
christophfroehlich 600a7a2
Removed try_ prefix from open loop update method
Devdoot57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // Copyright 2026 Devdoot Chatterjee | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "gmock/gmock.h" | ||
| #include "omni_wheel_drive_controller/odometry.hpp" | ||
|
|
||
| class OmniOdometryTest : public ::testing::Test | ||
| { | ||
| protected: | ||
| void SetUp() override | ||
| { | ||
| // Standard 4-wheel omni robot | ||
| // Robot radius = 1.0m, Wheel radius = 0.1m, Wheel offset = 0.0 rads, 4 wheels | ||
| odometry_.setParams(1.0, 0.1, 0.0, 4); | ||
| } | ||
|
|
||
| omni_wheel_drive_controller::Odometry odometry_; | ||
| }; | ||
|
|
||
| TEST_F(OmniOdometryTest, TestInitialState) | ||
| { | ||
| EXPECT_DOUBLE_EQ(odometry_.getX(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getY(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getHeading(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getLinearXVel(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getLinearYVel(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getAngularVel(), 0.0); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestLinearMotionX) | ||
| { | ||
| // Move purely forward in X: Vx = 1.0, Vy = 0.0, W = 0.0, dt = 1.0 | ||
| // W0 = 0, W1 = 10, W2 = 0, W3 = -10 | ||
| std::vector<double> wheel_vels = {0.0, 10.0, 0.0, -10.0}; | ||
| bool result = odometry_.update_from_vel(wheel_vels, 1.0); | ||
|
|
||
| EXPECT_TRUE(result); | ||
| EXPECT_NEAR(odometry_.getX(), 1.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getY(), 0.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getHeading(), 0.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getLinearXVel(), 1.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getLinearYVel(), 0.0, 1e-5); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestLinearMotionY) | ||
| { | ||
| // Strafing purely sideways in Y: Vx = 0.0, Vy = 1.0, W = 0.0, dt = 1.0 | ||
| // W0 = -10, W1 = 0, W2 = 10, W3 = 0 | ||
| std::vector<double> wheel_vels = {-10.0, 0.0, 10.0, 0.0}; | ||
| bool result = odometry_.update_from_vel(wheel_vels, 1.0); | ||
|
|
||
| EXPECT_TRUE(result); | ||
| EXPECT_NEAR(odometry_.getX(), 0.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getY(), 1.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getHeading(), 0.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getLinearYVel(), 1.0, 1e-5); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestPureRotation) | ||
| { | ||
| // Rotate in place: Vx = 0.0, Vy = 0.0, W = 2.0, dt = 1.0 | ||
| // W0 = -20, W1 = -20, W2 = -20, W3 = -20 | ||
| std::vector<double> wheel_vels = {-20.0, -20.0, -20.0, -20.0}; | ||
| bool result = odometry_.update_from_vel(wheel_vels, 1.0); | ||
|
|
||
| EXPECT_TRUE(result); | ||
| EXPECT_NEAR(odometry_.getX(), 0.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getY(), 0.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getHeading(), 2.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getAngularVel(), 2.0, 1e-5); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestCurvedMotion_ExactArc) | ||
| { | ||
| // Curve: Moving in X, Y, and Rotating simultaneously | ||
| // Vx = 1.5, Vy = 0.5, W = 1.0, dt = 1.0 | ||
| // W0 = (-0.5 - 1.0)*10 = -15 | ||
| // W1 = (1.5 - 1.0)*10 = 5 | ||
| // W2 = (0.5 - 1.0)*10 = -5 | ||
| // W3 = (-1.5 - 1.0)*10 = -25 | ||
| std::vector<double> wheel_vels = {-15.0, 5.0, -5.0, -25.0}; | ||
| bool result = odometry_.update_from_vel(wheel_vels, 1.0); | ||
| EXPECT_TRUE(result); | ||
|
|
||
| const double expected_x = (1.5 / 1.0) * std::sin(1.0) + (0.5 / 1.0) * (std::cos(1.0) - 1.0); | ||
| const double expected_y = -(1.5 / 1.0) * (std::cos(1.0) - 1.0) + (0.5 / 1.0) * std::sin(1.0); | ||
|
|
||
| EXPECT_NEAR(odometry_.getX(), expected_x, 1e-5); | ||
| EXPECT_NEAR(odometry_.getY(), expected_y, 1e-5); | ||
| EXPECT_NEAR(odometry_.getHeading(), 1.0, 1e-5); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestSmallDtRejection) | ||
| { | ||
| std::vector<double> wheel_vels = {1.0, 1.0, 1.0, 1.0}; | ||
| bool result = odometry_.update_from_vel(wheel_vels, 1e-7); | ||
|
|
||
| EXPECT_FALSE(result); | ||
| EXPECT_DOUBLE_EQ(odometry_.getX(), 0.0); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestOpenLoopUpdate) | ||
| { | ||
| // Directly feed vx=2.0, vy=0.5, w=1.0, dt=1.0 to bypass SVD math | ||
| bool result = odometry_.try_update_open_loop(2.0, 0.5, 1.0, 1.0); | ||
|
|
||
| EXPECT_TRUE(result); | ||
|
|
||
| const double expected_x = (2.0 / 1.0) * std::sin(1.0) + (0.5 / 1.0) * (std::cos(1.0) - 1.0); | ||
| const double expected_y = -(2.0 / 1.0) * (std::cos(1.0) - 1.0) + (0.5 / 1.0) * std::sin(1.0); | ||
|
|
||
| EXPECT_NEAR(odometry_.getX(), expected_x, 1e-5); | ||
| EXPECT_NEAR(odometry_.getY(), expected_y, 1e-5); | ||
| EXPECT_DOUBLE_EQ(odometry_.getHeading(), 1.0); | ||
|
|
||
| EXPECT_DOUBLE_EQ(odometry_.getLinearXVel(), 2.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getLinearYVel(), 0.5); | ||
| EXPECT_DOUBLE_EQ(odometry_.getAngularVel(), 1.0); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestUpdateFromPosition) | ||
| { | ||
| // Feed position increments that equate to Vx=1.0 over dt=1.0 | ||
| std::vector<double> wheel_pos = {0.0, 10.0, 0.0, -10.0}; | ||
|
|
||
| bool result = odometry_.update_from_pos(wheel_pos, 1.0); | ||
|
|
||
| EXPECT_TRUE(result); | ||
| EXPECT_NEAR(odometry_.getX(), 1.0, 1e-5); | ||
| EXPECT_NEAR(odometry_.getLinearXVel(), 1.0, 1e-5); | ||
| } | ||
|
|
||
| TEST_F(OmniOdometryTest, TestReset) | ||
| { | ||
| // 1. Move the robot | ||
| std::vector<double> wheel_vels = {0.0, 10.0, 0.0, -10.0}; | ||
| bool result = odometry_.update_from_vel(wheel_vels, 1.0); | ||
| EXPECT_TRUE(result); | ||
| EXPECT_NE(odometry_.getX(), 0.0); | ||
|
|
||
| // 2. Reset | ||
| odometry_.setOdometry(0.0, 0.0, 0.0); | ||
|
|
||
| // 3. Verify position is cleared | ||
| EXPECT_DOUBLE_EQ(odometry_.getX(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getY(), 0.0); | ||
| EXPECT_DOUBLE_EQ(odometry_.getHeading(), 0.0); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the try_ prefix here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is similar to #1854, what was the intention back then @Amronos? because it won't get updated when dt is close to zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really remember the reason now, update_open_loop would be better though.