3 import pinocchio
as pin
5 from test_case
import PinocchioTestCase
as TestCase
10 model = pin.buildSampleModelHumanoidRandom()
12 data = model.createData()
13 data_ref = model.createData()
15 model.lowerPositionLimit[:7] = -1.0
16 model.upperPositionLimit[:7] = 1.0
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):
24 phi[4 * (k - 1)] = Y.mass
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 In = pin.Inertia.Random()
34 v = pin.Motion.Random()
35 a = pin.Motion.Random()
37 f = In * a + In.vxiv(v)
39 f_regressor = pin.bodyRegressor(v, a).dot(In.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(
58 model.inertias[JOINT_ID].toDynamicParameters()
61 self.assertApprox(f_regressor, f.vector)
64 model = pin.buildSampleModelManipulator()
66 JOINT_ID = model.njoints - 1
68 framePlacement = pin.SE3.Random()
69 FRAME_ID = model.addBodyFrame(
"test_body", JOINT_ID, framePlacement, -1)
71 data = model.createData()
73 q = pin.randomConfiguration(model)
74 v = pin.utils.rand(model.nv)
75 a = pin.utils.rand(model.nv)
77 pin.rnea(model, data, q, v, a)
79 f = framePlacement.actInv(data.f[JOINT_ID])
80 In = framePlacement.actInv(model.inertias[JOINT_ID])
82 f_regressor = pin.frameBodyRegressor(model, data, FRAME_ID).dot(
83 In.toDynamicParameters()
86 self.assertApprox(f_regressor, f.vector)
89 model = pin.buildSampleModelHumanoidRandom()
90 model.lowerPositionLimit[:7] = -1.0
91 model.upperPositionLimit[:7] = 1.0
93 data = model.createData()
94 data_ref = model.createData()
96 q = pin.randomConfiguration(model)
97 v = pin.utils.rand(model.nv)
98 a = pin.utils.rand(model.nv)
100 pin.rnea(model, data_ref, q, v, a)
102 params =
zero(10 * (model.njoints - 1))
103 for i
in range(1, model.njoints):
104 params[(i - 1) * 10 : i * 10] = model.inertias[i].toDynamicParameters()
106 pin.computeJointTorqueRegressor(model, data, q, v, a)
108 tau_regressor = data.jointTorqueRegressor.dot(params)
110 self.assertApprox(tau_regressor, data_ref.tau)
113 if __name__ ==
"__main__":