bindings_regressor.py
Go to the documentation of this file.
1 import unittest
2 from test_case import PinocchioTestCase as TestCase
3 import pinocchio as pin
4 from pinocchio.utils import rand, zero
5 import numpy as np
6 
7 class TestRegressorBindings(TestCase):
8 
10  model = pin. buildSampleModelHumanoidRandom()
11 
12  data = model.createData()
13  data_ref = model.createData()
14 
15  model.lowerPositionLimit[:7] = -1.
16  model.upperPositionLimit[:7] = 1.
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  I = pin.Inertia.Random()
34  v = pin.Motion.Random()
35  a = pin.Motion.Random()
36 
37  f = I*a + I.vxiv(v)
38 
39  f_regressor = pin.bodyRegressor(v,a).dot(I.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(model.inertias[JOINT_ID].toDynamicParameters())
58 
59  self.assertApprox(f_regressor, f.vector)
60 
62  model = pin.buildSampleModelManipulator()
63 
64  JOINT_ID = model.njoints - 1
65 
66  framePlacement = pin.SE3.Random()
67  FRAME_ID = model.addBodyFrame ("test_body", JOINT_ID, framePlacement, -1)
68 
69  data = model.createData()
70 
71  q = pin.randomConfiguration(model)
72  v = pin.utils.rand(model.nv)
73  a = pin.utils.rand(model.nv)
74 
75  pin.rnea(model,data,q,v,a)
76 
77  f = framePlacement.actInv(data.f[JOINT_ID])
78  I = framePlacement.actInv(model.inertias[JOINT_ID])
79 
80  f_regressor = pin.frameBodyRegressor(model,data,FRAME_ID).dot(I.toDynamicParameters())
81 
82  self.assertApprox(f_regressor, f.vector)
83 
85  model = pin.buildSampleModelHumanoidRandom()
86  model.lowerPositionLimit[:7] = -1.
87  model.upperPositionLimit[:7] = 1.
88 
89  data = model.createData()
90  data_ref = model.createData()
91 
92  q = pin.randomConfiguration(model)
93  v = pin.utils.rand(model.nv)
94  a = pin.utils.rand(model.nv)
95 
96  pin.rnea(model,data_ref,q,v,a)
97 
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()
101 
102  pin.computeJointTorqueRegressor(model,data,q,v,a)
103 
104  tau_regressor = data.jointTorqueRegressor.dot(params)
105 
106  self.assertApprox(tau_regressor, data_ref.tau)
107 
108 if __name__ == '__main__':
109  unittest.main()


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02