2 from pathlib
import Path
4 import pinocchio
as pin
6 from test_case
import PinocchioTestCase
as TestCase
11 self.
model = pin.buildSampleModelHumanoidRandom()
15 self.assertEqual(model.nbodies, 1)
16 self.assertEqual(model.nq, 0)
17 self.assertEqual(model.nv, 0)
18 model.name =
"empty_model"
24 idx, pin.JointModelRY(), pin.SE3.Identity(),
"joint_" + str(idx + 1)
32 me = np.array([MAX_EFF])
33 mv = np.array([MAX_VEL])
34 lb = np.array([MIN_POS])
35 ub = np.array([MAX_POS])
40 "joint_" + str(idx + 1),
47 self.assertEqual(model.nbodies, 1)
48 self.assertEqual(model.njoints, 3)
49 self.assertEqual(model.nq, 2)
50 self.assertEqual(model.nv, 2)
52 self.assertEqual(float(model.effortLimit[1]), MAX_EFF)
53 self.assertEqual(float(model.velocityLimit[1]), MAX_VEL)
54 self.assertEqual(float(model.lowerPositionLimit[1]), MIN_POS)
55 self.assertEqual(float(model.upperPositionLimit[1]), MAX_POS)
60 self.assertEqual(model.nbodies, nb)
61 self.assertEqual(model.nq, nb - 1 + 6)
62 self.assertEqual(model.nv, nb - 1 + 5)
66 model.inertias[1] = model.inertias[2]
67 self.assertApprox(model.inertias[1].np, model.inertias[2].np)
71 model.jointPlacements[1] = model.jointPlacements[2]
72 self.assertApprox(model.jointPlacements[1].np, model.jointPlacements[2].np)
73 self.assertEqual(model.parents[0], 0)
74 self.assertEqual(model.parents[1], 0)
75 model.parents[2] = model.parents[1]
76 self.assertEqual(model.parents[2], model.parents[1])
77 self.assertEqual(model.names[0],
"universe")
80 self.assertApprox(self.
model.gravity.np, np.array([0, 0, -9.81, 0, 0, 0]).T)
84 data = model.createData()
88 qddot =
zero(model.nv)
89 for i
in range(model.nbodies):
90 data.a[i] = pin.Motion.Zero()
92 pin.rnea(model, data, q, qdot, qddot)
93 for i
in range(model.nbodies):
94 self.assertApprox(data.v[i].np,
zero(6))
95 self.assertApprox(data.a_gf[0].np, -model.gravity.np)
96 self.assertApprox(data.f[-1], model.inertias[-1] * data.a_gf[-1])
100 model.referenceConfigurations[
"neutral"] = pin.neutral(model)
101 q_neutral = model.referenceConfigurations[
"neutral"]
104 self.assertApprox(model.referenceConfigurations[
"neutral"], q_neutral)
110 filename = Path(
"model.pickle")
111 with filename.open(
"wb")
as f:
112 pickle.dump(model, f)
114 with filename.open(
"rb")
as f:
115 model_copy = pickle.load(f)
117 self.assertTrue(model == model_copy)
120 if __name__ ==
"__main__":