bindings_data.py
Go to the documentation of this file.
1 import unittest
2 from pathlib import Path
3 
4 import pinocchio as pin
5 from test_case import PinocchioTestCase as TestCase
6 
7 
8 class TestData(TestCase):
9  def setUp(self):
10  self.model = pin.buildSampleModelHumanoidRandom()
11  self.data = self.model.createData()
12 
13  def test_copy(self):
14  data2 = self.data.copy()
15  q = pin.neutral(self.model)
16  pin.forwardKinematics(self.model, data2, q)
17  jointId = self.model.njoints - 1
18  self.assertNotEqual(self.data.oMi[jointId], data2.oMi[jointId])
19 
20  data3 = data2.copy()
21  self.assertEqual(data2.oMi[jointId], data3.oMi[jointId])
22 
24  model = self.model
25  data = self.data
26 
27  q = pin.neutral(model)
28  pin.centerOfMass(model, data, q)
29 
30  _com_list = data.com.tolist()
31  com = data.com[0]
32  with self.assertRaises(Exception) as context:
33  com = data.com[len(data.com) + 10]
34  print("com: ", com)
35 
36  self.assertTrue("Index out of range" in str(context.exception))
37 
38  with self.assertRaises(Exception) as context:
39  com = data.com["1"]
40  print("com: ", com)
41 
42  self.assertTrue("Invalid index type" in str(context.exception))
43 
44  def test_pickle(self):
45  import pickle
46 
47  data = self.data
48  filename = Path("data.pickle")
49  with filename.open("wb") as f:
50  pickle.dump(data, f)
51 
52  with filename.open("rb") as f:
53  data_copy = pickle.load(f)
54 
55  self.assertTrue(data == data_copy)
56 
57 
58 if __name__ == "__main__":
59  unittest.main()
bindings_data.TestData.data
data
Definition: bindings_data.py:11
bindings_data.TestData.test_pickle
def test_pickle(self)
Definition: bindings_data.py:44
bindings_data.TestData.setUp
def setUp(self)
Definition: bindings_data.py:9
pinocchio::createData
ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > createData(const ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > &cmodel)
Definition: constraint-model-visitor.hpp:239
bindings_data.TestData.test_std_vector_field
def test_std_vector_field(self)
Definition: bindings_data.py:23
pinocchio::copy
void copy(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &origin, DataTpl< Scalar, Options, JointCollectionTpl > &dest, KinematicLevel kinematic_level)
Copy part of the data from origin to dest. Template parameter can be used to select at which differen...
Definition: copy.hpp:42
bindings_data.TestData.test_copy
def test_copy(self)
Definition: bindings_data.py:13
bindings_data.TestData
Definition: bindings_data.py:8
bindings_data.TestData.model
model
Definition: bindings_data.py:10


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:25