5 import pinocchio
as pin
6 pin.switchToNumpyMatrix()
14 m = pin.SE3.Identity()
15 m.translation = np.matrix([[float(i)]
for i
in [x, y, z]])
16 m.rotation *=
rotate(
'x', rx)
17 m.rotation *=
rotate(
'y', ry)
18 m.rotation *=
rotate(
'z', rz)
23 return [int(i)
for i
in '%03d' % int(bin(body_number % 8)[2:])] + [1]
28 self.
visuals = [(
'universe', pin.SE3.Identity(), pin.SE3.Identity().translation)]
29 self.
name = self.__class__.__name__
if name
is None else name
35 for joint
in self.joints:
38 def add_joint(self, joint_name, joint_model=None, joint_placement=None, lever=None, shape="box",
39 dimensions=1, mass=
None, body_color=1, parent=0):
40 if joint_model
is None:
41 joint_model = pin.JointModelFreeFlyer()
42 elif isinstance(joint_model, str):
43 joint_model = pin.__dict__[
'JointModel' + joint_model]()
44 if joint_placement
is None:
45 joint_placement = pin.SE3.Identity()
46 elif isinstance(joint_placement, dict):
47 joint_placement =
placement(**joint_placement)
49 lever = pin.SE3.Identity()
50 elif isinstance(lever, dict):
52 joint_name, body_name = (
'world/%s_%s_%s' % (self.
name, joint_name, i)
for i
in (
'joint',
'body'))
53 body_inertia = pin.Inertia.Random()
55 w, h, d = (float(i)
for i
in dimensions)
if isinstance(dimensions, tuple)
else [float(dimensions)] * 3
57 mass = w * h * d * DENSITY
58 body_inertia = pin.Inertia.FromBox(mass, w, h, d)
60 self.display.viewer.gui.addBox(body_name, w, h, d,
color(body_color))
61 elif shape ==
"cylinder":
64 mass = pi * r ** 2 * h * DENSITY
65 body_inertia = pin.Inertia.FromCylinder(mass, r, h)
67 self.display.viewer.gui.addCylinder(body_name, r, h,
color(body_color))
68 elif shape ==
"sphere":
69 w, h, d = (float(i)
for i
in dimensions)
if isinstance(dimensions, tuple)
else [float(dimensions)] * 3
71 mass = 4. / 3. * pi * w * h * d * DENSITY
72 body_inertia = pin.Inertia.FromEllipsoid(mass, w, h, d)
74 self.display.viewer.gui.addSphere(body_name, dimensions,
color(body_color))
75 body_inertia.lever = lever.translation
76 joint_id = self.model.addJoint(parent, joint_model, joint_placement, joint_name)
77 self.model.appendBodyToJoint(joint_id, body_inertia, pin.SE3.Identity())
78 self.model.addJointFrame(joint_id, -1)
79 self.model.addBodyFrame(body_name, joint_id, pin.SE3.Identity(),-1)
80 self.visuals.append((body_name, joint_placement, lever))
81 self.
data = self.model.createData()
86 for i, (name, placement, lever)
in enumerate(self.
visuals):
89 self.display.place(name, self.data.oMi[i] * placement * lever)
90 self.display.viewer.gui.refresh()
95 from gepetto
import corbaserver
99 window_id = self.viewer.gui.getWindowID(window_name)
101 window_id = self.viewer.gui.createWindow(window_name)
102 self.viewer.gui.createSceneWithFloor(
"world")
103 self.viewer.gui.addSceneToWindow(
"world", window_id)
104 self.viewer.gui.setLightingMode(
'world',
'OFF')
105 self.viewer.gui.setVisibility(
'world/floor',
"OFF")
106 self.viewer.gui.refresh()
109 self.viewer.gui.applyConfiguration(obj_name,pin.se3ToXYZQUATtuple(m))
114 {
'joint_name':
"pelvis",
115 'dimensions': (.1, .2, .1),
118 {
'joint_name':
"left_leg",
120 'joint_placement': {
'y': -.15},
121 'lever': {
'z': -.45},
123 'dimensions': (.1, .9),
128 {
'joint_name':
"right_leg",
130 'joint_placement': {
'y': .15},
131 'lever': {
'z': -.45},
133 'dimensions': (.1, .9),
Eigen::Matrix3d rotate(const std::string &axis, const double ang)
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")