2 from test_case
import PinocchioTestCase
as TestCase
3 import pinocchio
as pin
12 data = model.createData()
13 data_ref = model.createData()
15 model.lowerPositionLimit[:7] = -1.
16 model.upperPositionLimit[:7] = 1.
18 q = pin.randomConfiguration(model)
19 pin.computeStaticRegressor(model,data,q)
21 phi =
zero(4*(model.njoints-1))
22 for k
in range(1,model.njoints):
25 phi[4*k-3:4*k] = Y.mass * Y.lever
27 static_com_ref = pin.centerOfMass(model,data_ref,q)
28 static_com = data.staticRegressor.dot(phi)
30 self.assertApprox(static_com, static_com_ref)
33 I = pin.Inertia.Random()
34 v = pin.Motion.Random()
35 a = pin.Motion.Random()
39 f_regressor = pin.bodyRegressor(v,a).dot(I.toDynamicParameters())
41 self.assertApprox(f_regressor, f.vector)
44 model = pin.buildSampleModelManipulator()
45 data = model.createData()
47 JOINT_ID = model.njoints - 1
49 q = pin.randomConfiguration(model)
50 v = pin.utils.rand(model.nv)
51 a = pin.utils.rand(model.nv)
53 pin.rnea(model,data,q,v,a)
57 f_regressor = pin.jointBodyRegressor(model,data,JOINT_ID).dot(model.inertias[JOINT_ID].toDynamicParameters())
59 self.assertApprox(f_regressor, f.vector)
62 model = pin.buildSampleModelManipulator()
64 JOINT_ID = model.njoints - 1
66 framePlacement = pin.SE3.Random()
67 FRAME_ID = model.addBodyFrame (
"test_body", JOINT_ID, framePlacement, -1)
69 data = model.createData()
71 q = pin.randomConfiguration(model)
72 v = pin.utils.rand(model.nv)
73 a = pin.utils.rand(model.nv)
75 pin.rnea(model,data,q,v,a)
77 f = framePlacement.actInv(data.f[JOINT_ID])
78 I = framePlacement.actInv(model.inertias[JOINT_ID])
80 f_regressor = pin.frameBodyRegressor(model,data,FRAME_ID).dot(I.toDynamicParameters())
82 self.assertApprox(f_regressor, f.vector)
85 model = pin.buildSampleModelHumanoidRandom()
86 model.lowerPositionLimit[:7] = -1.
87 model.upperPositionLimit[:7] = 1.
89 data = model.createData()
90 data_ref = model.createData()
92 q = pin.randomConfiguration(model)
93 v = pin.utils.rand(model.nv)
94 a = pin.utils.rand(model.nv)
96 pin.rnea(model,data_ref,q,v,a)
98 params =
zero(10*(model.njoints-1))
99 for i
in range(1, model.njoints):
100 params[(i-1)*10:i*10] = model.inertias[i].toDynamicParameters()
102 pin.computeJointTorqueRegressor(model,data,q,v,a)
104 tau_regressor = data.jointTorqueRegressor.dot(params)
106 self.assertApprox(tau_regressor, data_ref.tau)
108 if __name__ ==
'__main__':
def test_frameBodyRegressor(self)
def test_staticRegressor(self)
def test_bodyRegressor(self)
def test_joint_torque_regressor(self)
def test_jointBodyRegressor(self)
Model buildSampleModelHumanoidRandom()