Actions

3.5. Actions#

Actions are yet another form of messaging between nodes. It is primarily intended for running large tasks with different moving parts. They also utilize a lot of the features we have already covered in this section beforehand!

Actions are very similar to services, and they are, in fact, built on topics and services too. The difference between actions and services are that actions come with the benefit of being preemptable, meaning you can cancel them while they are executing. They also provide a steady feedback loop, which services do not with their call-response model.

Although it seems like it may be complicated at first glance, actions are actually straightforward. They have three phases:

Goal Phase: An action client sends out a goal, which simply states what they want to be accomplished. Through the goal service, the action server receives the goal. It sends it back to the action client through a response. A response request can be sent after this as well.

Feedback Phase: While the action is being performed, the action server sends a constant stream of updates about its progress and current status in the form of a feedback topic.

Result Phase: After the action server has finished its work, a result is sent back to the action client through the result service, thus ending the exchange.

ROS2 Program Service ROS2 Action Example (Courtesy of ROS2 Documentation)

3.6. Review Quiz#