1.4.4 ROS Actions code illustration: Part 2

Course subject(s) Module 1. ROS Essentials

In this lecture, we will learn how to use our newly created action message in code.

Similar to the services in the previous module we have the action server and the action client. This example script has been modified from the actionlib tutorial on the ROS wiki to suit this course context.

The relevant imports and the python class implementation of the action server.
Followed by the defined feedback and result messages. Then we initialise the action server.
After that, we start the action server with the start function.
Now the execute callback function needs to be configured.
In the final part, we first create the ROS node for the action server. Then we instantiate the action server implementation by initialising it with the name of the node.

Now to the action client. First, you have the imports followed by a simple action client. After that, you wait for the server to become available. Then we create a goal message. We can include a blocking functionality or perform other actions while the action is being processed. Lastly, we return the result.

Actions in action!

Don’t forget to source your workspace in every shell first!
$ source $HOME/hrwros_ws/devel/setup.bash

First start roscore in a different terminal.

Then we start the action server and client with the following commands.
$ rosrun hrwros_week1 counter_with_delay_as.py
$ rosrun hrwros_week1 counter_with_delay_ac.py

You can see while the goal is being progressed you can do other things. We can verify this with the following code.
$ rostopic echo /counter_with_delay/feedback

Creative Commons License
Hello (Real) World with ROS - Robot Operating System by TU Delft OpenCourseWare is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://online-learning.tudelft.nl/courses/hello-real-world-with-ros-robot-operating-systems//.
Back to top