bindings_frame.py
Go to the documentation of this file.
1 import unittest
2 from pathlib import Path
3 
4 import numpy as np
5 import pinocchio as pin
6 from test_case import PinocchioTestCase
7 
8 
10  def setUp(self):
11  self.model = pin.buildSampleModelHumanoidRandom()
12  self.parent_idx = (
13  self.model.getJointId("rarm2_joint")
14  if self.model.existJointName("rarm2_joint")
15  else (self.model.njoints - 1)
16  )
17  self.frame_name = self.model.names[self.parent_idx] + "_frame"
18  self.frame_placement = pin.SE3.Random()
19  self.frame_type = pin.FrameType.OP_FRAME
20  self.model.addFrame(
21  pin.Frame(
22  self.frame_name,
23  self.parent_idx,
24  0,
25  self.frame_placement,
26  self.frame_type,
27  )
28  )
29  self.frame_idx = self.model.getFrameId(self.frame_name)
30 
31  def tearDown(self):
32  del self.model
33 
34  def test_type_get_set(self):
35  f = self.model.frames[self.frame_idx]
36  self.assertTrue(f.type == self.frame_type)
37  f.type = pin.FrameType.BODY
38  self.assertTrue(f.type == pin.FrameType.BODY)
39 
40  def test_name_get_set(self):
41  f = self.model.frames[self.frame_idx]
42  self.assertTrue(f.name == self.frame_name)
43  f.name = "new_hip_frame"
44  self.assertTrue(f.name == "new_hip_frame")
45 
47  f = self.model.frames[self.frame_idx]
48  self.assertTrue(f.parentJoint == self.parent_idx)
49  newparent = self.parent_idx - 1
50  f.parentJoint = newparent
51  self.assertTrue(f.parentJoint == newparent)
52 
54  f = self.model.frames[self.frame_idx]
55  self.assertTrue(
56  np.allclose(f.placement.homogeneous, self.frame_placement.homogeneous)
57  )
58  new_placement = pin.SE3.Random()
59  f.placement = new_placement
60  self.assertTrue(np.allclose(f.placement.homogeneous, new_placement.homogeneous))
61 
63  M = pin.SE3.Random()
64  frame1 = pin.Frame("name", 1, 2, M, pin.OP_FRAME)
65  frame2 = pin.Frame("name", 1, 2, M, pin.OP_FRAME)
66  frame3 = pin.Frame("othername", 3, 4, pin.SE3.Random(), pin.BODY)
67 
68  self.assertTrue(frame1 == frame2)
69  self.assertFalse(frame1 != frame2)
70  self.assertTrue(frame1 != frame3)
71  self.assertFalse(frame1 == frame3)
72 
73  def test_pickle(self):
74  import pickle
75 
76  frame = pin.Frame("name", 1, 2, pin.SE3.Random(), pin.OP_FRAME)
77  filename = Path("frame.pickle")
78  with filename.open("wb") as f:
79  pickle.dump(frame, f)
80 
81  with filename.open("rb") as f:
82  frame_copy = pickle.load(f)
83 
84  self.assertEqual(frame, frame_copy)
85 
86  def test_getters(self):
87  data = self.model.createData()
88  q = pin.randomConfiguration(self.model)
89  v = np.random.rand(self.model.nv)
90  a = np.random.rand(self.model.nv)
91  pin.forwardKinematics(self.model, data, q, v, a)
92 
93  T = pin.updateFramePlacement(self.model, data, self.frame_idx)
94  self.assertApprox(T, data.oMi[self.parent_idx].act(self.frame_placement))
95 
96  v = pin.getFrameVelocity(self.model, data, self.frame_idx)
97  self.assertApprox(v, self.frame_placement.actInv(data.v[self.parent_idx]))
98  v = pin.getFrameVelocity(
99  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL
100  )
101  self.assertApprox(v, self.frame_placement.actInv(data.v[self.parent_idx]))
102  v = pin.getFrameVelocity(
103  self.model, data, self.frame_idx, pin.ReferenceFrame.WORLD
104  )
105  self.assertApprox(v, data.oMi[self.parent_idx].act(data.v[self.parent_idx]))
106  v = pin.getFrameVelocity(
107  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
108  )
109  self.assertApprox(
110  v,
111  pin.SE3(T.rotation, np.zeros(3)).act(
112  self.frame_placement.actInv(data.v[self.parent_idx])
113  ),
114  )
115 
116  a = pin.getFrameAcceleration(self.model, data, self.frame_idx)
117  self.assertApprox(a, self.frame_placement.actInv(data.a[self.parent_idx]))
118  a = pin.getFrameAcceleration(
119  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL
120  )
121  self.assertApprox(a, self.frame_placement.actInv(data.a[self.parent_idx]))
122  a = pin.getFrameAcceleration(
123  self.model, data, self.frame_idx, pin.ReferenceFrame.WORLD
124  )
125  self.assertApprox(a, data.oMi[self.parent_idx].act(data.a[self.parent_idx]))
126  a = pin.getFrameAcceleration(
127  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
128  )
129  self.assertApprox(
130  a,
131  pin.SE3(T.rotation, np.zeros(3)).act(
132  self.frame_placement.actInv(data.a[self.parent_idx])
133  ),
134  )
135 
136  a = pin.getFrameClassicalAcceleration(self.model, data, self.frame_idx)
137  a = pin.getFrameClassicalAcceleration(
138  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL
139  )
140  a = pin.getFrameClassicalAcceleration(
141  self.model, data, self.frame_idx, pin.ReferenceFrame.WORLD
142  )
143  a = pin.getFrameClassicalAcceleration(
144  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
145  )
146 
147  def test_frame_algo(self):
148  model = self.model
149  data = model.createData()
150 
151  q = pin.neutral(model)
152  v = np.random.rand(model.nv)
153  frame_id = self.frame_idx
154 
155  J1 = pin.computeFrameJacobian(model, data, q, frame_id)
156  J2 = pin.computeFrameJacobian(model, data, q, frame_id, pin.LOCAL)
157 
158  self.assertApprox(J1, J2)
159  data2 = model.createData()
160 
161  pin.computeJointJacobians(model, data2, q)
162  J3 = pin.getFrameJacobian(model, data2, frame_id, pin.LOCAL)
163  self.assertApprox(J1, J3)
164 
165  dJ1 = pin.frameJacobianTimeVariation(model, data, q, v, frame_id, pin.LOCAL)
166 
167  data3 = model.createData()
168  pin.computeJointJacobiansTimeVariation(model, data3, q, v)
169 
170  dJ2 = pin.getFrameJacobianTimeVariation(model, data3, frame_id, pin.LOCAL)
171  self.assertApprox(dJ1, dJ2)
172 
173 
174 if __name__ == "__main__":
175  unittest.main()
bindings_frame.TestFrameBindings.tearDown
def tearDown(self)
Definition: bindings_frame.py:31
bindings_frame.TestFrameBindings.model
model
Definition: bindings_frame.py:11
pinocchio::motionSet::act
static void act(const Eigen::MatrixBase< Mat > &iV, const ForceDense< ForceDerived > &f, Eigen::MatrixBase< MatRet > const &jF)
Action of a motion set on a force object. The input motion set is represented by a 6xN matrix whose e...
bindings_frame.TestFrameBindings.test_type_get_set
def test_type_get_set(self)
Definition: bindings_frame.py:34
bindings_frame.TestFrameBindings.test_getters
def test_getters(self)
Definition: bindings_frame.py:86
bindings_frame.TestFrameBindings.test_pickle
def test_pickle(self)
Definition: bindings_frame.py:73
bindings_frame.TestFrameBindings.frame_name
frame_name
Definition: bindings_frame.py:17
bindings_frame.TestFrameBindings.test_frame_equality
def test_frame_equality(self)
Definition: bindings_frame.py:62
bindings_frame.TestFrameBindings.test_name_get_set
def test_name_get_set(self)
Definition: bindings_frame.py:40
bindings_frame.TestFrameBindings.setUp
def setUp(self)
Definition: bindings_frame.py:10
bindings_frame.TestFrameBindings.parent_idx
parent_idx
Definition: bindings_frame.py:12
bindings_frame.TestFrameBindings
Definition: bindings_frame.py:9
pinocchio::createData
ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > createData(const ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > &cmodel)
Definition: constraint-model-visitor.hpp:239
bindings_frame.TestFrameBindings.frame_placement
frame_placement
Definition: bindings_frame.py:18
bindings_frame.TestFrameBindings.test_placement_get_set
def test_placement_get_set(self)
Definition: bindings_frame.py:53
test_case.PinocchioTestCase.assertApprox
def assertApprox(self, a, b, eps=1e-6)
Definition: test_case.py:12
bindings_frame.TestFrameBindings.frame_idx
frame_idx
Definition: bindings_frame.py:29
bindings_frame.TestFrameBindings.frame_type
frame_type
Definition: bindings_frame.py:19
bindings_frame.TestFrameBindings.test_parent_get_set
def test_parent_get_set(self)
Definition: bindings_frame.py:46
test_case.PinocchioTestCase
Definition: test_case.py:11
bindings_frame.TestFrameBindings.test_frame_algo
def test_frame_algo(self)
Definition: bindings_frame.py:147


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