Skip to content

Commit 106cc92

Browse files
authored
Merge pull request #408 from compas-dev/raise-bfnserror
Raise specific exceptions if backend feature is not supported
2 parents c5b975b + de211cf commit 106cc92

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
* Raise `BackendFeatureNotSupportedError` exceptions when a features is not supported by the planner, instead of generic `Exception`.
15+
1416
### Removed
1517

1618

src/compas_fab/backends/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@
9191
:nosignatures:
9292
9393
BackendError
94+
BackendFeatureNotSupportedError
9495
CartesianMotionError
95-
KinematicsError
9696
InverseKinematicsError
97+
KinematicsError
9798
9899
Interfaces
99100
==========
@@ -108,8 +109,9 @@
108109
# Base imports
109110
from .exceptions import (
110111
BackendError,
111-
KinematicsError,
112+
BackendFeatureNotSupportedError,
112113
InverseKinematicsError,
114+
KinematicsError,
113115
)
114116
from .tasks import (
115117
FutureResult,
@@ -158,8 +160,9 @@
158160
__all__ = [
159161
# Base
160162
"BackendError",
161-
"KinematicsError",
163+
"BackendFeatureNotSupportedError",
162164
"InverseKinematicsError",
165+
"KinematicsError",
163166
"FutureResult",
164167
"CancellableFutureResult",
165168
# ROS

src/compas_fab/backends/exceptions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
__all__ = [
66
"BackendError",
7-
"KinematicsError",
7+
"BackendFeatureNotSupportedError",
88
"InverseKinematicsError",
9+
"KinematicsError",
910
]
1011

1112

@@ -17,6 +18,12 @@ def __init__(self, message):
1718
super(BackendError, self).__init__(message)
1819

1920

21+
class BackendFeatureNotSupportedError(Exception):
22+
"""Indicates that the selected backend does not support the selected feature."""
23+
24+
pass
25+
26+
2027
class KinematicsError(BackendError):
2128
"""Indicates a kinematic solver exception."""
2229

src/compas_fab/backends/interfaces/client.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22
from __future__ import division
33
from __future__ import print_function
4+
from compas_fab.backends.exceptions import BackendFeatureNotSupportedError
45

56

67
def forward_docstring(backend_feature):
@@ -117,40 +118,40 @@ def inverse_kinematics(self, *args, **kwargs):
117118
118119
Raises
119120
------
120-
Exception
121+
BackendFeatureNotSupportedError
121122
Planner does not have this feature.
122123
"""
123-
raise Exception("Assigned planner does not have this feature.")
124+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
124125

125126
def forward_kinematics(self, *args, **kwargs):
126127
"""Default method for planner.
127128
128129
Raises
129130
------
130-
Exception
131+
BackendFeatureNotSupportedError
131132
Planner does not have this feature.
132133
"""
133-
raise Exception("Assigned planner does not have this feature.")
134+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
134135

135136
def plan_motion(self, *args, **kwargs):
136137
"""Default method for planner.
137138
138139
Raises
139140
------
140-
Exception
141+
BackendFeatureNotSupportedError
141142
Planner does not have this feature.
142143
"""
143-
raise Exception("Assigned planner does not have this feature.")
144+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
144145

145146
def plan_cartesian_motion(self, *args, **kwargs):
146147
"""Default method for planner.
147148
148149
Raises
149150
------
150-
Exception
151+
BackendFeatureNotSupportedError
151152
Planner does not have this feature.
152153
"""
153-
raise Exception("Assigned planner does not have this feature.")
154+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
154155

155156
# ==========================================================================
156157
# collision objects and planning scene
@@ -161,67 +162,67 @@ def get_planning_scene(self, *args, **kwargs):
161162
162163
Raises
163164
------
164-
Exception
165+
BackendFeatureNotSupportedError
165166
Planner does not have this feature.
166167
"""
167-
raise Exception("Assigned planner does not have this feature.")
168+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
168169

169170
def reset_planning_scene(self, *args, **kwargs):
170171
"""Default method for planner.
171172
172173
Raises
173174
------
174-
Exception
175+
BackendFeatureNotSupportedError
175176
Planner does not have this feature.
176177
"""
177-
raise Exception("Assigned planner does not have this feature.")
178+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
178179

179180
def add_collision_mesh(self, *args, **kwargs):
180181
"""Default method for planner.
181182
182183
Raises
183184
------
184-
Exception
185+
BackendFeatureNotSupportedError
185186
Planner does not have this feature.
186187
"""
187-
raise Exception("Assigned planner does not have this feature.")
188+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
188189

189190
def remove_collision_mesh(self, *args, **kwargs):
190191
"""Default method for planner.
191192
192193
Raises
193194
------
194-
Exception
195+
BackendFeatureNotSupportedError
195196
Planner does not have this feature.
196197
"""
197-
raise Exception("Assigned planner does not have this feature.")
198+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
198199

199200
def append_collision_mesh(self, *args, **kwargs):
200201
"""Default method for planner.
201202
202203
Raises
203204
------
204-
Exception
205+
BackendFeatureNotSupportedError
205206
Planner does not have this feature.
206207
"""
207-
raise Exception("Assigned planner does not have this feature.")
208+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
208209

209210
def add_attached_collision_mesh(self, *args, **kwargs):
210211
"""Default method for planner.
211212
212213
Raises
213214
------
214-
Exception
215+
BackendFeatureNotSupportedError
215216
Planner does not have this feature.
216217
"""
217-
raise Exception("Assigned planner does not have this feature.")
218+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")
218219

219220
def remove_attached_collision_mesh(self, *args, **kwargs):
220221
"""Default method for planner.
221222
222223
Raises
223224
------
224-
Exception
225+
BackendFeatureNotSupportedError
225226
Planner does not have this feature.
226227
"""
227-
raise Exception("Assigned planner does not have this feature.")
228+
raise BackendFeatureNotSupportedError("Assigned planner does not have this feature.")

src/compas_fab/ghpython/components/Cf_VisualizeRobot/code.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ghpythonlib.componentbase import executingcomponent as component
1515
from scriptcontext import sticky as st
1616

17+
from compas_fab.backends import BackendFeatureNotSupportedError
1718
from compas_fab.robots import PlanningScene
1819

1920

@@ -89,7 +90,15 @@ def RunScript(
8990

9091
if update_scene:
9192
scene = PlanningScene(robot)
92-
scene = robot.client.get_planning_scene()
93+
try:
94+
scene = robot.client.get_planning_scene()
95+
except BackendFeatureNotSupportedError:
96+
print(
97+
"The selected backend does not support collision meshes. If you need collision mesh support, use a different backend."
98+
)
99+
scene = None
100+
show_cm = False
101+
show_acm = False
93102

94103
if update_scene and show_cm:
95104
collision_meshes = []

0 commit comments

Comments
 (0)