4 import pinocchio
as pin
6 from test_case
import PinocchioTestCase
as TestCase
11 self.
model = pin.buildSampleModelHumanoidRandom()
14 qmax = np.full((self.
model.nq, 1), np.pi)
15 self.
q = pin.randomConfiguration(self.
model, -qmax, qmax)
18 mass = pin.computeTotalMass(self.
model)
19 self.assertIsNot(mass, np.nan)
21 mass_check = sum([inertia.mass
for inertia
in self.
model.inertias[1:]])
22 self.assertApprox(mass, mass_check)
24 mass_data = pin.computeTotalMass(self.
model, self.
data)
25 self.assertIsNot(mass_data, np.nan)
26 self.assertApprox(mass, mass_data)
27 self.assertApprox(mass_data, self.
data.mass[0])
30 pin.centerOfMass(self.
model, data2, self.
q)
31 self.assertApprox(mass, data2.mass[0])
34 pin.computeSubtreeMasses(self.
model, self.
data)
37 pin.centerOfMass(self.
model, data2, self.
q)
39 for i
in range(self.
model.njoints):
40 self.assertApprox(self.
data.mass[i], data2.mass[i])
45 c0 = pin.centerOfMass(self.
model, self.
data, self.
q)
46 c0_bis = pin.centerOfMass(self.
model, self.
data, self.
q,
False)
48 self.assertApprox(c0, c0_bis)
51 pin.forwardKinematics(self.
model, data, self.
q)
52 c0 = pin.centerOfMass(self.
model, data, pin.POSITION)
53 pin.forwardKinematics(self.
model, data2, self.
q)
54 c0_bis = pin.centerOfMass(self.
model, data2, pin.POSITION,
False)
56 self.assertApprox(c0, c0_bis)
58 c0_bis = pin.centerOfMass(self.
model, self.
data, 0)
60 self.assertApprox(c0, c0_bis)
62 self.assertApprox(c0, data2.com[0])
63 self.assertApprox(self.
data.com[0], data2.com[0])
69 c0 = pin.centerOfMass(self.
model, self.
data, self.
q, v)
70 c0_bis = pin.centerOfMass(self.
model, self.
data, self.
q, v,
False)
72 self.assertApprox(c0, c0_bis)
75 pin.forwardKinematics(self.
model, data, self.
q, v)
76 c0 = pin.centerOfMass(self.
model, data, pin.VELOCITY)
77 pin.forwardKinematics(self.
model, data2, self.
q, v)
78 c0_bis = pin.centerOfMass(self.
model, data2, pin.VELOCITY,
False)
80 self.assertApprox(c0, c0_bis)
82 c0_bis = pin.centerOfMass(self.
model, data2, 1)
84 self.assertApprox(c0, c0_bis)
87 pin.centerOfMass(self.
model, data3, self.
q)
89 self.assertApprox(self.
data.com[0], data2.com[0])
90 self.assertApprox(self.
data.vcom[0], data2.vcom[0])
92 self.assertApprox(self.
data.com[0], data3.com[0])
99 c0 = pin.centerOfMass(self.
model, self.
data, self.
q, v, a)
100 c0_bis = pin.centerOfMass(self.
model, self.
data, self.
q, v, a,
False)
102 self.assertApprox(c0, c0_bis)
105 pin.forwardKinematics(self.
model, data, self.
q, v, a)
106 c0 = pin.centerOfMass(self.
model, data, pin.ACCELERATION)
107 pin.forwardKinematics(self.
model, data2, self.
q, v, a)
108 c0_bis = pin.centerOfMass(self.
model, data2, pin.ACCELERATION,
False)
110 self.assertApprox(c0, c0_bis)
112 c0_bis = pin.centerOfMass(self.
model, data2, 2)
113 self.assertApprox(c0, c0_bis)
116 pin.centerOfMass(self.
model, data3, self.
q)
119 pin.centerOfMass(self.
model, data4, self.
q, v)
121 self.assertApprox(self.
data.com[0], data2.com[0])
122 self.assertApprox(self.
data.vcom[0], data2.vcom[0])
123 self.assertApprox(self.
data.acom[0], data2.acom[0])
125 self.assertApprox(self.
data.com[0], data3.com[0])
127 self.assertApprox(self.
data.com[0], data4.com[0])
128 self.assertApprox(self.
data.vcom[0], data4.vcom[0])
133 pin.centerOfMass(self.
model, self.
data, self.
q, v, a)
136 pin.forwardKinematics(self.
model, data2, self.
q, v, a)
137 pin.centerOfMass(self.
model, data2)
139 for i
in range(self.
model.njoints):
140 self.assertApprox(self.
data.com[i], data2.com[i])
141 self.assertApprox(self.
data.vcom[i], data2.vcom[i])
142 self.assertApprox(self.
data.acom[i], data2.acom[i])
145 Jcom = pin.jacobianCenterOfMass(self.
model, self.
data, self.
q)
146 self.assertFalse(np.isnan(Jcom).any())
149 Jcom = pin.jacobianCenterOfMass(self.
model, self.
data, self.
q,
True)
150 self.assertFalse(np.isnan(Jcom).any())
151 self.assertFalse(np.isnan(self.
data.com[1]).any())
157 pin.forwardKinematics(self.
model, data_no, self.
q)
158 Jcom_no = pin.jacobianCenterOfMass(self.
model, data_no)
160 Jcom_up = pin.jacobianCenterOfMass(self.
model, data_up, self.
q)
162 self.assertTrue((Jcom_no == Jcom_up).all())
168 pin.forwardKinematics(self.
model, data_no, self.
q)
169 Jcom_no = pin.jacobianCenterOfMass(self.
model, data_no,
True)
171 Jcom_up = pin.jacobianCenterOfMass(self.
model, data_up, self.
q,
True)
173 self.assertTrue((Jcom_no == Jcom_up).all())
174 self.assertTrue((data_no.com[1] == data_up.com[1]).all())
180 Jcom = pin.jacobianCenterOfMass(model, data, self.
q)
181 Jcom_subtree = pin.getJacobianSubtreeCenterOfMass(model, data, 0)
182 self.assertApprox(Jcom, Jcom_subtree)
184 data2 = model.createData()
185 Jcom_subtree2 = pin.jacobianSubtreeCenterOfMass(model, data2, self.
q, 0)
186 self.assertApprox(Jcom_subtree, Jcom_subtree2)
188 data3 = model.createData()
189 Jcom_subtree3 = pin.jacobianSubtreeCenterOfMass(model, data3, self.
q, 0)
190 self.assertApprox(Jcom_subtree3, Jcom_subtree2)
192 Jcom_subtree4 = pin.jacobianSubtreeCenterOfMass(model, data3, 0)
193 self.assertApprox(Jcom_subtree3, Jcom_subtree4)
196 if __name__ ==
"__main__":