bindings_geometry_model_urdf.py
Go to the documentation of this file.
1 import unittest
2 import pinocchio as pin
3 import os
4 
5 def checkGeom(geom1,geom2):
6  return geom1.ngeoms == geom2.ngeoms
7 
8 @unittest.skipUnless(pin.WITH_URDFDOM,"Needs URDFDOM")
9 class TestGeometryObjectUrdfBindings(unittest.TestCase):
10 
11  def setUp(self):
12  self.current_file = os.path.dirname(str(os.path.abspath(__file__)))
13  self.mesh_path = os.path.abspath(os.path.join(self.current_file, "../../models"))
14  self.model_dir = os.path.abspath(os.path.join(self.current_file, "../../models/example-robot-data/robots"))
15  self.model_path = os.path.abspath(os.path.join(self.model_dir, "romeo_description/urdf/romeo.urdf"))
16 
17  def test_load(self):
18  hint_list = [self.mesh_path, "wrong/hint"]
19  expected_mesh_path = os.path.join(self.model_dir,'romeo_description/meshes/V1/collision/LHipPitch.dae')
20 
21  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
22  collision_model = pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.COLLISION, hint_list)
23 
24  col = collision_model.geometryObjects[1]
25  self.assertEqual(os.path.normpath(col.meshPath), os.path.normpath(expected_mesh_path))
26 
27  def test_self_load(self):
28  hint_list = [self.mesh_path]
29 
30  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
31  collision_model_ref = pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.COLLISION, hint_list)
32 
33  collision_model_self = pin.GeometryModel()
34  pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.COLLISION, collision_model_self, hint_list)
35  self.assertTrue(checkGeom(collision_model_ref, collision_model_self))
36 
37  collision_model_self = pin.GeometryModel()
38  pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.COLLISION, collision_model_self, self.mesh_path)
39  self.assertTrue(checkGeom(collision_model_ref, collision_model_self))
40 
41  hint_vec = pin.StdVec_StdString()
42  hint_vec.append(self.mesh_path)
43 
44  collision_model_self = pin.GeometryModel()
45  pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.COLLISION, collision_model_self, hint_vec)
46  self.assertTrue(checkGeom(collision_model_ref, collision_model_self))
47 
48 
49  def test_multi_load(self):
50  hint_list = [self.mesh_path, "wrong/hint"]
51  expected_collision_path = os.path.join(self.model_dir,'romeo_description/meshes/V1/collision/LHipPitch.dae')
52  expected_visual_path = os.path.join(self.model_dir,'romeo_description/meshes/V1/visual/LHipPitch.dae')
53 
54  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
55 
56  collision_model = pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.COLLISION, hint_list)
57  col = collision_model.geometryObjects[1]
58  self.assertEqual(os.path.normpath(col.meshPath), os.path.normpath(expected_collision_path))
59 
60  visual_model = pin.buildGeomFromUrdf(model, self.model_path, pin.GeometryType.VISUAL, hint_list)
61  vis = visual_model.geometryObjects[1]
62  self.assertEqual(os.path.normpath(vis.meshPath), os.path.normpath(expected_visual_path))
63 
64  model_2, collision_model_2, visual_model_2 = pin.buildModelsFromUrdf(self.model_path, hint_list, pin.JointModelFreeFlyer())
65 
66  self.assertEqual(model,model_2)
67 
68  col_2 = collision_model_2.geometryObjects[1]
69  self.assertEqual(os.path.normpath(col_2.meshPath), os.path.normpath(expected_collision_path))
70 
71  vis_2 = visual_model_2.geometryObjects[1]
72  self.assertEqual(os.path.normpath(vis_2.meshPath), os.path.normpath(expected_visual_path))
73 
74  model_c, collision_model_c = pin.buildModelsFromUrdf(self.model_path, hint_list, pin.JointModelFreeFlyer(), geometry_types=pin.GeometryType.COLLISION)
75 
76  self.assertEqual(model,model_c)
77 
78  col_c = collision_model_c.geometryObjects[1]
79  self.assertEqual(os.path.normpath(col_c.meshPath), os.path.normpath(expected_collision_path))
80 
81  model_v, visual_model_v = pin.buildModelsFromUrdf(self.model_path, hint_list, pin.JointModelFreeFlyer(), geometry_types=pin.GeometryType.VISUAL)
82 
83  self.assertEqual(model,model_v)
84 
85  vis_v = visual_model_v.geometryObjects[1]
86  self.assertEqual(os.path.normpath(vis_v.meshPath), os.path.normpath(expected_visual_path))
87 
89  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
90 
91  hint_list = [self.mesh_path, "wrong/hint"]
92  pin.buildGeomFromUrdf(model, self.model_path, hint_list, pin.GeometryType.COLLISION)
93 
94  hint_vec = pin.StdVec_StdString()
95  hint_vec.append(self.mesh_path)
96  pin.buildGeomFromUrdf(model, self.model_path, hint_vec, pin.GeometryType.COLLISION)
97 
98  pin.buildGeomFromUrdf(model, self.model_path, self.mesh_path, pin.GeometryType.COLLISION)
99 
100  if pin.WITH_HPP_FCL_BINDINGS:
101  pin.buildGeomFromUrdf(model, self.model_path, hint_list, pin.GeometryType.COLLISION, pin.hppfcl.MeshLoader())
102  pin.buildGeomFromUrdf(model, self.model_path, hint_vec, pin.GeometryType.COLLISION, pin.hppfcl.MeshLoader())
103  pin.buildGeomFromUrdf(model, self.model_path, self.mesh_path, pin.GeometryType.COLLISION, pin.hppfcl.MeshLoader())
104 
105 if __name__ == '__main__':
106  unittest.main()


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02