from basics.msg import TimerAction, TimerGoal, TimerResult, TimerFeedback # BEGIN PART_1 def feedback_cb(feedback): print('[Feedback] Time elapsed: %f' % (feedback.time_elapsed.to_sec())) print('[Feedback] Time remaining: %f' % (feedback.time_remaining.to_sec())) # END PART_1 rospy.init_node('timer_action_client') client = actionlib.SimpleActionClient('timer', TimerAction) client.wait_for_server() goal = TimerGoal() goal.time_to_wait = rospy.Duration.from_sec(5.0) # BEGIN PART_5 # Uncomment this line to test server-side abort: goal.time_to_wait = rospy.Duration.from_sec(500.0) # END PART_5 # BEGIN PART_2 client.send_goal(goal, feedback_cb=feedback_cb) # END PART_2 # BEGIN PART_4 # Uncomment these lines to test goal preemption: # time.sleep(3.0) # client.cancel_goal() # END PART_4
# 'timer'. # The second argument is the type of the action, # which must also match the server: # TimerAction. # Having created the client, # we tell it to wait for the action server to come up, # which it does by checking for the five advertised topics # that we saw earlier when testing the server. # Similar to rospy.wait_for_service(), # which we used to wait for a service to be ready, # SimpleActionClient.wait_for_server() will block until # the server is ready: goal = TimerGoal() # Now we create a goal of type TimerGoal # and fill in the amount of time we want the goal.time_to_wait = rospy.Duration.from_sec( 5.0) # timer to wait, which is five seconds. client.send_goal(goal) # Then we send the goal, # which causes the transmission # of the goal message to the server: client.wait_for_result() # Next, we wait for a result from the server. # If things are working properly, we expect to # block here for about five seconds. print( 'Time elapsed: %f' % (client.get_result().time_elapsed.to_sec())) # After the result comes in, # we use get_result() to retrieve it # from within the client object and