Skip to content
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

Adding MecanumDrive plugin with Odom and Tf, with Tests. #2297

Open
wants to merge 18 commits into
base: gz-sim8
Choose a base branch
from

Conversation

muttistefano
Copy link

@muttistefano muttistefano commented Jan 24, 2024

🎉 New feature

Summary

Adding MecanumDrive plugin with Odom and Tf, with Tests.
Relative to #1665 , but targets gz-sim8, fixes an include error in the plugin and add tests.

Checklist

  • [ x] Signed all commits for DCO
  • [ x] Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸

@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Jan 24, 2024
@azeey
Copy link
Contributor

azeey commented Feb 2, 2024

Thanks for your contribution @muttistefano. Do you mind fixing the linter issues and signing off on your commit (see https://github.com/gazebosim/gz-sim/pull/2297/checks?check_run_id=20866188364).

@muttistefano
Copy link
Author

Hi @azeey , thanks for the answer.
I signed the commits but I don't understand the linter issue.

@azeey
Copy link
Contributor

azeey commented Feb 12, 2024

There are some trailing white spaces in the code (see https://github.com/gazebosim/gz-sim/actions/runs/7765649621/job/21405089973?pr=2297).

Stefano Mutti and others added 9 commits March 5, 2024 10:54
Signed-off-by: Stefano Mutti <[email protected]>
Signed-off-by: Stefano Mutti <[email protected]>
Signed-off-by: Stefano Mutti <[email protected]>
Signed-off-by: Stefano Mutti <[email protected]>
Signed-off-by: Stefano Mutti <[email protected]>
Signed-off-by: Stefano Mutti <[email protected]>
Signed-off-by: Stefano Mutti <[email protected]>
@will-44
Copy link

will-44 commented May 24, 2024

Hello !
I'm very interested in this PR (as I think a lot of people are). Do you think it could be merged into the main version?
Thank you very much for your help

@muttistefano
Copy link
Author

If I'm not mistaken, the checks are fine, the only thing missing is the review from @mjcarroll .
Thanks :)

Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

@muttistefano I think you've accidentally checked in a few files and directories (e.g. log, .vscode) to the pull request. Could you please remove them?

@muttistefano
Copy link
Author

My bad; it should be fixed now.

@azeey azeey self-requested a review June 10, 2024 18:55
@azeey
Copy link
Contributor

azeey commented Jun 18, 2024

Can you fix DCO?

Signed-off-by: Stefano Mutti <[email protected]>
@azeey azeey added the beta Targeting beta release of upcoming collection label Jul 29, 2024
test/integration/mecanum_drive_system.cc Outdated Show resolved Hide resolved
test/integration/mecanum_drive_system.cc Outdated Show resolved Hide resolved
#include "gz/sim/components/Model.hh"
#include "gz/sim/components/Pose.hh"
#include "gz/sim/Server.hh"
#include "gz/sim/SystemLoader.hh"
Copy link
Contributor

Choose a reason for hiding this comment

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

This header seems to be unused. Can you remove?

Comment on lines +194 to +195
// EXPECT_NEAR(poses.back().Pos().X(), finalModelFramePose.Pos().X(), 1e-2);
// EXPECT_NEAR(poses.back().Pos().Y(), finalModelFramePose.Pos().Y(), 1e-2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for commenting these out? finalModelFramePose is now an unused variable.

/////////////////////////////////////////////////
// See: https://github.com/gazebosim/gz-sim/issues/1175
// See: https://github.com/gazebosim/gz-sim/issues/630
TEST_P(MecanumDriveTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(PublishCmd))
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is copied from the DiffDrive test, but can we first try to enable it and see if it doesn't work on the other platforms?

Comment on lines +212 to +213
testCmdVel(true /*test forward movement*/);
testCmdVel(false /*test backward movement*/);
Copy link

Choose a reason for hiding this comment

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

I was unaware that this MR existed and basically did the exact same work two weeks ago. I also refactored the TestPublishCmd function to also test the sideways, diagonal and rotational movement of the drive instead of only forward and backward, which is what the diff drive test does.

Feel free to grab the function code from my changes in here to improve the coverage.

Comment on lines +159 to +168
// Odometry calculates the pose of a point that is located half way
// between the two wheels, not the origin of the model. For example,
// if the vehicle is commanded to rotate in place, the vehicle will
// rotate about the point half way between the two wheels, thus,
// the odometry position will remain zero.
// However, since the model origin is offset, the model position will
// change. To find the final pose of the model, we have to do the
// following similarity transformation

math::Pose3d tOdomModel(0.554283,0,-0.325,0,0,0);
Copy link

Choose a reason for hiding this comment

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

This transform is correct for the differential drive model, but not for the mecanum one. The mecanum math derivation places the origin at the center of the four wheels, which for the model in the xml is at math::Pose3d tOdomModel(-0.2, 0., 0., 0., 0., 0.);

This is not noticed in the test probably because no rotation is being applied to the drive.

@azeey azeey removed the beta Targeting beta release of upcoming collection label Aug 26, 2024
@garyservin
Copy link

any updates on this? It would be really great to have this implemented! Thanks!

return;
}

if (this->frontLeftJoints.empty() || this->frontRightJoints.empty() || this->backLeftJoints.empty() || this->backRightJoints.empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

please use lines with less than 100 characters

return;
}

this->odom.Update(frontLeftPos->Data()[0],frontRightPos->Data()[0],backLeftPos->Data()[0],backRightPos->Data()[0],std::chrono::steady_clock::time_point(_info.simTime));
Copy link
Contributor

Choose a reason for hiding this comment

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

include <chrono> and lines < 100

/// \param[in] _sdfFile SDF file to load.
/// \param[in] _cmdVelTopic Command velocity topic.
/// \param[in] _odomTopic Odometry topic.
protected: void TestPublishCmd(const std::string &_sdfFile,
Copy link
Contributor

Choose a reason for hiding this comment

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

include <string>

// Create a system that records the vehicle poses
test::Relay testSystem;

std::vector<math::Pose3d> poses;
Copy link
Contributor

Choose a reason for hiding this comment

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

include <vector>

double period{1.0 / 50.0};
double lastMsgTime{1.0};
std::vector<math::Pose3d> odomPoses;
std::function<void(const msgs::Odometry &)> odomCb =
Copy link
Contributor

Choose a reason for hiding this comment

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

include <functional>

// Start server
ServerConfig serverConfig;
serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/mecanum_drive.sdf");
Copy link
Contributor

Choose a reason for hiding this comment

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

use gz::common::joinPath()

// Start server
ServerConfig serverConfig;
serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/mecanum_drive_custom_frame_id.sdf");
Copy link
Contributor

Choose a reason for hiding this comment

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

use gz::common::joinPath()

// Start server
ServerConfig serverConfig;
serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/mecanum_drive_custom_tf_topic.sdf");
Copy link
Contributor

Choose a reason for hiding this comment

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

use gz::common::joinPath()


msgs::Twist msg;
msgs::Set(msg.mutable_linear(), math::Vector3d(0.5, 0, 0));
msgs::Set(msg.mutable_angular(), math::Vector3d(0.0, 0, 0.2));
Copy link
Contributor

Choose a reason for hiding this comment

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

include `gz::math::Vector3.hh

Comment on lines +289 to +292
</link>


<joint name='front_left_wheel_joint' type='revolute'>
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
</link>
<joint name='front_left_wheel_joint' type='revolute'>
</link>
<joint name='front_left_wheel_joint' type='revolute'>

@muttistefano
Copy link
Author

I cannot work anymore on gz-sim8 cause I don't have an Ubuntu 22 PC.
If I move the pull base to gz-sim9 do I mess up something?
Thanks

@azeey
Copy link
Contributor

azeey commented Nov 11, 2024

@muttistefano, gz-sim8 is supported on Ubuntu 24.04 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

6 participants