5 import pinocchio
as pin
13 m = pin.SE3.Identity()
14 m.translation = np.array([x, y, z])
15 m.rotation *= rotate(
'x', rx)
16 m.rotation *= rotate(
'y', ry)
17 m.rotation *= rotate(
'z', rz)
22 return [int(i)
for i
in '%03d' % int(bin(body_number % 8)[2:])] + [1]
27 self.
visuals = [(
'universe', pin.SE3.Identity(), pin.SE3.Identity().translation)]
28 self.
name = self.__class__.__name__
if name
is None else name
34 for joint
in self.joints:
37 def add_joint(self, joint_name, joint_model=None, joint_placement=None, lever=None, shape="box",
38 dimensions=1, mass=None, body_color=1, parent=0):
39 if joint_model
is None:
40 joint_model = pin.JointModelFreeFlyer()
41 elif isinstance(joint_model, str):
42 joint_model = pin.__dict__[
'JointModel' + joint_model]()
43 if joint_placement
is None:
44 joint_placement = pin.SE3.Identity()
45 elif isinstance(joint_placement, dict):
46 joint_placement =
placement(**joint_placement)
48 lever = pin.SE3.Identity()
49 elif isinstance(lever, dict):
51 joint_name, body_name = (
'world/%s_%s_%s' % (self.
name, joint_name, i)
for i
in (
'joint',
'body'))
52 body_inertia = pin.Inertia.Random()
54 w, h, d = (float(i)
for i
in dimensions)
if isinstance(dimensions, tuple)
else [float(dimensions)] * 3
56 mass = w * h * d * DENSITY
57 body_inertia = pin.Inertia.FromBox(mass, w, h, d)
59 self.
display.viewer.gui.addBox(body_name, w, h, d,
color(body_color))
60 elif shape ==
"cylinder":
63 mass = pi * r ** 2 * h * DENSITY
64 body_inertia = pin.Inertia.FromCylinder(mass, r, h)
66 self.
display.viewer.gui.addCylinder(body_name, r, h,
color(body_color))
67 elif shape ==
"sphere":
68 w, h, d = (float(i)
for i
in dimensions)
if isinstance(dimensions, tuple)
else [float(dimensions)] * 3
70 mass = 4. / 3. * pi * w * h * d * DENSITY
71 body_inertia = pin.Inertia.FromEllipsoid(mass, w, h, d)
73 self.
display.viewer.gui.addSphere(body_name, dimensions,
color(body_color))
74 body_inertia.lever = lever.translation
75 joint_id = self.
model.addJoint(parent, joint_model, joint_placement, joint_name)
76 self.
model.appendBodyToJoint(joint_id, body_inertia, pin.SE3.Identity())
77 self.
model.addJointFrame(joint_id, -1)
78 self.
model.addBodyFrame(body_name, joint_id, pin.SE3.Identity(),-1)
85 for i, (name, placement, lever)
in enumerate(self.
visuals):
89 self.
display.viewer.gui.refresh()
94 from gepetto
import corbaserver
98 window_id = self.
viewer.gui.getWindowID(window_name)
100 window_id = self.
viewer.gui.createWindow(window_name)
101 self.
viewer.gui.createSceneWithFloor(
"world")
102 self.
viewer.gui.addSceneToWindow(
"world", window_id)
103 self.
viewer.gui.setLightingMode(
'world',
'OFF')
104 self.
viewer.gui.setVisibility(
'world/floor',
"OFF")
108 self.
viewer.gui.applyConfiguration(obj_name,pin.se3ToXYZQUATtuple(m))
113 {
'joint_name':
"pelvis",
114 'dimensions': (.1, .2, .1),
117 {
'joint_name':
"left_leg",
119 'joint_placement': {
'y': -.15},
120 'lever': {
'z': -.45},
122 'dimensions': (.1, .9),
127 {
'joint_name':
"right_leg",
129 'joint_placement': {
'y': .15},
130 'lever': {
'z': -.45},
132 'dimensions': (.1, .9),
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
def placement(x=0, y=0, z=0, rx=0, ry=0, rz=0)
def add_joint(self, joint_name, joint_model=None, joint_placement=None, lever=None, shape="box", dimensions=1, mass=None, body_color=1, parent=0)
def __init__(self, name=None, display=False)
def place(self, obj_name, m)
def __init__(self, window_name="pinocchio")