erwincoumans / tiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.
Apache License 2.0
1.2k stars 129 forks source link

Spherical joint implementation #57

Closed PaulSchreiner closed 3 years ago

PaulSchreiner commented 3 years ago

It took a while but here is a working implementation of a spherical joint.

I have created (copy/pasted) a new example called spherical_joint_test, based on the pendulum_example_gui which works for both the Tiny and Eigen algebra's. I have not implemented it for any of the other algebra's.

The bug in the previous PR turned out to be an issue with an errornous transpose in mul_transpose() for matrix6x3, now it runs pretty stable. I could get it to explode but that was when I run a simulation with 50 undamped spherical joints after a good few seconds of simulation. To be sure that this is not related to the spherical joints I checked with the pendulum example and the same happens if I chain 50 undamped hinges.

I have made an implementation for the mass_matrix calculation too, but I am not 100% sure that it is correct and I haven't got time to do extensive tests at the moment.

This is what I have changed:

erwincoumans commented 3 years ago

Ah, very nice, thanks a lot! I didn't get a notification, need to set it up. Will check the PR soon, I was busy getting the CUDA laikago example wrapped up (see https://twitter.com/erwincoumans/status/1340056288902795266)

PaulSchreiner commented 3 years ago

That looks great with the CUDA suport, I am looking forward to trying that out myself!

erwincoumans commented 3 years ago

close-reopen to retrigger CI

PaulSchreiner commented 3 years ago

Hi Erwin, is this still active?

erwincoumans commented 3 years ago

Yes, will get back to this soon after the holidays. Happy new year Paul!

PaulSchreiner commented 3 years ago

Great, happy new year to you too! Enjoy the rest of your holidays.

erwincoumans commented 3 years ago

Hi Paul,

I had a quick look at the spherical joint test 1) Eigen version seems to work, Tiny version doesn't. See video. 2) the laikago_opengl_eigen_example (and a few others) are broken, in euler_integrate, the qdindex of some link is -2. You can easily reproduce it in 'Debug' mode using the free Visual Studio 2019 on Windows.

Can you check it? I'll also have a look. Thanks! Erwin

erwincoumans commented 3 years ago

Let's merge for now, it requires some small fixes in integrator.hpp to solve (2), will look into (1) later. Thanks for the contribution!

PaulSchreiner commented 3 years ago

Hi Erwin, I can see you fixed (2), I must have missed that if statement.

I am trying to run the spherical pendulum example from the current master but it fails telling me it can't find pendulum5spherical.urdf but I could reproduce the issue in my fork. I am guessing it is an issue within TinyAlgebra, maybe some of the functions I implemented there are not numerically stable.

I will have a look at it over the next few days but I am a bit bussy with a deadline the end of the month so I might be a bit slow.

Cheers, Paul.

erwincoumans commented 3 years ago

Yes, I just added the missing URDF file. In general, it is easier to create a URDF file instead of programmatic generating figures. The Tiny issue is likely a small bug somewhere, we'll figure it out (easy to compare side-by-side using Eigen)