Add SwerveDriveOdometry utility to gz-math#718
Add SwerveDriveOdometry utility to gz-math#718C88-YQ wants to merge 11 commits intogazebosim:mainfrom
Conversation
arjo129
left a comment
There was a problem hiding this comment.
This is a good first attempt, there is an edge case I've thought of that I dont think handled correctly.
The rest of the math seems to check out and co uld be genuinely useful for the communinty.
|
Also consider re-targetting this pr to |
7cae895 to
6e08ced
Compare
|
Hi @arjo129, thanks again for the detailed review! All the suggestions have now been addressed in the latest commits. |
|
Hi @arjo129 Could you please approve the workflow again so the remaining CI checks can run? |
|
Hi @arjo129, I updated the Eigen Bazel dependency in BUILD.bazel. Initially I added My local Bazel environment currently seems to have some issues, so I'm not fully confident that my local results reflect the CI environment correctly. Could you please approve the workflows again so the remaining CI checks can run with the latest changes? |
|
Yeah the eigen dependency is another thing I'm going to have to look into a bit. For some reason I thought we always depended on eigen but that turns out to not be the case. FWIW I think sim itself depends on Eigen, but math does not. I'll ask in zulip about this to see the best way forward. |
|
Thanks for looking into this! In my current implementation of If depending on Eigen is not recommended for gz-math, solving this system without it might become a bit cumbersome. One possible option could be to adopt approaches like the one described here: https://control.ros.org/humble/doc/ros2_controllers/doc/mobile_robot_kinematics.html#omnidirectional-drive-robots-using-omni-wheels:~:text=)-,Odometry,-The%20body%20twist Another alternative would be implementing something similar to Eigen’s SVD directly in gz-math, but that might also introduce some complexity. I’m happy to follow whatever direction is preferred here. |
|
I fully agree that we should leverage Eigen’s SVD (Singular Value Decomposition) for our mathematical operations. It is a robust, industry-standard solution that makes a lot of sense for our requirements. Before proceeding, I want to consult with the wider community to ensure there wasn't a specific historical or architectural reason why Eigen wasn't introduced to gz-math previously. If there are no blockers, I'll move forward with the integration. |
|
That sounds great to me! Looking forward to the outcome of the discussion. |
fe885fa to
83b7781
Compare
arjo129
left a comment
There was a problem hiding this comment.
I asked the council of elders of gazebo #Gazebo PMC (Restricted posting) > Is making gz-math depend on eigen a good idea?. Eigen should be fine, only to discover we seem to redistribute eigen in this repo 🤣 .
Thanks for the quick iteration on this PR. LGTM!
|
That's great! Thanks a lot for the quick review and feedback, I really appreciate it! Once this PR is merged, I’ll mark the corresponding PR in |
|
I saw the discussion on Zulip, but I can't comment there. I'm asking myself - if I install something called gz-math, would I expect Eigen to be brought in? Sure! Is there an actual reason for not wanting Eigen for math? |
|
This is what I commented on Zulip:
We can have a discussion on whether we should make Eigen a dependency of gz-math core, but this is not currently the case. It will also likely not be backportable if we make the change. Generally, I have no problem making Eigen a core dependency. @traversaro seemed to be concerned about using it in our public headers though. |
|
Thanks for the clarification. Just to confirm: in my implementation Eigen is only used inside the src/SwerveDriveOdometry.cc solving the linear system via SVD, and it is not exposed in any public headers. If this feature is expected to be backported to other versions where introducing Eigen as a core dependency is not desirable, I could also prepare an alternative implementation that does not rely on Eigen. However, that approach might be somewhat less robust compared to using Eigen‘s SVD. |
Hmm, if you just need to solve least squares, you can use pseudoinverse. It's just 3 matrix multiplications. Maybe SVD is faster in general, but this could be a way to sneak in this controller to the released distros (with potentially less efficient computation). |
Using Eigen in gz-math core but not in public headers seems reasonable to me. We already require the |
I split the Eigen dependency change out into #721 |
|
@peci1 Thanks for your suggestion! I tried implementing the computation using the native matrix / vector types already available in gz-math, but the overall implementation became somewhat cumbersome. The linear system comes from the wheel velocity constraints of the controller. Each wheel provides one constraint relating the robot body velocity to the wheel velocity: Where:
By writing this constraint for the four wheels, we obtain an overdetermined linear system of the form In addition, my implementation separately handles the So overall, while a non-Eigen implementation seems possible, the computation path starts to feel somewhat awkward and verbose when expressed only with gz-math primitives. That is one reason I am hesitating on whether this is the right direction for this PR. Because of this, I wanted to ask for advice:
As mentioned earlier, I also considered another approach which avoids solving the linear system(https://control.ros.org/humble/doc/ros2_controllers/doc/mobile_robot_kinematics.html#omnidirectional-drive-robots-using-omni-wheels:~:text=)-,Odometry,-The%20body%20twist), However, I suspect the numerical behavior might not be as good as the SVD-based method in some cases. |
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
83b7781 to
0a58f4e
Compare
|
Since #721 has now been merged, I’ve rebased this branch and removed the dependency-related changes that were previously included in this PR😊 |
🎉 New feature
Related to gazebosim/gz-sim#3364
Summary
This PR introduces a new
SwerveDriveOdometryutility class togz-math.The new class provides kinematic and odometry computation support for four-wheel independent steering (swerve / 4WISD) drive systems.
Main features:
gz-mathThis utility is intended to support swerve drive system implementations in
gz-sim, while keeping kinematics and odometry logic withingz-mathto preserve architectural separation between math utilities and simulation systems.The implementation does not modify any existing behavior.
If Eigen (or any additional math utilities) are used internally, they are not exposed in the public API.
Test it
To test this feature locally:
Build
gz-mathRun the unit tests (or filter to only the new test):
The new unit tests cover:
Checklist
codecheckpassed (See contributing)