5 import pinocchio
as pin
9 from os.path import dirname, join, abspath
15 pinocchio_model_dir = join(dirname(dirname(str(abspath(__file__)))),
"models")
17 model_path = join(pinocchio_model_dir,
"example-robot-data/robots")
18 mesh_dir = pinocchio_model_dir
21 urdf_filename =
"solo.urdf" 22 urdf_model_path = join(join(model_path,
"solo_description/robots"), urdf_filename)
24 model, collision_model, visual_model = pin.buildModelsFromUrdf(
25 urdf_model_path, mesh_dir, pin.JointModelFreeFlyer()
37 viz.initViewer(open=
True)
38 except ImportError
as err:
40 "Error while initializing the viewer. It seems you should install Python meshcat" 49 q0 = pin.neutral(model)
51 viz.displayCollisions(
True)
52 viz.displayVisuals(
False)
54 mesh = visual_model.geometryObjects[0].geometry
55 mesh.buildConvexRepresentation(
True)
58 if convex
is not None:
59 placement = pin.SE3.Identity()
60 placement.translation[0] = 2.0
61 geometry = pin.GeometryObject(
"convex", 0, convex, placement)
62 geometry.meshColor = np.ones((4))
63 visual_model.addGeometryObject(geometry)
67 viz2.initViewer(viz.viewer)
68 viz2.loadViewerModel(rootNodeName=
"pinocchio2")
75 [0.0, 0.0, 0.235, 0.0, 0.0, 0.0, 1.0, 0.8, -1.6, 0.8, -1.6, -0.8, 1.6, -0.8, 1.6]
78 v0 = np.random.randn(model.nv) * 2
80 pin.forwardKinematics(model, data, q1, v0)
81 frame_id = model.getFrameId(
"HR_FOOT")
83 viz.drawFrameVelocities(frame_id=frame_id)
85 model.gravity.linear[:] = 0.0
90 tau0 = np.zeros(model.nv)
94 for i
in range(nsteps):
97 a1 = pin.aba(model, data, q, v, tau0)
99 qnext = pin.integrate(model, q, dt * vnext)
103 viz.drawFrameVelocities(frame_id=frame_id)
109 fid2 = model.getFrameId(
"FL_FOOT")
113 viz.drawFrameVelocities(frame_id)
114 viz.drawFrameVelocities(fid2)
117 with viz.create_video_ctx(
"../leap.mp4"):
118 viz.play(qs, dt, callback=my_callback)