dojo-sim / Dojo.jl

A differentiable physics engine for robotics
MIT License
309 stars 27 forks source link

API for getting the gradients with respect to model parameters #44

Open ChiyenLee opened 2 years ago

ChiyenLee commented 2 years ago

Is there a way to get access to gradients with respect to a mechanism's model parameters like inertia, mass, and center of mass?

simon-lc commented 2 years ago

Yes there is a way to do this. This file computes the the gradient of the residual wrt to the mechanism data = (previous state, control input, mass inertia, etc).

https://github.com/dojo-sim/Dojo.jl/blob/main/src/gradients/data.jl

simon-lc commented 2 years ago

then to get the gradient of the next state wrt to the mass, inertia. You'll need to implement something like get_maximal_gradients https://github.com/dojo-sim/Dojo.jl/blob/main/src/gradients/state.jl

this means using the Iplicit function theorem i.e. computing d next_state/ d data = -d residual /d next_state ^-1 * d residual / d data

simon-lc commented 2 years ago

I can help you set this up if you want to work on this!

zpatty commented 2 years ago

+1 on this as a desired feature. I'd be willing to help set it up in my spare time.