bindings_regressor.py
Go to the documentation of this file.
1 import unittest
2 
3 import pinocchio as pin
4 from pinocchio.utils import zero
5 from test_case import PinocchioTestCase as TestCase
6 
7 
8 class TestRegressorBindings(TestCase):
10  model = pin.buildSampleModelHumanoidRandom()
11 
12  data = model.createData()
13  data_ref = model.createData()
14 
15  model.lowerPositionLimit[:7] = -1.0
16  model.upperPositionLimit[:7] = 1.0
17 
18  q = pin.randomConfiguration(model)
19  pin.computeStaticRegressor(model, data, q)
20 
21  phi = zero(4 * (model.njoints - 1))
22  for k in range(1, model.njoints):
23  Y = model.inertias[k]
24  phi[4 * (k - 1)] = Y.mass
25  phi[4 * k - 3 : 4 * k] = Y.mass * Y.lever
26 
27  static_com_ref = pin.centerOfMass(model, data_ref, q)
28  static_com = data.staticRegressor.dot(phi)
29 
30  self.assertApprox(static_com, static_com_ref)
31 
32  def test_bodyRegressor(self):
33  In = pin.Inertia.Random()
34  v = pin.Motion.Random()
35  a = pin.Motion.Random()
36 
37  f = In * a + In.vxiv(v)
38 
39  f_regressor = pin.bodyRegressor(v, a).dot(In.toDynamicParameters())
40 
41  self.assertApprox(f_regressor, f.vector)
42 
44  model = pin.buildSampleModelManipulator()
45  data = model.createData()
46 
47  JOINT_ID = model.njoints - 1
48 
49  q = pin.randomConfiguration(model)
50  v = pin.utils.rand(model.nv)
51  a = pin.utils.rand(model.nv)
52 
53  pin.rnea(model, data, q, v, a)
54 
55  f = data.f[JOINT_ID]
56 
57  f_regressor = pin.jointBodyRegressor(model, data, JOINT_ID).dot(
58  model.inertias[JOINT_ID].toDynamicParameters()
59  )
60 
61  self.assertApprox(f_regressor, f.vector)
62 
64  model = pin.buildSampleModelManipulator()
65 
66  JOINT_ID = model.njoints - 1
67 
68  framePlacement = pin.SE3.Random()
69  FRAME_ID = model.addBodyFrame("test_body", JOINT_ID, framePlacement, -1)
70 
71  data = model.createData()
72 
73  q = pin.randomConfiguration(model)
74  v = pin.utils.rand(model.nv)
75  a = pin.utils.rand(model.nv)
76 
77  pin.rnea(model, data, q, v, a)
78 
79  f = framePlacement.actInv(data.f[JOINT_ID])
80  In = framePlacement.actInv(model.inertias[JOINT_ID])
81 
82  f_regressor = pin.frameBodyRegressor(model, data, FRAME_ID).dot(
83  In.toDynamicParameters()
84  )
85 
86  self.assertApprox(f_regressor, f.vector)
87 
89  model = pin.buildSampleModelHumanoidRandom()
90  model.lowerPositionLimit[:7] = -1.0
91  model.upperPositionLimit[:7] = 1.0
92 
93  data = model.createData()
94  data_ref = model.createData()
95 
96  q = pin.randomConfiguration(model)
97  v = pin.utils.rand(model.nv)
98  a = pin.utils.rand(model.nv)
99 
100  pin.rnea(model, data_ref, q, v, a)
101 
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()
105 
106  pin.computeJointTorqueRegressor(model, data, q, v, a)
107 
108  tau_regressor = data.jointTorqueRegressor.dot(params)
109 
110  self.assertApprox(tau_regressor, data_ref.tau)
111 
112 
113 if __name__ == "__main__":
114  unittest.main()
bindings_regressor.TestRegressorBindings.test_frameBodyRegressor
def test_frameBodyRegressor(self)
Definition: bindings_regressor.py:63
bindings_regressor.TestRegressorBindings.test_staticRegressor
def test_staticRegressor(self)
Definition: bindings_regressor.py:9
bindings_regressor.TestRegressorBindings.test_bodyRegressor
def test_bodyRegressor(self)
Definition: bindings_regressor.py:32
pinocchio.utils
Definition: bindings/python/pinocchio/utils.py:1
bindings_regressor.TestRegressorBindings.test_joint_torque_regressor
def test_joint_torque_regressor(self)
Definition: bindings_regressor.py:88
bindings_regressor.TestRegressorBindings.test_jointBodyRegressor
def test_jointBodyRegressor(self)
Definition: bindings_regressor.py:43
bindings_regressor.TestRegressorBindings
Definition: bindings_regressor.py:8
pinocchio.utils.zero
def zero(n)
Definition: bindings/python/pinocchio/utils.py:37


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:06