7 import pinocchio
as pin
15 joint_placement = pin.SE3.Identity()
19 shape0 = fcl.Sphere(body_radius)
21 geom0_obj.meshColor = np.array([1.0, 0.1, 0.1, 1.0])
22 geom_model.addGeometryObject(geom0_obj)
25 joint_name =
"joint_" + str(k + 1)
26 joint_id = model.addJoint(
30 body_inertia = pin.Inertia.FromSphere(body_mass, body_radius)
31 body_placement = joint_placement.copy()
32 body_placement.translation[2] = 1.0
33 model.appendBodyToJoint(joint_id, body_inertia, body_placement)
35 geom1_name =
"ball_" + str(k + 1)
36 shape1 = fcl.Sphere(body_radius)
38 geom1_obj.meshColor = np.ones(4)
39 geom_model.addGeometryObject(geom1_obj)
41 geom2_name =
"bar_" + str(k + 1)
42 shape2 = fcl.Cylinder(body_radius / 4.0, body_placement.translation[2])
43 shape2_placement = body_placement.copy()
44 shape2_placement.translation[2] /= 2.0
47 geom2_obj.meshColor = np.array([0.0, 0.0, 0.0, 1.0])
48 geom_model.addGeometryObject(geom2_obj)
51 joint_placement = body_placement.copy()
54 visual_model = geom_model
60 except ImportError
as err:
62 "Error while initializing the viewer. "
63 "It seems you should install gepetto-viewer"
69 viz.loadViewerModel(
"pinocchio")
70 except AttributeError
as err:
72 "Error while loading the viewer model. "
73 "It seems you should start gepetto-viewer"
86 N = math.floor(T / dt)
88 model.lowerPositionLimit.fill(-math.pi)
89 model.upperPositionLimit.fill(+math.pi)
91 v = np.zeros(model.nv)
94 data_sim = model.createData()
96 tau_control = np.zeros(model.nv)
97 a =
pin.aba(model, data_sim, q, v, tau_control)