Simple-Robotics / aligator

A versatile and efficient framework for constrained trajectory optimization
https://simple-robotics.github.io/aligator/
BSD 2-Clause "Simplified" License
106 stars 15 forks source link

Fix dynamics unittests involving finite difference function #128

Closed edantec closed 7 months ago

edantec commented 7 months ago

This PR aims at solving issue https://github.com/Simple-Robotics/aligator/issues/127#issue-2131916127 about an error in the finite difference python function used in unittest. It also adds some missing unittest for MultibodyFreeFwdDynamics derivatives.

ManifoldFR commented 7 months ago

I'm working on this PR at the moment

ManifoldFR commented 7 months ago

The error in the Jx Jacobian of the multibody free fwd dynamics gives something like this (in log-scale, white means 0)

Figure_1

I set $\epsilon = 10^{-6}$ here. Not sure where the problem comes from.

I changed some things such as passing the $\epsilon$ finite-difference parameter to finite_diff

ManifoldFR commented 7 months ago

Setting

x0 = space.rand()
x0[:3] = 0.

Did increase the residual. I think there's some kind of high-frequency component that 1st-order finite differences just can't capture.

Figure_1

ManifoldFR commented 7 months ago

We'll be switching to centered finite differences then. I'll also be scaling $\epsilon$ in the finite differences by the norms of x and u.

I restored $\epsilon$ to 1e-6.

ManifoldFR commented 7 months ago

For further reference, here's what Crocoddyl does:

@jorisv would you agree with the state of this PR? @edantec do you agree with my analysis of Crocoddyl's behaviour?

edantec commented 7 months ago

Looks good to me!

jorisv commented 7 months ago

@ManifoldFR We can also look at the 5 points finite difference made in roboptim

It's maybe more precise and the code estimate the truncation error and the rounding error.

ManifoldFR commented 7 months ago

@ManifoldFR We can also look at the 5 points finite difference made in roboptim

It's maybe more precise and the code estimate the truncation error and the rounding error.

That must be very accurate, wow