From 54f38859cc3b610d1ba6172d8e9ea4ca7b2b7ce8 Mon Sep 17 00:00:00 2001 From: Ipuch Date: Fri, 16 Feb 2024 10:11:53 -0500 Subject: [PATCH 1/2] doc(biorbd_holonomic_model) --- bioptim/models/biorbd/holonomic_biorbd_model.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bioptim/models/biorbd/holonomic_biorbd_model.py b/bioptim/models/biorbd/holonomic_biorbd_model.py index 647e82fc8..f94d73535 100644 --- a/bioptim/models/biorbd/holonomic_biorbd_model.py +++ b/bioptim/models/biorbd/holonomic_biorbd_model.py @@ -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): @@ -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.: @@ -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) From bd5ce92a6f161f31d803dd577bb6da1f5d70afc3 Mon Sep 17 00:00:00 2001 From: Ipuch Date: Mon, 19 Feb 2024 10:56:14 -0500 Subject: [PATCH 2/2] restoring animation --- bioptim/models/biorbd/biorbd_model.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bioptim/models/biorbd/biorbd_model.py b/bioptim/models/biorbd/biorbd_model.py index a87c9b992..cb7ff8265 100644 --- a/bioptim/models/biorbd/biorbd_model.py +++ b/bioptim/models/biorbd/biorbd_model.py @@ -1,6 +1,7 @@ from typing import Callable, Any import biorbd_casadi as biorbd +import numpy as np from biorbd_casadi import ( GeneralizedCoordinates, GeneralizedVelocity, @@ -8,11 +9,11 @@ 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") @@ -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