jrl-umi3218 / RBDyn

RBDyn provides a set of classes and functions to model the dynamics of rigid body systems.
BSD 2-Clause "Simplified" License
163 stars 47 forks source link

Is it possible to speed up the CoM Jacobian calculation by generating the CoM Jacobian code? #58

Closed oofrivia closed 5 years ago

oofrivia commented 5 years ago

Hi! I met with some problems with the Center Of Mass Jacobian for a humanoid robot.

It is easy to use CoMJacobian to calculate the CoM Jacobian, but it uses more than 1.5 milliseconds on an I5 Intel processor, and I want it to be faster, so I want to speed up the calculation by generating the CoM Jacobian code like this library do: https://github.com/cdsousa/SymPyBotics

rbt.kin.J[-1] Matrix([ [0, 0], [0, 0], [0, 0], [0, -cos(q1)], [0, -sin(q1)], [1, 0]])

Above is a two dof jacobian matrix. May I get a matrix like this, and I can use mbc.q to directly calculate the CoM Jacobian? If it is possible, how could I get the 3x18 CoM Jacobian matrix?

Thanks a lot!

jcarpent commented 5 years ago

@zisang I think you have compiled your code without using the flag Release for the CMAKE_BUILD_TYPE when generating your make through cmake.

gergondet commented 5 years ago

I agree with @jcarpent diagnostic. This looks you didn't set a CMAKE_BUILD_TYPE correctly. Either Release or RelWithDebInfo will get you much better performances (probably x1000 or more in this case).

oofrivia commented 5 years ago

Sorry to bother you, but I think the -DCMAKE_BUIlD_TYPE=Release flag doesn't work. Maybe 'Release' mode is set to default. I build RBDyn different flags: camke .. cmake -DCMAKE_BUIlD_TYPE=Release .. cmake --DCMAKE_BUIlD_TYPE=RelWithDebInfo .. cmake --DCMAKE_BUIlD_TYPE=Debug .. all these flags generated the same libRBDyn.so with exactly the same hash code. Before every next building, I deleted all files in RBDyn/_build/. And time-consuming is the same with all libRBDyn.so.

gergondet commented 5 years ago

@zisang the correct flag is CMAKE_BUILD_TYPE not CMAKE_BUIlD_TYPE as (at least for this) CMake is case-sensitive.

You can also build some simple benchmarks with the library by setting -DBENCHMARK=ON. The benchmarks run with a 30-dof humanoid-like tree.

This is the results I get in Debug: (not your CPU obviously, but I don't expect to see drasitcally different results)

Run on (8 X 3800 MHz CPU s)
2019-03-19 14:35:45
***WARNING*** Library was built as DEBUG. Timings may be affected.
-----------------------------------------------------------------------
Benchmark                                Time           CPU Iterations
-----------------------------------------------------------------------
BM_Jacobian                         630073 ns     630072 ns       1139
BM_BodyJacobian                     624435 ns     624419 ns       1116
BM_VectorBodyJacobian               553798 ns     553783 ns       1251
BM_JacobianDot                     1376488 ns    1376455 ns        480
BM_BodyJacobianDot                  784997 ns     785007 ns        907
BM_CoMJacobianDummy_jacobian      12414945 ns   12415053 ns         58
BM_CoMJacobianDummy_jacobianDot   28658158 ns   28657513 ns         25
BM_CoMJacobian_jacobian            7278504 ns    7278598 ns        100
BM_CoMJacobian_jacobianDot        25179734 ns   25179918 ns         27
BM_MomentumJacobian_jacobian      15659580 ns   15659255 ns         46
BM_MomentumJacobian_jacobianDot   33959479 ns   33959901 ns         21

And in Release:

Run on (8 X 3800 MHz CPU s)
2019-03-19 14:39:50
-----------------------------------------------------------------------
Benchmark                                Time           CPU Iterations
-----------------------------------------------------------------------
BM_Jacobian                            601 ns        601 ns    1189074
BM_BodyJacobian                        595 ns        595 ns    1172540
BM_VectorBodyJacobian                  513 ns        513 ns    1364122
BM_JacobianDot                        1282 ns       1282 ns     550505
BM_BodyJacobianDot                     736 ns        736 ns     838521
BM_CoMJacobianDummy_jacobian         22661 ns      22661 ns      31956
BM_CoMJacobianDummy_jacobianDot      36005 ns      36006 ns      19162
BM_CoMJacobian_jacobian               7971 ns       7971 ns      88051
BM_CoMJacobian_jacobianDot           23498 ns      23498 ns      30547
BM_MomentumJacobian_jacobian         28845 ns      28846 ns      25047
BM_MomentumJacobian_jacobianDot      59836 ns      59836 ns      12033
oofrivia commented 5 years ago

thank you very much @gergondet ~ I get a drastically speed up after using the flag above. Now it's both convenient and has high performance.

gergondet commented 5 years ago

@zisang that's great!

We have notice that the CMAKE_BUIlD_TYPE typo was also in the README file so we fixed it.

Closing the issue.