andreadelprete / consim

GNU General Public License v3.0
14 stars 1 forks source link

Accuracy of the Euler integration #23

Closed jcarpent closed 4 years ago

jcarpent commented 4 years ago

These lines of code perform a classic first-order Euler integration step

https://github.com/andreadelprete/consim/blob/c1d6b07ca4a7ae8ef64e70531ac32addd6fd8f4c/src/simulator.cpp#L237-L240

I was wondering why to not use a more stable approach based on Euler semi-implicit, namely:

 v_ += dv_ * sub_dt; 
 pinocchio::integrate(*model_, q_, v_ * sub_dt, qnext_); 
 q_ = qnext_; 

This would lead to a second-order accuracy.

andreadelprete commented 4 years ago

Interesting, I didn't know this semi-implicit scheme was second order. If you have a reference at hand that explains why I'd love to take a look. Otherwise I'm gonna look for one by myself.

jcarpent commented 4 years ago

I was incorrect when saying second-order, but this method is much more stable in the sense that it preserves the mechanical energy of the system. See https://en.wikipedia.org/wiki/Semi-implicit_Euler_method for more details. Euler explicit has very bad behavior with this aspect.

andreadelprete commented 4 years ago

Hello @jcarpent I've implemented semi-implicit Euler and tested it on the quadruped jumping motion. Surprisingly it doesn't do better than explicit Euler. Here the mean infinity norm of the local integration error: jump_dt_10ms_semi_implicit_euler_mean_inf_norm

Semi-implicit Euler performs a bit better than explicit Euler for dt=10 ms, but in all other cases it does a bit worse than explicit Euler, and for one case the error goes out of the chart. For small time steps (<=0.3 ms), the error seems to be basically the same as for explicit Euler.

andreadelprete commented 4 years ago

Given these results, it doesn't seem worth it to use semi-implicit Euler, so I am going to close this issue for now.