@@ -174,12 +174,13 @@ def init_robot(self):
174174 }
175175 )
176176
177- # test action appearance
178- self .jtc_action_client = waitForAction (
179- self .node ,
180- "/scaled_joint_trajectory_controller/follow_joint_trajectory" ,
181- FollowJointTrajectory ,
182- )
177+ action_interfaces = {
178+ "/scaled_joint_trajectory_controller/follow_joint_trajectory" : FollowJointTrajectory
179+ }
180+ self .action_clients = {
181+ action_name : waitForAction (self .node , action_name , action_type )
182+ for (action_name , action_type ) in action_interfaces .items ()
183+ }
183184
184185 # Start robot
185186 empty_req = Trigger .Request ()
@@ -275,12 +276,15 @@ def test_trajectory(self):
275276 # Sending trajectory goal
276277 self .node .get_logger ().info ("Sending simple goal" )
277278 goal_response = self .call_action (
278- self .jtc_action_client , FollowJointTrajectory .Goal (trajectory = trajectory )
279+ "/scaled_joint_trajectory_controller/follow_joint_trajectory" ,
280+ FollowJointTrajectory .Goal (trajectory = trajectory ),
279281 )
280282 self .assertEqual (goal_response .accepted , True )
281283
282284 # Verify execution
283- result = self .get_result (self .jtc_action_client , goal_response )
285+ result = self .get_result (
286+ "/scaled_joint_trajectory_controller/follow_joint_trajectory" , goal_response
287+ )
284288 self .assertEqual (result .error_code , FollowJointTrajectory .Result .SUCCESSFUL )
285289 self .node .get_logger ().info ("Received result SUCCESSFUL" )
286290
@@ -307,7 +311,8 @@ def test_illegal_trajectory(self):
307311 # Send illegal goal
308312 self .node .get_logger ().info ("Sending illegal goal" )
309313 goal_response = self .call_action (
310- self .jtc_action_client , FollowJointTrajectory .Goal (trajectory = trajectory )
314+ "/scaled_joint_trajectory_controller/follow_joint_trajectory" ,
315+ FollowJointTrajectory .Goal (trajectory = trajectory ),
311316 )
312317
313318 # Verify the failure is correctly detected
@@ -336,12 +341,16 @@ def test_trajectory_scaled(self):
336341 # see https://github.com/ros-controls/ros2_controllers/issues/249
337342 # self.node.get_logger().info("Sending scaled goal without time restrictions")
338343 self .node .get_logger ().info ("Sending goal for robot to follow" )
339- goal_response = self .call_action (self .jtc_action_client , goal )
344+ goal_response = self .call_action (
345+ "/scaled_joint_trajectory_controller/follow_joint_trajectory" , goal
346+ )
340347
341348 self .assertEqual (goal_response .accepted , True )
342349
343350 if goal_response .accepted :
344- result = self .get_result (self .jtc_action_client , goal_response )
351+ result = self .get_result (
352+ "/scaled_joint_trajectory_controller/follow_joint_trajectory" , goal_response
353+ )
345354 self .assertIn (
346355 result .error_code ,
347356 (
@@ -359,12 +368,12 @@ def test_trajectory_scaled(self):
359368 # self.node.get_logger().info("Sending scaled goal with time restrictions")
360369 #
361370 # goal.goal_time_tolerance = Duration(nanosec=10000000)
362- # goal_response = self.call_action(self.jtc_action_client , goal)
371+ # goal_response = self.call_action("/scaled_joint_trajectory_controller/follow_joint_trajectory" , goal)
363372 #
364373 # self.assertEqual(goal_response.accepted, True)
365374 #
366375 # if goal_response.accepted:
367- # result = self.get_result(self.jtc_action_client , goal_response)
376+ # result = self.get_result("/scaled_joint_trajectory_controller/follow_joint_trajectory" , goal_response)
368377 # self.assertEqual(result.error_code, FollowJointTrajectory.Result.GOAL_TOLERANCE_VIOLATED)
369378 # self.node.get_logger().info("Received result GOAL_TOLERANCE_VIOLATED")
370379
@@ -382,19 +391,23 @@ def call_service(self, srv_name, request):
382391 else :
383392 raise Exception (f"Exception while calling service: { future .exception ()} " )
384393
385- def call_action (self , ac_client , g ):
386- future = ac_client .send_goal_async (g )
394+ def call_action (self , action_name , goal ):
395+ self .node .get_logger ().info (f"Sending goal to action server '{ action_name } '" )
396+ future = self .action_clients [action_name ].send_goal_async (goal )
387397 rclpy .spin_until_future_complete (self .node , future )
388398
389399 if future .result () is not None :
390400 return future .result ()
391401 else :
392402 raise Exception (f"Exception while calling action: { future .exception ()} " )
393403
394- def get_result (self , ac_client , goal_response ):
395- future_res = ac_client ._get_result_async (goal_response )
404+ def get_result (self , action_name , goal_response ):
405+ self .node .get_logger ().info (f"Waiting for result for action server '{ action_name } '" )
406+ future_res = self .action_clients [action_name ]._get_result_async (goal_response )
396407 rclpy .spin_until_future_complete (self .node , future_res )
408+
397409 if future_res .result () is not None :
410+ self .node .get_logger ().info (f"Received result { future_res .result ().result } " )
398411 return future_res .result ().result
399412 else :
400413 raise Exception (f"Exception while calling action: { future_res .exception ()} " )
0 commit comments