-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add rollout with custom integrator * fix: correct rk4 implementation * chore: rename * chore: typo * feat: implement manifold rk4 * fix: update comparison * feat: add controls to rollout
- Loading branch information
Showing
13 changed files
with
661 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Module for various integrators""" | ||
from .base import Integrator | ||
from .fwd_euler import ForwardEuler | ||
from .rk4 import RK4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Module for base class of integrators""" | ||
|
||
from abc import ABC, abstractstaticmethod | ||
from ..base import StateSpaceBase | ||
from ...arrays import ArrayLike | ||
import casadi as cs | ||
|
||
|
||
class Integrator(ABC): | ||
@abstractstaticmethod | ||
def forward( | ||
state_space: StateSpaceBase, | ||
x0: ArrayLike, | ||
qfrc_u: ArrayLike, | ||
dt: float | cs.SX, | ||
) -> ArrayLike: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Module for forward euler integrator""" | ||
from .base import Integrator, StateSpaceBase, ArrayLike, cs | ||
|
||
|
||
class ForwardEuler(Integrator): | ||
@staticmethod | ||
def forward( | ||
state_space: StateSpaceBase, | ||
x0: ArrayLike, | ||
qfrc_u: ArrayLike, | ||
dt: cs.SX | float, | ||
): | ||
nq = state_space.model.nq | ||
nv = state_space.model.nv | ||
|
||
q, v = x0[:nq], x0[nq:] | ||
vdot = state_space.model.forward_dynamics(q, v, qfrc_u) | ||
|
||
# forward euler to integrate velocity | ||
integrated_v = v + dt * vdot | ||
|
||
# pinocchio fancy lie-group integration | ||
integrated_q = state_space.model.backend.integrate_configuration( | ||
dt, q, integrated_v | ||
) | ||
|
||
container = state_space.model.backend.math.zeros(nq + nv).array | ||
container[:nq] = integrated_q | ||
container[nq:] = integrated_v | ||
|
||
return container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Module for RK4 integrator""" | ||
from .base import Integrator, StateSpaceBase, ArrayLike, cs | ||
|
||
|
||
class RK4(Integrator): | ||
@staticmethod | ||
def forward( | ||
state_space: StateSpaceBase, | ||
x0: ArrayLike, | ||
qfrc_u: ArrayLike, | ||
h: cs.SX | float, | ||
): | ||
nq = state_space.model.nq | ||
nv = state_space.model.nv | ||
|
||
def tangent_int(x, tang_x): | ||
"""tangent integration of state by its increment""" | ||
|
||
# simplify notation for integration on manifold | ||
manifold_int = state_space.model.backend.integrate_configuration | ||
|
||
container = state_space.model.backend.math.zeros(nq + nv) | ||
|
||
# configuration is integrated on manifold using pinocchio implementation | ||
container[:nq] = manifold_int(h, x[:nq], tang_x[nv:]) | ||
|
||
# velocity and acceleration are in the same space and do not require specific treatment | ||
container[nq:] = x[nq:] + h * tang_x[nv:] | ||
|
||
return container.array | ||
|
||
k1 = state_space.derivative(x0[:nq], x0[nq:], qfrc_u) | ||
|
||
k2_ = tangent_int(x0, 0.5 * h * k1) | ||
k2 = state_space.derivative(k2_[:nq], k2_[nq:], qfrc_u) | ||
|
||
k3_ = tangent_int(x0, 0.5 * h * k2) | ||
k3 = state_space.derivative(k3_[:nq], k3_[nq:], qfrc_u) | ||
|
||
k4_ = tangent_int(x0, h * k3) | ||
k4 = state_space.derivative(k4_[:nq], k4_[nq:], qfrc_u) | ||
|
||
return tangent_int(x0, (h / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.