From 6c7c476023a31da1e7b612c4e557d5de73aefdad Mon Sep 17 00:00:00 2001 From: diegoferigo Date: Tue, 21 May 2024 17:32:21 +0200 Subject: [PATCH] Make sure the link names and frame names are unique --- src/jaxsim/parsers/kinematic_graph.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/jaxsim/parsers/kinematic_graph.py b/src/jaxsim/parsers/kinematic_graph.py index 6bd6bb240..046164b8d 100644 --- a/src/jaxsim/parsers/kinematic_graph.py +++ b/src/jaxsim/parsers/kinematic_graph.py @@ -98,6 +98,15 @@ def __post_init__(self) -> None: for index, link in enumerate(self): link.mutable(validate=False).index = index + # Get the names of the links and frames. + link_names = [l.name for l in self] + frame_names = [f.name for f in self.frames] + + # Make sure that they are unique. + assert len(link_names) == len(set(link_names)) + assert len(frame_names) == len(set(frame_names)) + assert set(link_names).isdisjoint(set(frame_names)) + # Order frames with their name. super().__setattr__("frames", sorted(self.frames, key=lambda f: f.name))