Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(biorbd_holonomic_model) #847

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions bioptim/models/biorbd/biorbd_model.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from typing import Callable, Any

import biorbd_casadi as biorbd
import numpy as np
from biorbd_casadi import (
GeneralizedCoordinates,
GeneralizedVelocity,
GeneralizedTorque,
GeneralizedAcceleration,
)
from casadi import SX, MX, vertcat, horzcat, norm_fro
import numpy as np

from ..utils import _var_mapping, bounds_from_ranges
from ...limits.path_conditions import Bounds
from ...misc.utils import check_version
from ...misc.mapping import BiMapping, BiMappingList
from ..utils import _var_mapping, bounds_from_ranges
from ...misc.utils import check_version

check_version(biorbd, "1.10.0", "1.11.0")

Expand Down Expand Up @@ -727,17 +728,17 @@ def animate(

all_bioviz = []
for idx_phase, data in enumerate(states):
if not isinstance(solution.ocp.nlp[idx_phase].model, BiorbdModel):
if not isinstance(ocp.nlp[idx_phase].model, BiorbdModel):
raise NotImplementedError("Animation is only implemented for biorbd models")

# This calls each of the function that modify the internal dynamic model based on the parameters
nlp = solution.ocp.nlp[idx_phase]
nlp = ocp.nlp[idx_phase]

# noinspection PyTypeChecker
biorbd_model: BiorbdModel = nlp.model

all_bioviz.append(bioviz.Viz(biorbd_model.path, **kwargs))
all_bioviz[-1].load_movement(solution.ocp.nlp[idx_phase].variable_mappings["q"].to_second.map(data["q"]))
all_bioviz[-1].load_movement(ocp.nlp[idx_phase].variable_mappings["q"].to_second.map(solution["q"]))

if "q_roots" in solution and "q_joints" in solution:
# TODO: Fix the mapping for this case
Expand Down
9 changes: 8 additions & 1 deletion bioptim/models/biorbd/holonomic_biorbd_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
)
from casadi import MX, DM, vertcat, horzcat, Function, solve, rootfinder, inv

from ..holonomic_constraints import HolonomicConstraintsList
from .biorbd_model import BiorbdModel
from ..holonomic_constraints import HolonomicConstraintsList


class HolonomicBiorbdModel(BiorbdModel):
Expand Down Expand Up @@ -277,6 +277,8 @@ def partitioned_forward_dynamics(

def coupling_matrix(self, q: MX) -> MX:
"""
Also denoted as Bvu in the literature.

Sources
-------
Docquier, N., Poncelet, A., and Fisette, P.:
Expand Down Expand Up @@ -325,6 +327,11 @@ def state_from_partition(self, state_u: MX, state_v: MX) -> MX:
return q

def compute_q_v(self, q_u: MX | DM, q_v_init: MX | DM = None) -> MX | DM:
"""
Compute the dependent joint positions from the independent joint positions.
This function might be misleading because it can be used for numerical purpose with DM
or for symbolic purpose with MX. The return type is not enforced.
"""
decision_variables = MX.sym("decision_variables", self.nb_dependent_joints)
q = self.state_from_partition(q_u, decision_variables)
mx_residuals = self.holonomic_constraints(q)
Expand Down
Loading