9
9
from rclpy .node import Node
10
10
11
11
# Local imports
12
- from ada_feeding_msgs .action import AcquireFood
12
+ from ada_feeding_msgs .action import AcquireFood , MoveTo
13
13
14
14
15
15
class AcquireFoodClient (Node ):
16
16
def __init__ (self ):
17
17
super ().__init__ ("acquire_food_client" )
18
+ self ._above_client = ActionClient (self , MoveTo , "/MoveAbovePlate" )
18
19
self ._action_client = ActionClient (self , AcquireFood , "/AcquireFood" )
19
20
20
21
self .declare_parameter ("request_path" , rclpy .Parameter .Type .STRING )
21
22
request_path = self .get_parameter ("request_path" )
22
23
with open (request_path .value , "rb" ) as file :
23
24
self .goal_msg = pickle .load (file )
24
25
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 ())
27
29
30
+ def acquire_food (self ):
31
+ self ._action_client .wait_for_server ()
28
32
return self ._action_client .send_goal_async (self .goal_msg )
29
33
30
34
@@ -33,8 +37,28 @@ def main(args=None):
33
37
34
38
action_client = AcquireFoodClient ()
35
39
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
+
36
60
# Send Goal
37
- future = action_client .send_goal ()
61
+ future = action_client .acquire_food ()
38
62
rclpy .spin_until_future_complete (action_client , future )
39
63
40
64
# Check Accept
0 commit comments