2 from pathlib
import Path
5 import pinocchio
as pin
6 from test_case
import PinocchioTestCase
11 self.
model = pin.buildSampleModelHumanoidRandom()
13 self.
model.getJointId(
"rarm2_joint")
14 if self.
model.existJointName(
"rarm2_joint")
15 else (self.
model.njoints - 1)
37 f.type = pin.FrameType.BODY
38 self.assertTrue(f.type == pin.FrameType.BODY)
43 f.name =
"new_hip_frame"
44 self.assertTrue(f.name ==
"new_hip_frame")
48 self.assertTrue(f.parentJoint == self.
parent_idx)
50 f.parentJoint = newparent
51 self.assertTrue(f.parentJoint == newparent)
58 new_placement = pin.SE3.Random()
59 f.placement = new_placement
60 self.assertTrue(np.allclose(f.placement.homogeneous, new_placement.homogeneous))
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)
68 self.assertTrue(frame1 == frame2)
69 self.assertFalse(frame1 != frame2)
70 self.assertTrue(frame1 != frame3)
71 self.assertFalse(frame1 == frame3)
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:
81 with filename.open(
"rb")
as f:
82 frame_copy = pickle.load(f)
84 self.assertEqual(frame, frame_copy)
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)
98 v = pin.getFrameVelocity(
102 v = pin.getFrameVelocity(
106 v = pin.getFrameVelocity(
107 self.
model, data, self.
frame_idx, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
111 pin.SE3(T.rotation, np.zeros(3)).
act(
118 a = pin.getFrameAcceleration(
122 a = pin.getFrameAcceleration(
126 a = pin.getFrameAcceleration(
127 self.
model, data, self.
frame_idx, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
131 pin.SE3(T.rotation, np.zeros(3)).
act(
136 a = pin.getFrameClassicalAcceleration(self.
model, data, self.
frame_idx)
137 a = pin.getFrameClassicalAcceleration(
140 a = pin.getFrameClassicalAcceleration(
143 a = pin.getFrameClassicalAcceleration(
144 self.
model, data, self.
frame_idx, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
149 data = model.createData()
151 q = pin.neutral(model)
152 v = np.random.rand(model.nv)
155 J1 = pin.computeFrameJacobian(model, data, q, frame_id)
156 J2 = pin.computeFrameJacobian(model, data, q, frame_id, pin.LOCAL)
159 data2 = model.createData()
161 pin.computeJointJacobians(model, data2, q)
162 J3 = pin.getFrameJacobian(model, data2, frame_id, pin.LOCAL)
165 dJ1 = pin.frameJacobianTimeVariation(model, data, q, v, frame_id, pin.LOCAL)
167 data3 = model.createData()
168 pin.computeJointJacobiansTimeVariation(model, data3, q, v)
170 dJ2 = pin.getFrameJacobianTimeVariation(model, data3, frame_id, pin.LOCAL)
174 if __name__ ==
"__main__":