Skip to content
  • Home
  • About the Blog
  • About the Author
  • Sitemap

Abdur Rosyid's Blog

Just a few notes on mechanical engineering and robotics

Creating ROS1 Action

July 9, 2021 by Abdur Rosyid

Below are the steps to create a ROS1 action:

Step 1: Add the following in package.xml

roscpp # Use this if the action is in C++
rospy # Use this if the action is in Python
actionlib
std_msgs
message_generation
actionlib_msgs
roscpp # Use this if the action is in C++
rospy # Use this if the action is in Python
actionlib
std_msgs
message_runtime
actionlib_msgs

Step 2: Add the following in CMakeLists.txt

find_package(catkin REQUIRED COMPONENTS
roscpp # Use this if the action is in C++
rospy  # Use this if the action is in Python
std_msgs
message_generation
actionlib_msgs
actionlib
)

add_action_files(FILES ActionFile.action)

generate_messages(DEPENDENCIES actionlib_msgs std_msgs)

catkin_package(
LIBRARIES action_name
CATKIN_DEPENDS std_msgs actionlib_msgs actionlib roscpp
)

include_directories(${catkin_INCLUDE_DIRS})

# SKIP ALL BELOW IF THE ACTION SERVER & CLIENT ARE WRITTEN IN PYTHON

add_executable(action_server src/action_server.cpp)
add_dependencies(action_server ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(action_server ${catkin_LIBRARIES})

add_executable(action_client src/action_client.cpp)
add_dependencies(action_client ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(action_client ${catkin_LIBRARIES})

Step 3: Create a folder called “action” (if you still don’t have it) inside your package folder. And then make the action file (.action) called “ActionFile.action”. For example, if the action is to compute Fibonacci numbers, you may call it “Fibonacci.action” which looks like below:

#goal definition
int32 order
---
#result definition
int32[] sequence
---
#feedback
int32[] sequence

The lines of three dashes above separate between the request variable(s), the result variable(s), and the feedback variable(s).

Step 4: Write the “action_server” node.

Using C++, write the action_server node in a file namely “action_server.cpp”, inside “src” folder of the package. An code example can be found here: http://wiki.ros.org/actionlib_tutorials/Tutorials/SimpleActionServer%28ExecuteCallbackMethod%29

Using Python, write the action_server node in a file namely “action_server.py”, inside “script” folder of the package. An code example can be found here: http://wiki.ros.org/actionlib_tutorials/Tutorials/Writing%20a%20Simple%20Action%20Server%20using%20the%20Execute%20Callback%20%28Python%29

Step 5: Write the “action_client” node.

Using C++, write the action_client node in a file namely “action_client.cpp”, inside “src” folder of the package. An code example can be found here: http://wiki.ros.org/actionlib_tutorials/Tutorials/SimpleActionClient

Using Python, write the action_client node in a file namely “action_server.py”, inside “script” folder of the package. An code example can be found here: http://wiki.ros.org/actionlib_tutorials/Tutorials/Writing%20a%20Simple%20Action%20Client%20%28Python%29

Step 6: Build the package by using “catkin_make” command.

Running the action

After making sure that ROS Master is running (unless roslaunch is used), type the following in the terminal to run the “action_server” node:

For C++ action: rosrun package_name action_server
For Python action: rosrun package_name action_server.py

To call the action, run the “action_client” node:

For C++ action: rosrun package_name action_client
For Python action: rosrun package_name action_client.py

To show the stream of the action feedback:

rostopic echo /action_name/feedback

Post navigation

Previous Post:

ROS Action

Next Post:

ROS Parameters

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • STEM 101
  • Robotics
  • Kinematics
  • Dynamics
  • Control
  • Robot Operating System (ROS)
  • Robot Operating System (ROS2)
  • Software Development
  • Mechanics of Materials
  • Finite Element Analysis
  • Fluid Mechanics
  • Thermodynamics

Recent Posts

  • Pull Request on Github
  • Basics of Git and Github
  • Conda vs Docker
  • A Conda Cheat Sheet
  • Installing NVIDIA GPU Driver on Ubuntu

Archives

  • June 2025
  • July 2021
  • June 2021
  • March 2021
  • September 2020
  • April 2020
  • January 2015
  • April 2014
  • March 2014
  • March 2012
  • February 2012
  • June 2011
  • March 2008
© 2026 Abdur Rosyid's Blog | WordPress Theme by Superbthemes