stack-of-tasks / pinocchio

A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
http://stack-of-tasks.github.io/pinocchio/
BSD 2-Clause "Simplified" License
1.89k stars 392 forks source link

Error with buildReducedModel #2313

Open stephane-caron opened 4 months ago

stephane-caron commented 4 months ago

I can reproduce the issue from the discussion below using this minimal example:

from robot_descriptions.loaders.pinocchio import load_robot_description

robot = load_robot_description("baxter_description")
reduced_model = pin.buildReducedModel(robot.model, [], robot.q0)

It seems related to the Baxter description (if we replace baxter_description with e.g. upkie_description, then buildReducedModel returns normally).

Discussed in https://github.com/stack-of-tasks/pinocchio/discussions/2311

Originally posted by **maymohan** July 2, 2024 Hello, I recently started using Pinocchio and am interested in building a reduced model for a single arm of a Baxter robot. I followed the example in the wiki. But, I get the following error: ` ValueError: Several frames match the filter - please specify the FrameType ` Here is a minimum working example of my code: ``` import pinocchio as pin import numpy as np # Build the model pinocchio_model_dir = "./models/" mesh_dir = pinocchio_model_dir urdf_filename = ("./baxter.urdf") # Load the urdf model model, collision_model, visual_model = pin.buildModelsFromUrdf(urdf_filename, mesh_dir) # Build the reduced model relevantJoints = ['right_s0', 'right_s1', 'right_e0', 'right_e1', 'right_w0', 'right_w1', 'right_w2'] jointsToLockIDs = [] initialJointConfig = np.array([0, #head 0, 0,0, 0.1,0,0,0, # Left arm 0, 0,0, 0.1,0,0,0 ])# Right arm for name in model.names: if not name in relevantJoints: if model.existJointName(name): jointsToLockIDs.append(model.getFrameId(name)) else: print('Warning: joint ' + str(name) + ' does not belong to the model!') model_reduced = pin.buildReducedModel(model, visual_model, jointsToLockIDs, initialJointConfig) ``` Here is [Baxter's URDF](https://github.com/RethinkRobotics/baxter_common/blob/master/baxter_description/urdf/baxter.urdf). I looked around quite a bit and could not find anyway to resolve the issue. I would appreciate any help in resolving the issue. Please let me know if I can provide any other information. Thank you for your help!
Zionshang commented 3 months ago

I haven't looked at your URDF file in detail, but it's probably because some names of joint in the URDF are same as some names of link. You need to check the urdf in detail.

maymohan commented 3 months ago

@Zionshang You were right!

In case anyone else has the same issue, I changed the joint names of the following joints by adding the suffix "_fixed": head_camera, right_hand, right_hand_camera, right_hand_camera_axis, right_hand_range, right_hand_accelerometer, right_gripper_base, left_hand, left_hand_camera, left_hand_camera_axis, left_hand_range, left_hand_accelerometer, left_gripper_base.

My modified URDF file can be found on my fork of the Rethink SDK.