Skip to content

Commit 74137b2

Browse files
authored
MoveAbovePlate before AcquireFood (#89)
* MoveAbovePlate before AcquireFood * Black format * Remove auto-Shutdown, this actually makes it harder to see the result, need manual Ctrl-C after each test
1 parent 5c83b69 commit 74137b2

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

feeding_web_app_ros2_test/feeding_web_app_ros2_test/AcquireFoodClient.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@
99
from rclpy.node import Node
1010

1111
# Local imports
12-
from ada_feeding_msgs.action import AcquireFood
12+
from ada_feeding_msgs.action import AcquireFood, MoveTo
1313

1414

1515
class AcquireFoodClient(Node):
1616
def __init__(self):
1717
super().__init__("acquire_food_client")
18+
self._above_client = ActionClient(self, MoveTo, "/MoveAbovePlate")
1819
self._action_client = ActionClient(self, AcquireFood, "/AcquireFood")
1920

2021
self.declare_parameter("request_path", rclpy.Parameter.Type.STRING)
2122
request_path = self.get_parameter("request_path")
2223
with open(request_path.value, "rb") as file:
2324
self.goal_msg = pickle.load(file)
2425

25-
def send_goal(self):
26-
self._action_client.wait_for_server()
26+
def move_above_plate(self):
27+
self._above_client.wait_for_server()
28+
return self._above_client.send_goal_async(MoveTo.Goal())
2729

30+
def acquire_food(self):
31+
self._action_client.wait_for_server()
2832
return self._action_client.send_goal_async(self.goal_msg)
2933

3034

@@ -33,8 +37,28 @@ def main(args=None):
3337

3438
action_client = AcquireFoodClient()
3539

40+
# First Move Above Plate
41+
# Send Goal
42+
future = action_client.move_above_plate()
43+
rclpy.spin_until_future_complete(action_client, future)
44+
45+
# Check Accept
46+
goal_handle = future.result()
47+
if not goal_handle.accepted:
48+
action_client.get_logger().error("MoveAbovePlate Rejected")
49+
return
50+
action_client.get_logger().info("MoveAbovePlate Accepted")
51+
52+
# Get Result
53+
future = goal_handle.get_result_async()
54+
rclpy.spin_until_future_complete(action_client, future)
55+
result = future.result().result
56+
if result.status != result.STATUS_SUCCESS:
57+
action_client.get_logger().error("MoveAbovePlate Failed")
58+
return
59+
3660
# Send Goal
37-
future = action_client.send_goal()
61+
future = action_client.acquire_food()
3862
rclpy.spin_until_future_complete(action_client, future)
3963

4064
# Check Accept

feeding_web_app_ros2_test/launch/feeding_dummy_acquirefood_launch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
from launch_ros.substitutions import FindPackageShare
33
from launch import LaunchDescription
4-
from launch.actions import IncludeLaunchDescription, Shutdown
4+
from launch.actions import IncludeLaunchDescription
55
from launch.launch_description_sources import AnyLaunchDescriptionSource
66
from launch.actions import DeclareLaunchArgument
77
from launch.substitutions import (
@@ -62,7 +62,6 @@ def generate_launch_description():
6262
parameters=[
6363
request_path,
6464
],
65-
on_exit=Shutdown(),
6665
)
6766
)
6867

0 commit comments

Comments
 (0)