2 from test_case
import PinocchioTestCase
as TestCase
3 import pinocchio
as pin
10 self.
model = pin.buildSampleModelHumanoidRandom()
13 qmax = np.full((self.
model.nq,1),np.pi)
14 self.
q = pin.randomConfiguration(self.
model,-qmax,qmax)
17 mass = pin.computeTotalMass(self.
model)
18 self.assertIsNot(mass, np.nan)
20 mass_check = sum([inertia.mass
for inertia
in self.
model.inertias[1:] ])
21 self.assertApprox(mass,mass_check)
23 mass_data = pin.computeTotalMass(self.
model,self.
data)
24 self.assertIsNot(mass_data, np.nan)
25 self.assertApprox(mass,mass_data)
26 self.assertApprox(mass_data,self.
data.mass[0])
29 pin.centerOfMass(self.
model,data2,self.
q)
30 self.assertApprox(mass,data2.mass[0])
33 pin.computeSubtreeMasses(self.
model,self.
data)
36 pin.centerOfMass(self.
model,data2,self.
q)
38 for i
in range(self.
model.njoints):
39 self.assertApprox(self.
data.mass[i],data2.mass[i])
44 c0 = pin.centerOfMass(self.
model,self.
data,self.
q)
45 c0_bis = pin.centerOfMass(self.
model,self.
data,self.
q,
False)
47 self.assertApprox(c0,c0_bis)
50 pin.forwardKinematics(self.
model,data,self.
q)
51 c0 = pin.centerOfMass(self.
model,data,pin.POSITION)
52 pin.forwardKinematics(self.
model,data2,self.
q)
53 c0_bis = pin.centerOfMass(self.
model,data2,pin.POSITION,
False)
55 self.assertApprox(c0,c0_bis)
57 c0_bis = pin.centerOfMass(self.
model,self.
data,0)
59 self.assertApprox(c0,c0_bis)
61 self.assertApprox(c0,data2.com[0])
62 self.assertApprox(self.
data.com[0],data2.com[0])
68 c0 = pin.centerOfMass(self.
model,self.
data,self.
q,v)
69 c0_bis = pin.centerOfMass(self.
model,self.
data,self.
q,v,
False)
71 self.assertApprox(c0,c0_bis)
74 pin.forwardKinematics(self.
model,data,self.
q,v)
75 c0 = pin.centerOfMass(self.
model,data,pin.VELOCITY)
76 pin.forwardKinematics(self.
model,data2,self.
q,v)
77 c0_bis = pin.centerOfMass(self.
model,data2,pin.VELOCITY,
False)
79 self.assertApprox(c0,c0_bis)
81 c0_bis = pin.centerOfMass(self.
model,data2,1)
83 self.assertApprox(c0,c0_bis)
86 pin.centerOfMass(self.
model,data3,self.
q)
88 self.assertApprox(self.
data.com[0],data2.com[0])
89 self.assertApprox(self.
data.vcom[0],data2.vcom[0])
91 self.assertApprox(self.
data.com[0],data3.com[0])
98 c0 = pin.centerOfMass(self.
model,self.
data,self.
q,v,a)
99 c0_bis = pin.centerOfMass(self.
model,self.
data,self.
q,v,a,
False)
101 self.assertApprox(c0,c0_bis)
104 pin.forwardKinematics(self.
model,data,self.
q,v,a)
105 c0 = pin.centerOfMass(self.
model,data,pin.ACCELERATION)
106 pin.forwardKinematics(self.
model,data2,self.
q,v,a)
107 c0_bis = pin.centerOfMass(self.
model,data2,pin.ACCELERATION,
False)
109 self.assertApprox(c0,c0_bis)
111 c0_bis = pin.centerOfMass(self.
model,data2,2)
112 self.assertApprox(c0,c0_bis)
115 pin.centerOfMass(self.
model,data3,self.
q)
118 pin.centerOfMass(self.
model,data4,self.
q,v)
120 self.assertApprox(self.
data.com[0],data2.com[0])
121 self.assertApprox(self.
data.vcom[0],data2.vcom[0])
122 self.assertApprox(self.
data.acom[0],data2.acom[0])
124 self.assertApprox(self.
data.com[0],data3.com[0])
126 self.assertApprox(self.
data.com[0],data4.com[0])
127 self.assertApprox(self.
data.vcom[0],data4.vcom[0])
132 pin.centerOfMass(self.
model,self.
data,self.
q,v,a)
135 pin.forwardKinematics(self.
model,data2,self.
q,v,a)
136 pin.centerOfMass(self.
model,data2)
138 for i
in range(self.
model.njoints):
139 self.assertApprox(self.
data.com[i],data2.com[i])
140 self.assertApprox(self.
data.vcom[i],data2.vcom[i])
141 self.assertApprox(self.
data.acom[i],data2.acom[i])
144 Jcom = pin.jacobianCenterOfMass(self.
model,self.
data,self.
q)
145 self.assertFalse(np.isnan(Jcom).any())
148 Jcom = pin.jacobianCenterOfMass(self.
model,self.
data,self.
q,
True)
149 self.assertFalse(np.isnan(Jcom).any())
150 self.assertFalse(np.isnan(self.
data.com[1]).any())
156 pin.forwardKinematics(self.
model,data_no,self.
q)
157 Jcom_no = pin.jacobianCenterOfMass(self.
model,data_no)
159 Jcom_up = pin.jacobianCenterOfMass(self.
model,data_up,self.
q)
161 self.assertTrue((Jcom_no==Jcom_up).all())
167 pin.forwardKinematics(self.
model,data_no,self.
q)
168 Jcom_no = pin.jacobianCenterOfMass(self.
model,data_no,
True)
170 Jcom_up = pin.jacobianCenterOfMass(self.
model,data_up,self.
q,
True)
172 self.assertTrue((Jcom_no==Jcom_up).all())
173 self.assertTrue((data_no.com[1]==data_up.com[1]).all())
179 Jcom = pin.jacobianCenterOfMass(model,data,self.
q)
180 Jcom_subtree = pin.getJacobianSubtreeCenterOfMass(model,data,0)
181 self.assertApprox(Jcom,Jcom_subtree)
183 data2 = model.createData()
184 Jcom_subtree2 = pin.jacobianSubtreeCenterOfMass(model,data2,self.
q,0)
185 self.assertApprox(Jcom_subtree,Jcom_subtree2)
187 data3 = model.createData()
188 Jcom_subtree3 = pin.jacobianSubtreeCoMJacobian(model,data3,self.
q,0)
189 self.assertApprox(Jcom_subtree3,Jcom_subtree2)
191 Jcom_subtree4 = pin.jacobianSubtreeCoMJacobian(model,data3,0)
192 self.assertApprox(Jcom_subtree3,Jcom_subtree4)
194 if __name__ ==
'__main__':
def test_Jcom_noupdate3(self)
def test_Jcom_update4(self)
def test_subtree_masses(self)
def test_Jcom_noupdate2(self)
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
def test_Jcom_update3(self)
def test_com_default(self)
def test_subtree_jacobian(self)