[ROS Q&A] 131 – Compilation error in ROS Action Server

Compilation-error-in-ROS-Action-Server

Written by Alberto Ezquerro

25/06/2018

 

In this video we are going to see why a user gets a compilation error when trying to compile his ROS Action Server node.

This is a video trying to answer the following question posted at the ROS answers forum: https://answers.ros.org/question/294052/compilation-error-in-ros-action-server-code/

Step 1. Create a project in ROS Development Studio(ROSDS)

ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here. Let’s create a new project and call it testing_action.

Step 2. Create package

At first, let’s create the package with dependencies

cd ~/catkin_ws/src
catkin_create_pkg test_action roscpp actionlib actionlib_msgs robot_calibration_msgs

Then we create a file called action_code.cpp under test_action/src folder with the following content from the question

#include <ros/ros.h>
#include <actionlib/server/simple_action_server.h>
#include <robot_calibration_msgs/GripperLedCommandAction.h>

typedef actionlib::SimpleActionServer<robot_calibration_msgs::GripperLedCommandAction> led_actn_srvr_t;

class led_action
{

ros::NodeHandle nh;
led_actn_srvr_t ls;
std::string action_name;
public:

led_action(std::string name):
    ls(nh, name, boost::bind(&led_action::execute_cb, this, _1), false),
    action_name(name)
{
    ls.start();
}
void execute_cb(const robot_calibration_msgs::GripperLedCommandActionConstPtr &action)
{
}
};

int main(int argc, char** argv)
{
    return 0;
}

To compile the code, we have to add the following code into BUILD part of the CMakeLists.txt file

add_executable(action_code src_action_code.cpp)
add_dependencies(action_code ${action_code_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(action_code
  ${catkin_LIBRARIES}
)

If we try to compile the code with the following command

cd ~/catkin_ws
catkin_make

We got some error.

Step 3. Solve the problem

It turns out the actionlib generates topics for us in the following format

GripperLedCommandAction

But inside the code, we have to directly use

GripperLedCommand…

So we only have to change one line in the source file to make it work

...
void execute_cb(const robot_calibration_msgs::GripperLedCommandGoalConstPtr &action)
...

Then it compiles successfully!

 

 

Edit by: Tony Huang

// RELATED LINKS

▸ Original question: https://answers.ros.org/question/294052/compilation-error-in-ros-action-server-code/
Robot Ignite Academy
ROS Basics in 5 days (C++)
ROS Development Studio (RDS)


Feedback

Did you like this video? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

Topics: ROS Action
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This