gazebosim / gz-sim

Open source robotics simulator. The latest version of Gazebo.
https://gazebosim.org
Apache License 2.0
685 stars 262 forks source link

Question regarding mecanum drive plugin & feature request #2261

Closed PerFrivik closed 8 months ago

PerFrivik commented 9 months ago

Desired behavior

My question is how the current mecanum plugin works, I don't see any force control in the plugin, so I feel like the plugin is actually friction-based simulation? If that is the case, how do you manage it? When looking at the collision model, the wheels are spheres with only one joint. This can be found around 12 seconds into the video.

https://www.youtube.com/watch?v=keGh5wYqTOg

I would like to propose a feature where we can individually manage the angular velocities of each wheel, instead of just controlling the overall linear velocities in the x and y axes and the yaw velocity. This feature would allow us to directly publish commands to a topic that controls each of the four (or more) wheels separately. The primary benefit of this approach is that it enables us to handle the inverse kinematics calculations on our end, rather than relying on the existing plugin to do so.

Implementation suggestion

Add another topic to control all 4 or more wheels independently :)! The topic only needs 4 wheels, but we can map more in the URDF.

PerFrivik commented 9 months ago

@mjcarroll I was wondering if you maybe know more about this?

azeey commented 9 months ago

@scpeters any thoughts?

PerFrivik commented 9 months ago

Screencast from 15.12.2023 15:04:14.webm

Any updates? I am really confused on how this plugin works, I even swapped the spheres for cylinders and it works. But I see no forces applied to any body? Just pure wheel speeds.

azeey commented 9 months ago

It works using the same principle as tracked vehicles (see https://arxiv.org/pdf/1703.04316.pdf) where the desired velocity is part of the constraints on a contact point, in addition to normal force and friction. The constraint solver is asked to satisfy this desired velocity so it will apply the necessary force on the wheels. This is a much more efficient way of modelling tracked vehicles and mecanum wheels than simulating the individual wheels. At least for tracked vehicles, we've tried in the past to simulate individual wheels, and while it works, the performance drops due to the sheer number of contacts to process.

PerFrivik commented 9 months ago

@azeey, thank you for your recent clarifications! They were really helpful. Could you please guide me to where I can find these equations in our codebase? I'd like to take a closer look.

Additionally, I wanted to come back to the feature I proposed earlier. Would you consider this feature beneficial and something you would consider merging if I implemented it? I am trying to implement a mecanum rover in PX4, but I want the controller to output the wheel speeds, that's why I would like to control the wheels directly, instead of the linear- and yaw velocity.

PerFrivik commented 9 months ago

Any updates on this? @azeey sorry for the constant tagging, I just really need this done for a project.

azeey commented 9 months ago

Any updates on this? @azeey sorry for the constant tagging, I just really need this done for a project.

If you want to control the velocities of each joint, we already have the JointController system. Can you not use that? It has topics for each wheel and can be set up to use velocity or force mode. Alternatively, it can use actuator messages to control all wheels with a single topic.

PerFrivik commented 9 months ago

Ah, so the mecanum force logic, is already built into gazebo. So if I simulate a rover and use 4 JointControllers, and use my custom mecanum inverse kinematics to control the 4 individual motors, the rover will behave like a mencaum rover even if I don't have the mecanum plugin in the sdf?

azeey commented 9 months ago

No, I thought you meant you'd model the wheels of a mecanum wheel. So are you asking about extending the Mecanum plugin so it accepts joint velocities as an alternative to cmd_vel, but still uses the current velocity constraint based approach to actually move the robot?

PerFrivik commented 9 months ago

"extending the Mecanum plugin so it accepts joint velocities as an alternative to cmd_vel, but still uses the current velocity constraint based approach to actually move the robot"

This is exactly what I mean! Sorry for being unclear.

azeey commented 9 months ago

In that case, yes, I think we'd welcome a PR. Thanks for your patience.

PerFrivik commented 9 months ago

Awesome! Thank you for your help :). Do you have any preference on what message type I should use for this? I think if we make something new or use something existing, we should make sure that the message type can get reused in other plugins, like differential drive, or Ackermann too. Or if required, make separate message types.

azeey commented 9 months ago

Would the Actuators message work? https://github.com/gazebosim/gz-msgs/blob/gz-msgs10/proto/gz/msgs/actuators.proto

bperseghetti commented 9 months ago

Awesome! Thank you for your help :). Do you have any preference on what message type I should use for this? I think if we make something new or use something existing, we should make sure that the message type can get reused in other plugins, like differential drive, or Ackermann too. Or if required, make separate message types.

I would suggest actuators msg as that is already used across most "drive" plugins and eliminates the painful need for super specific joint/entity names otherwise.

scpeters commented 8 months ago

Ah, so the mecanum force logic, is already built into gazebo.

Sorry I'm late to this discussion. Yes, the mecanum force logic is encoded within a given model's friction parameters:

See examples/worlds/mecanum_drive.sdf for an example. I need to write a tutorial to explain how these parameters all work together

So if I simulate a rover and use 4 JointControllers, and use my custom mecanum inverse kinematics to control the 4 individual motors, the rover will behave like a mencaum rover even if I don't have the mecanum plugin in the sdf?

yes, this should be the case

bperseghetti commented 8 months ago

Ah, so the mecanum force logic, is already built into gazebo.

Sorry I'm late to this discussion. Yes, the mecanum force logic is encoded within a given model's friction parameters:

  • //surface/friction/ode/mu
  • //surface/friction/ode/mu2
  • //surface/friction/ode/fdir
  • //surface/friction/ode/fdir/@gz:expressed_in

See examples/worlds/mecanum_drive.sdf for an example. I need to write a tutorial to explain how these parameters all work together

So if I simulate a rover and use 4 JointControllers, and use my custom mecanum inverse kinematics to control the 4 individual motors, the rover will behave like a mencaum rover even if I don't have the mecanum plugin in the sdf?

yes, this should be the case

This means you can just link it up from the Actuators message to control each joint.

PerFrivik commented 8 months ago

Ah, so the mecanum force logic, is already built into gazebo.

Sorry I'm late to this discussion. Yes, the mecanum force logic is encoded within a given model's friction parameters:

  • //surface/friction/ode/mu
  • //surface/friction/ode/mu2
  • //surface/friction/ode/fdir
  • //surface/friction/ode/fdir/@gz:expressed_in

See examples/worlds/mecanum_drive.sdf for an example. I need to write a tutorial to explain how these parameters all work together

So if I simulate a rover and use 4 JointControllers, and use my custom mecanum inverse kinematics to control the 4 individual motors, the rover will behave like a mencaum rover even if I don't have the mecanum plugin in the sdf?

yes, this should be the case

Ohh, awesome! I was quite confused, but now it makes sense! Thank you, but then I don't need to make the PR, I can just use 4 joint controllers and leave away the mecanum plugin.

Also, yes a video would be awesome, I think it would help a lot of beginners (like me :D) and save you guys some time.

Thank you for the help guys, I really appreciate it!