4 from pathlib
import Path
8 import pinocchio
as pin
12 pinocchio_model_dir = Path(__file__).parent.parent /
"models"
14 model_path = pinocchio_model_dir /
"example-robot-data/robots"
15 mesh_dir = pinocchio_model_dir
16 urdf_filename =
"ur5_robot.urdf"
17 urdf_model_path = model_path /
"ur_description/urdf" / urdf_filename
19 model1, collision_model1, visual_model1 = pin.buildModelsFromUrdf(
20 urdf_model_path, package_dirs=mesh_dir
25 model2.name =
"pendulum"
26 geom_model = pin.GeometryModel()
29 joint_placement = pin.SE3.Identity()
33 joint_name =
"joint_spherical"
34 joint_id = model2.addJoint(
35 parent_id, pin.JointModelSpherical(), joint_placement, joint_name
38 body_inertia = pin.Inertia.FromSphere(body_mass, body_radius)
39 body_placement = joint_placement.copy()
40 body_placement.translation[2] = 0.1
41 model2.appendBodyToJoint(joint_id, body_inertia, body_placement)
44 shape1 = fcl.Sphere(body_radius)
45 geom1_obj = pin.GeometryObject(geom1_name, joint_id, body_placement, shape1)
46 geom1_obj.meshColor = np.ones(4)
47 geom_model.addGeometryObject(geom1_obj)
50 shape2 = fcl.Cylinder(body_radius / 4.0, body_placement.translation[2])
51 shape2_placement = body_placement.copy()
52 shape2_placement.translation[2] /= 2.0
54 geom2_obj = pin.GeometryObject(geom2_name, joint_id, shape2_placement, shape2)
55 geom2_obj.meshColor = np.array([0.0, 0.0, 0.0, 1.0])
56 geom_model.addGeometryObject(geom2_obj)
58 visual_model2 = geom_model
61 frame_id_end_effector = model1.getFrameId(
"tool0")
62 model, visual_model = pin.appendModel(
67 frame_id_end_effector,
72 f
"Check the joints of the appended model:\n {model} \n "
73 "->Notice the spherical joint at the end."
77 viz = Visualizer(model, visual_model, visual_model)
78 viz.initViewer(open=
True)
79 except ImportError
as err:
81 "Error while initializing the viewer. "
82 "It seems you should install Python meshcat"
91 model.lowerPositionLimit.fill(-math.pi / 2)
92 model.upperPositionLimit.fill(+math.pi / 2)
93 q = pin.randomConfiguration(model)