Ask Your Question
0

Actionlib Tutorials: cmake can't find Action.h file

asked 2019-01-14 22:53:45 -0500

sethgi gravatar image

updated 2019-01-15 10:44:52 -0500

Hi,

I'm getting started learning actionlib, and have the example from the tutorials working just fine, and I thought I understood it pretty well. I'm trying to implement a second server (Called counter_server, based on a Counter.action file) so I can learn it better, and am having some trouble.

Quick note, running ROS melodic in ubuntu 18.04 in a VMware VM.

When compiling, this is the error I get:

/home/me/catkin_ws/src/actionlib_tutorials/src/counter_server.cpp:3:10: fatal error: actionlib_tutorials/CounterAction.h: No such file or directory

 #include <actionlib_tutorials/CounterAction.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
actionlib_tutorials/CMakeFiles/counter_server.dir/build.make:62: recipe for target 'actionlib_tutorials/CMakeFiles/counter_server.dir/src/counter_server.cpp.o' failed
make[2]: *** [actionlib_tutorials/CMakeFiles/counter_server.dir/src/counter_server.cpp.o] Error 1
CMakeFiles/Makefile2:481: recipe for target 'actionlib_tutorials/CMakeFiles/counter_server.dir/all' failed
make[1]: *** [actionlib_tutorials/CMakeFiles/counter_server.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j1 -l1" failed

I suspect some sort of a cmake error. This is all of my CMakeLists:

cmake_minimum_required(VERSION 2.8.3)
project(actionlib_tutorials)

find_package(catkin REQUIRED COMPONENTS
  actionlib
  actionlib_msgs
  message_generation
  roscpp
  rospy
  std_msgs
)

add_action_files(
    DIRECTORY
    action

    FILES
    Counter.action
    Fibonacci.action
)


generate_messages(
  DEPENDENCIES
  actionlib_msgs   std_msgs
)

catkin_package(
    CATKIN_DEPENDS actionlib_msgs
)


include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
)

add_executable(fibonacci_server src/fibonacci_server.cpp)

target_link_libraries(
  fibonacci_server
  ${catkin_LIBRARIES}
)

add_dependencies(
  fibonacci_server
  ${fibonacci_server_EXPORTED_TARGETS}
    ${catkin_EXPORTED_TARGETS}
)


add_executable(counter_server src/counter_server.cpp)

target_link_libraries(
  counter_server
  ${catkin_LIBRARIES}
)

add_dependencies(
  counter_server
  ${counter_server_EXPORTED_TARGETS}
    ${catkin_EXPORTED_TARGETS}
)

This is the code in counter_server.cpp, but it seems like pretty straightforward C++ and is extremely similar to the code from the tutorial.

#include <ros/ros.h>
#include <actionlib/server/simple_action_server.h>
#include <actionlib_tutorials/CounterAction.h>


class CounterAction{

protected:

  ros::NodeHandle nh_;
  actionlib::SimpleActionServer<actionlib_tutorials::CounterAction> as_;

  std::string action_name_;

  actionlib_tutorials::CounterFeedback feedback_;
  actionlib_tutorial::CounterResult result_

public:

  CounterAction(std::string name): as_(nh, name, boost::bind(&FibonacciAction::executeCB, this, 1),false),
  action_name_(name){
    as_.start();
  }

  ~FibonacciAction(void){}

  void executeCB(const actionlib_tutorials::CounterGoalConstPtr& goal){

    ros::Rate r(1);
    bool success = true;
    int sum = 0;

    ROS_INFO("Starting counter");

    for(int i = 0; i < goal->maxVal; ++i){
      if(as_.isPreeptRequested() || !ros::ok()){
        ROS_INFO("Preempted");
        as_.setPreempted;
        success = false;
        break;
      }
      sum += i;
      feedback_.currentVal = i;
      as_.publishFeedback(feedback_);

      r.sleep();

    }

    if(success){
      result_.sum = sum;
      ROS_INFO("yay did a count");
      as_.setSucceeded(result_);
    }
  }

};

int main(int arcg, char** argv){
  ros::init(argc, argv, "counter");
  CounterAction counter("counter");
  ros::spin();
  return 0;
}



)

I hope you can help! Thanks!

edit retag flag offensive close merge delete

Comments

Can you add the full CMakeList.txt please ? Just a few remarks here :

add_action_files(
    FILES
    Counter.action
        Fibonacci.action
)

It seems to be missing DIRECTORY action

Delb gravatar imageDelb ( 2019-01-15 01:44:42 -0500 )edit

Your executeCB is within the scope of the FibonacciAction class, should be CounterAction. And you have typos here : actionlib_tutorial::CounterResult result_, missing ; and a s at actionlib_tutorials.

Delb gravatar imageDelb ( 2019-01-15 01:46:10 -0500 )edit

in CMakeList, check that the catkin directory is included:

include_directories(include      ${catkin_INCLUDE_DIRS}   )
mali gravatar imagemali ( 2019-01-15 03:15:16 -0500 )edit

I've made all the changed you all suggested (but include_directories(...) was already in my cmakelists) and still nothing! I've uploaded my full cmakelists in the hope it helps. And thanks @Delb for catching some C++ typos, but it of course hadn't gotten to compiling that anyways. Thanks!

sethgi gravatar imagesethgi ( 2019-01-15 10:12:18 -0500 )edit

ok I have no clue what I changed but suddenly it built... disappointing and I can't break it even by undoing stuff a bunch! I did a make clean and rebuild but the files existed in the first case, it just couldn't find them. So it's weird.

sethgi gravatar imagesethgi ( 2019-01-15 14:32:42 -0500 )edit

I've also seen this behavior ( => always failing at the first catkin_make and no error at the second). Does it compiles again if you delete your build and devel folders ?

Delb gravatar imageDelb ( 2019-01-16 03:29:38 -0500 )edit

I've also seen this behavior ( => always failing at the first catkin_make and no error at the second).

typically a symptom of a build script missing add_dependencies(..).

gvdhoorn gravatar imagegvdhoorn ( 2019-01-16 03:31:28 -0500 )edit

Yes, that was exactly one of my issues as the second answer of #q288890 suggested.

Delb gravatar imageDelb ( 2019-01-16 03:36:32 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-01-15 14:33:31 -0500

sethgi gravatar image

updated 2019-01-16 10:10:03 -0500

So, it turns out my dependencies were wrong! Here’s how I found out:

After a make clean, I would build and it would fail, then build again and it worked. So I checked if the files were there, and it only could compile if the files were there before compiling. This indicates bad dependencies. It turns out my exported targets tag was wrong. Instead of:

Counter_server_EXPORTED_TARGETS

It needs to be

${PROJECT_NAME}_EXPORTED_TARGETS

Problem solved, it builds first time after cleaning!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-01-14 22:38:57 -0500

Seen: 185 times

Last updated: Jan 16