@@ -57,16 +57,42 @@ def check_if_model_exist(folder_path, model):
5757 path = folder_path / Path (model )
5858 return path .is_dir ()
5959
60+ # Find the index of the model joints in the considered joints
61+ # This function is required if some of the considered joints are not in the model
62+ # For instance in underactuated robots
63+ def find_model_joints (model_name , considered_joints ):
64+ ml = idyn .ModelLoader ()
65+ ml .loadModelFromFile (model_name )
66+ model_joints_index = []
67+ model = ml .model ()
68+ number_of_joints = model .getNrOfJoints ()
69+ for i in range (number_of_joints ):
70+ joint_name = model .getJointName (i )
71+ if joint_name in considered_joints :
72+ # find the index of the joint in the considered joints
73+ index = considered_joints .index (joint_name )
74+ model_joints_index .append (index )
75+
76+ return model_joints_index
77+
6078 self ._is_model_loaded = False
6179
6280 # Load the model
6381 model_loader = idyn .ModelLoader ()
6482
83+ self .model_joints_index = []
6584 # In this case the user specify the model path
6685 if self .custom_model_path :
86+ self .model_joints_index = find_model_joints (
87+ self .custom_model_path , considered_joints
88+ )
89+ considered_model_joints = [
90+ considered_joints [i ] for i in self .model_joints_index
91+ ]
92+
6793 model_loader .loadReducedModelFromFile (
6894 self .custom_model_path ,
69- considered_joints ,
95+ considered_model_joints ,
7096 "urdf" ,
7197 [self .custom_package_dir ],
7298 )
@@ -93,9 +119,15 @@ def check_if_model_exist(folder_path, model):
93119 if not model_found_in_env_folders :
94120 return False
95121
96- model_loader . loadReducedModelFromFile (
122+ self . model_joints_index = find_model_joints (
97123 self .custom_model_path , considered_joints
98124 )
125+ considered_model_joints = [
126+ considered_joints [i ] for i in self .model_joints_index
127+ ]
128+ model_loader .loadReducedModelFromFile (
129+ self .custom_model_path , considered_model_joints
130+ )
99131
100132 if not model_loader .isValid ():
101133 return False
@@ -124,7 +156,9 @@ def run(self):
124156 self .meshcat_visualizer .set_multibody_system_state (
125157 base_position ,
126158 base_rotation ,
127- joint_value = joints [self ._signal_provider .index , :],
159+ joint_value = joints [
160+ self ._signal_provider .index , self .model_joints_index
161+ ],
128162 model_name = "robot" ,
129163 )
130164
0 commit comments