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

[RTM] Added contact_index for bioptim #361

Merged
merged 3 commits into from
Feb 26, 2025
Merged
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
24 changes: 23 additions & 1 deletion binding/python3/rigid_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ def marker_index(model, marker_name: str) -> int:
except ValueError:
raise ValueError(f"{marker_name} is not in the biorbd model")

def contact_index(model, contact_name: str) -> int:
"""
Return the index in the model of the desired contact point.
A ValueError is raised if the marker is not in the model

Parameters
----------
model: biorbd.Model
The biorbd model
contact_name: str
The name of the contact to get the index from
Returns
-------
The index of the contact.
"""

try:
return [n.to_string() for n in model.contactNames()].index(contact_name)
except ValueError:
raise ValueError(f"{contact_name} is not in the biorbd model")

def segment_index(model, segment_name):
"""
Expand Down Expand Up @@ -104,7 +124,7 @@ def extended_kalman_filter(

index_in_c3d = np.array(tuple(labels.index(name) if name in labels else -1 for name in marker_names))
markers_in_c3d = np.ndarray((3, len(index_in_c3d), n_frames)) * np.nan
markers_in_c3d[:, index_in_c3d >= 0, :] = data[:3, index_in_c3d[index_in_c3d >= 0], frames] / 1000 # To meter
markers_in_c3d[:, index_in_c3d[index_in_c3d >= 0], :] = data[:3, index_in_c3d[index_in_c3d >= 0], frames] / 1000 # To meter

# Create a Kalman filter structure
freq = c3d["parameters"]["POINT"]["RATE"]["value"][0]
Expand Down Expand Up @@ -339,6 +359,8 @@ def solve(self, method: str = "lm"):
raise ValueError('This method is not implemented please use "trf", "lm" or "only_lm" as argument')

for f in range(self.nb_frames):
if f % 100 == 0:
print(f"Frame {f}/{self.nb_frames}")
if initial_method != "lm":
x0 = (
np.array(
Expand Down
Loading