Skip to content

Commit 4f86506

Browse files
committed
add custom exception and raise it in behavior
1 parent 2736cef commit 4f86506

File tree

2 files changed

+17
-1
lines changed
  • bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules
  • bitbots_misc/bitbots_utils/bitbots_utils

2 files changed

+17
-1
lines changed

bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/misc_capsule.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Literal, Optional, TypeAlias
22

3-
from bitbots_utils.utils import get_parameters_from_other_node
3+
from bitbots_utils.utils import RobotNotConfiguredError, get_parameters_from_other_node
44
from rclpy.duration import Duration
55
from std_msgs.msg import Bool
66

@@ -30,6 +30,14 @@ def __init__(self, node, blackboard):
3030
self._node, "parameter_blackboard", ["bot_id", "position_number"]
3131
)
3232

33+
if any(param_val is None for param_val in gamestate_settings.values()):
34+
error_text = """
35+
The robot is not configured properly or the parameter_blackboard is not found.
36+
It is likely that the robot was not configured when you syncronised your clean code onto the robot.
37+
Run the deploy_robots script with the -c option to configure the robot and set parameters like the robot id and its role."""
38+
self._node.get_logger().fatal(error_text)
39+
raise RobotNotConfiguredError(error_text)
40+
3341
self.position_number: int = gamestate_settings["position_number"]
3442
self.bot_id: int = gamestate_settings["bot_id"]
3543

bitbots_misc/bitbots_utils/bitbots_utils/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
nobeartype = beartype(conf=BeartypeConf(strategy=BeartypeStrategy.O0))
1717

1818

19+
class RobotNotConfiguredError(Exception):
20+
"""Exception raised when the robot is not configured properly."""
21+
22+
def __init__(self, message):
23+
self.message = message
24+
super().__init__(message)
25+
26+
1927
def read_urdf(robot_name: str) -> str:
2028
urdf = os.popen(
2129
f"xacro {get_package_share_directory(f'{robot_name}_description')}"

0 commit comments

Comments
 (0)