EE50237 - Robotics Software 4a
EE50237 - Robotics Software 4a
Software
Dr Rob Wortham
Topics
• Topic Publisher & Topic Subscriber (listener)
• Service Server & Service Client
• Synchronicity, Performance, Scalability
• Remapping names
• Action Server & Action Client with progress feedback
• Define and use our own message types
• Using a launch file
22/01/2024 EE50237 Robotics Software - Lecture 4a 2
Today’s Lecture
• ROS Actions
• Next Lecture
• ROS Message Types
• ROS Launch Files
Timer.action
# Part 1: the goal, to be sent by the client
duration time_to_wait
---
# Part 2: the result, to be sent by the server upon completion
duration time_elapsed
uint32 updates_sent
---
# Part 3: the feedback, to be sent periodically by the server during
# execution.
duration time_elapsed
duration time_remaining
YES
Have we waited
Finish
long enough?
NO
Wait 1 Second
if server.is_preempt_requested():
result = TimerResult()
result.time_elapsed = rospy.Duration.from_sec(time.time() - start_time)
result.updates_sent = update_count
server.set_preempted(result, "Timer preempted")
return
feedback = TimerFeedback()
feedback.time_elapsed = rospy.Duration.from_sec(time.time() - start_time)
feedback.time_remaining = goal.time_to_wait - feedback.time_elapsed
server.publish_feedback(feedback)
update_count += 1
time.sleep(1.0)
result = TimerResult()
result.time_elapsed = rospy.Duration.from_sec(time.time() - start_time)
result.updates_sent = update_count
server.set_succeeded(result, "Timer completed successfully")
rospy.init_node('timer_action_server')
server = actionlib.SimpleActionServer('timer', TimerAction, do_timer, False)
Initialise a ROS Publisher instance server.start()
Register the action server ‘timer’ with auto_start=False rospy.spin()
Start the server, spin until termination.
feedback = TimerFeedback()
Create the feedback info and feedback.time_elapsed = rospy.Duration.from_sec(time.time() - start_time)
send it back to the client feedback.time_remaining = goal.time_to_wait - feedback.time_elapsed
server.publish_feedback(feedback)
update_count += 1
Wait one second (or do
time.sleep(1.0)
something useful)
result = TimerResult()
result.time_elapsed = rospy.Duration.from_sec(time.time() - start_time)
Create the result info. Return result.updates_sent = update_count
control to client server.set_succeeded(result, "Timer completed successfully")
def feedback_cb(feedback):
print('[Feedback] Time elapsed: %f'%(feedback.time_elapsed.to_sec()))
print('[Feedback] Time remaining: %f'%(feedback.time_remaining.to_sec()))
Callback to print feedback
notifications rospy.init_node('timer_action_client')
client = actionlib.SimpleActionClient('timer', TimerAction)
client.wait_for_server()
Initialise the node, wait until there goal = TimerGoal()
is a server we can use goal.time_to_wait = rospy.Duration.from_sec(5.0)
# Uncomment this line to test server-side abort:
Set a 5 second goal time #goal.time_to_wait = rospy.Duration.from_sec(500.0)
• Chapter 5: Actions
• Next Lecture
• ROS messages
• User defined message types
• Using a launch file
Questions?
Ask them on moodle!