Problem simulating a car

I am writing a simulator for a robot on wheels.
I modeled it with a multibody with a cuboid in the middle and four revolute joints with spheres attached as wheels (it seems I could not use cylinders as colliders).

I can then control the motors on the joints, and it works, until one of these two things happens:

  • I leave the car stopped for a few seconds, or
  • (maybe, I should test this more) there are fast collisions with walls

At that point the system is “stuck”, and activating the motors does not move it anymore.

I have tried the following:

  • use shorter time steps in the simulation (up to virtually 500Hz)
  • use larger collider margins
  • increase the space between the wheels and the car body
  • generally increase every integration parameter I could find
  • use 64 bits instead of 32 in the simulation
    but nothing changed.

I see that there is a way to make rigid bodies sleep, I thought that could be the issue but I could not find the setting on multibody and multibody parts.

If you want to test it, you should clone this:

and just do cargo run at the root.
Then, if you quickly press the “manual” button and play with the control, you can move the car.
If you wait too much it freezes.

It is also possible to visualize the simulation using the testbed instead of using my UI, just invoke main_testbed instead of main_full inside the main function.

Sorry if the workspace is large and messy, this is part of a much larger project for a robotic competition and I did not want to open it before the competition… this repo is just a code dump if somebody wants to test it to solve this issue.



All body from nphysics will be put to sleep after a certain period of inactivity. So this applies to multibody too. So to solve your problem, the method you are looking for is multibody.activate(). You can for example call this before modifying the joint motors.

It is part of the Body trait which is implemented by all body types on nphysics. You will have to use nphysics3d::object::Body; in order to call this.

It is true that you can’t use cylinders, so the possible options are to:

  • Use a Ball like you did.
  • Use a Capsule which is like a cylinder but with rounded ends.
  • Use a Convex as a polyhedral approximation of a cylinder.

Thanks, this was spot on and solved the issue!

And thanks for the amazing work you are doing with these crates :slight_smile: