From ab6f94685377432ec704246d92e2a5605f40337d Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Fri, 15 Nov 2024 16:41:48 +0800 Subject: [PATCH] Rename functions Signed-off-by: Aaron Chong --- free_fleet_adapter/free_fleet_adapter/fleet_adapter.py | 4 ++-- .../free_fleet_adapter/nav2_robot_adapter.py | 6 ++++-- free_fleet_adapter/free_fleet_adapter/robot_adapter.py | 4 ++-- .../tests/integration/test_nav2_robot_adapter.py | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/free_fleet_adapter/free_fleet_adapter/fleet_adapter.py b/free_fleet_adapter/free_fleet_adapter/fleet_adapter.py index 2cc7dbc..9f522ca 100644 --- a/free_fleet_adapter/free_fleet_adapter/fleet_adapter.py +++ b/free_fleet_adapter/free_fleet_adapter/fleet_adapter.py @@ -209,7 +209,7 @@ def run_in_parallel(*args, **kwargs): @parallel def update_robot(robot: Nav2RobotAdapter): - robot_pose = robot.pose() + robot_pose = robot.get_pose() if robot_pose is None: robot.node.get_logger().info(f'Failed to pose of robot [{robot.name}]') return None @@ -217,7 +217,7 @@ def update_robot(robot: Nav2RobotAdapter): state = rmf_easy.RobotState( robot.map, robot_pose, - robot.battery_soc + robot.get_battery_soc() ) if robot.update_handle is None: diff --git a/free_fleet_adapter/free_fleet_adapter/nav2_robot_adapter.py b/free_fleet_adapter/free_fleet_adapter/nav2_robot_adapter.py index 1af6677..434147c 100644 --- a/free_fleet_adapter/free_fleet_adapter/nav2_robot_adapter.py +++ b/free_fleet_adapter/free_fleet_adapter/nav2_robot_adapter.py @@ -146,10 +146,10 @@ def _battery_state_callback(sample: zenoh.Sample): _battery_state_callback ) - def battery_soc(self) -> float: + def get_battery_soc(self) -> float: return self.battery_soc - def pose(self) -> Annotated[list[float], 3] | None: + def get_pose(self) -> Annotated[list[float], 3] | None: transform = self.tf_handler.get_transform() if transform is None: error_message = \ @@ -305,6 +305,8 @@ def _handle_navigate_to_pose( self.update_handle.more().replan() self.nav_goal_id = None return + except RuntimeError as e: + raise e except Exception as e: payload = reply.err.payload.to_string() self.node.get_logger().error( diff --git a/free_fleet_adapter/free_fleet_adapter/robot_adapter.py b/free_fleet_adapter/free_fleet_adapter/robot_adapter.py index 86b1060..943e7e3 100644 --- a/free_fleet_adapter/free_fleet_adapter/robot_adapter.py +++ b/free_fleet_adapter/free_fleet_adapter/robot_adapter.py @@ -29,7 +29,7 @@ class RobotAdapter(ABC): between 0 and 1.0. """ @abstractmethod - def battery_soc(self) -> float: + def get_battery_soc(self) -> float: ... """ @@ -39,7 +39,7 @@ def battery_soc(self) -> float: returns None. """ @abstractmethod - def pose(self) -> Annotated[list[float], 3] | None: + def get_pose(self) -> Annotated[list[float], 3] | None: ... """ diff --git a/free_fleet_adapter/tests/integration/test_nav2_robot_adapter.py b/free_fleet_adapter/tests/integration/test_nav2_robot_adapter.py index 1f5550e..d31722d 100644 --- a/free_fleet_adapter/tests/integration/test_nav2_robot_adapter.py +++ b/free_fleet_adapter/tests/integration/test_nav2_robot_adapter.py @@ -57,7 +57,7 @@ def test_non_existent_robot_pose(self): robot_exists = False for i in range(10): - transform = robot_adapter.pose() + transform = robot_adapter.get_pose() if transform is not None: robot_exists = True break @@ -82,7 +82,7 @@ def test_robot_pose(self): robot_exists = False for i in range(10): - transform = robot_adapter.pose() + transform = robot_adapter.get_pose() if transform is not None: robot_exists = True break @@ -105,7 +105,7 @@ def test_robot_battery_soc(self): tf_buffer=tf_buffer ) - battery_soc = robot_adapter.battery_soc() + battery_soc = robot_adapter.get_battery_soc() assert math.isclose(battery_soc, 1.0) def test_robot_unable_to_update(self): @@ -168,7 +168,7 @@ def test_robot_stop_without_command(self): tf_buffer=tf_buffer ) assert robot_adapter.execution is None - robot_adapter.stop() + robot_adapter.stop(None) assert robot_adapter.execution is None assert robot_adapter._is_navigation_done()