bindings_geometry_model_urdf.py
Go to the documentation of this file.
1 import os
2 import unittest
3 from pathlib import Path
4 
5 import pinocchio as pin
6 
7 
8 def checkGeom(geom1, geom2):
9  return geom1.ngeoms == geom2.ngeoms
10 
11 
12 @unittest.skipUnless(pin.WITH_URDFDOM, "Needs URDFDOM")
13 class TestGeometryObjectUrdfBindings(unittest.TestCase):
14  def setUp(self):
15  self.current_dir = Path(__file__).parent
16  self.mesh_path = self.current_dir / "../../models"
17  self.model_dir = self.current_dir / "../../models/example-robot-data/robots"
18  self.model_path = self.model_dir / "romeo_description/urdf/romeo.urdf"
19 
20  def test_load(self):
21  hint_list = [self.mesh_path, "wrong/hint"]
22  expected_mesh_path = (
23  self.model_dir / "romeo_description/meshes/V1/collision/LHipPitch.dae"
24  )
25 
26  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
27  collision_model = pin.buildGeomFromUrdf(
28  model, self.model_path, pin.GeometryType.COLLISION, hint_list
29  )
30 
31  col = collision_model.geometryObjects[1]
32  self.assertEqual(
33  os.path.normpath(col.meshPath), os.path.normpath(expected_mesh_path)
34  )
35 
36  def test_self_load(self):
37  hint_list = [self.mesh_path]
38 
39  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
40  collision_model_ref = pin.buildGeomFromUrdf(
41  model, self.model_path, pin.GeometryType.COLLISION, hint_list
42  )
43 
44  collision_model_self = pin.GeometryModel()
45  pin.buildGeomFromUrdf(
46  model,
47  self.model_path,
48  pin.GeometryType.COLLISION,
49  collision_model_self,
50  hint_list,
51  )
52  self.assertTrue(checkGeom(collision_model_ref, collision_model_self))
53 
54  collision_model_self = pin.GeometryModel()
55  pin.buildGeomFromUrdf(
56  model,
57  self.model_path,
58  pin.GeometryType.COLLISION,
59  collision_model_self,
60  self.mesh_path,
61  )
62  self.assertTrue(checkGeom(collision_model_ref, collision_model_self))
63 
64  hint_vec = [self.mesh_path]
65 
66  collision_model_self = pin.GeometryModel()
67  pin.buildGeomFromUrdf(
68  model,
69  self.model_path,
70  pin.GeometryType.COLLISION,
71  collision_model_self,
72  hint_vec,
73  )
74  self.assertTrue(checkGeom(collision_model_ref, collision_model_self))
75 
76  def test_multi_load(self):
77  hint_list = [self.mesh_path, "wrong/hint"]
78  expected_collision_path = (
79  self.model_dir / "romeo_description/meshes/V1/collision/LHipPitch.dae"
80  )
81  expected_visual_path = (
82  self.model_dir / "romeo_description/meshes/V1/visual/LHipPitch.dae"
83  )
84 
85  model = pin.buildModelFromUrdf(self.model_path, pin.JointModelFreeFlyer())
86 
87  collision_model = pin.buildGeomFromUrdf(
88  model, self.model_path, pin.GeometryType.COLLISION, hint_list
89  )
90  col = collision_model.geometryObjects[1]
91  self.assertEqual(
92  os.path.normpath(col.meshPath), os.path.normpath(expected_collision_path)
93  )
94 
95  visual_model = pin.buildGeomFromUrdf(
96  model, self.model_path, pin.GeometryType.VISUAL, hint_list
97  )
98  vis = visual_model.geometryObjects[1]
99  self.assertEqual(
100  os.path.normpath(vis.meshPath), os.path.normpath(expected_visual_path)
101  )
102 
103  model_2, collision_model_2, visual_model_2 = pin.buildModelsFromUrdf(
104  self.model_path, hint_list, pin.JointModelFreeFlyer()
105  )
106 
107  self.assertEqual(model, model_2)
108 
109  col_2 = collision_model_2.geometryObjects[1]
110  self.assertEqual(
111  os.path.normpath(col_2.meshPath), os.path.normpath(expected_collision_path)
112  )
113 
114  vis_2 = visual_model_2.geometryObjects[1]
115  self.assertEqual(
116  os.path.normpath(vis_2.meshPath), os.path.normpath(expected_visual_path)
117  )
118 
119  model_c, collision_model_c = pin.buildModelsFromUrdf(
120  self.model_path,
121  hint_list,
122  pin.JointModelFreeFlyer(),
123  geometry_types=pin.GeometryType.COLLISION,
124  )
125 
126  self.assertEqual(model, model_c)
127 
128  col_c = collision_model_c.geometryObjects[1]
129  self.assertEqual(
130  os.path.normpath(col_c.meshPath), os.path.normpath(expected_collision_path)
131  )
132 
133  model_v, visual_model_v = pin.buildModelsFromUrdf(
134  self.model_path,
135  hint_list,
136  pin.JointModelFreeFlyer(),
137  geometry_types=pin.GeometryType.VISUAL,
138  )
139 
140  self.assertEqual(model, model_v)
141 
142  vis_v = visual_model_v.geometryObjects[1]
143  self.assertEqual(
144  os.path.normpath(vis_v.meshPath), os.path.normpath(expected_visual_path)
145  )
146 
147 
148 if __name__ == "__main__":
149  unittest.main()
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.setUp
def setUp(self)
Definition: bindings_geometry_model_urdf.py:14
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.model_dir
model_dir
Definition: bindings_geometry_model_urdf.py:17
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.test_load
def test_load(self)
Definition: bindings_geometry_model_urdf.py:20
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.mesh_path
mesh_path
Definition: bindings_geometry_model_urdf.py:16
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.model_path
model_path
Definition: bindings_geometry_model_urdf.py:18
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.test_self_load
def test_self_load(self)
Definition: bindings_geometry_model_urdf.py:36
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings
Definition: bindings_geometry_model_urdf.py:13
bindings_geometry_model_urdf.checkGeom
def checkGeom(geom1, geom2)
Definition: bindings_geometry_model_urdf.py:8
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.current_dir
current_dir
Definition: bindings_geometry_model_urdf.py:15
bindings_geometry_model_urdf.TestGeometryObjectUrdfBindings.test_multi_load
def test_multi_load(self)
Definition: bindings_geometry_model_urdf.py:76


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