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()
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]))
99  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL
100  )
101  self.assertApprox(v, self.frame_placement.actInv(data.v[self.parent_idx]))
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]))
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]))
119  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL
120  )
121  self.assertApprox(a, self.frame_placement.actInv(data.a[self.parent_idx]))
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]))
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 
138  self.model, data, self.frame_idx, pin.ReferenceFrame.LOCAL
139  )
141  self.model, data, self.frame_idx, pin.ReferenceFrame.WORLD
142  )
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...
pinocchio::getFrameClassicalAcceleration
MotionTpl< Scalar, Options > getFrameClassicalAcceleration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf=LOCAL)
Returns the "classical" acceleration of the Frame expressed in the desired reference frame....
Definition: frames.hpp:225
pinocchio::SE3
context::SE3 SE3
Definition: spatial/fwd.hpp:59
pinocchio::randomConfiguration
void randomConfiguration(const LieGroupGenericTpl< LieGroupCollection > &lg, const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const Eigen::MatrixBase< ConfigOut_t > &qout)
pinocchio::getFrameAcceleration
MotionTpl< Scalar, Options > getFrameAcceleration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf=LOCAL)
Returns the spatial acceleration of the Frame expressed in the desired reference frame....
Definition: frames.hpp:165
pinocchio::computeJointJacobiansTimeVariation
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobiansTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the full model Jacobian variations with respect to time. It corresponds to dJ/dt which depen...
pinocchio::forwardKinematics
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &a)
Update the joint placements, spatial velocities and spatial accelerations according to the current jo...
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
pinocchio::FrameTpl
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
Definition: multibody/frame.hpp:55
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
pinocchio::getFrameVelocity
MotionTpl< Scalar, Options > getFrameVelocity(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf=LOCAL)
Returns the spatial velocity of the Frame expressed in the desired reference frame....
Definition: frames.hpp:107
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
pinocchio::computeFrameJacobian
void computeFrameJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const FrameIndex frame_id, const Eigen::MatrixBase< Matrix6xLike > &J)
Computes the Jacobian of a specific Frame expressed in the LOCAL frame coordinate system.
Definition: frames.hpp:475
pinocchio::neutral
Eigen::Matrix< typename LieGroupCollection::Scalar, Eigen::Dynamic, 1, LieGroupCollection::Options > neutral(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the neutral element of it.
pinocchio::computeJointJacobians
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobians(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in the world frame....
pinocchio::getFrameJacobian
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > getFrameJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame reference_frame)
Returns the jacobian of the frame expressed either expressed in the local frame coordinate system,...
Definition: frames.hpp:394
pinocchio::getFrameJacobianTimeVariation
void getFrameJacobianTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf, const Eigen::MatrixBase< Matrix6xLike > &dJ)
Computes the Jacobian time variation of a specific frame (given by frame_id) expressed either in the ...
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::updateFramePlacement
const DataTpl< Scalar, Options, JointCollectionTpl >::SE3 & updateFramePlacement(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id)
Updates the placement of the given frame.


pinocchio
Author(s):
autogenerated on Wed May 28 2025 02:41:14