Actionlib Tutorials: cmake can't find Action.h file
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!
Can you add the full
CMakeList.txt
please ? Just a few remarks here :It seems to be missing
DIRECTORY action
Your executeCB is within the scope of the FibonacciAction class, should be CounterAction. And you have typos here :
actionlib_tutorial::CounterResult result_
, missing;
and as
at actionlib_tutorials.in CMakeList, check that the catkin directory is included:
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!
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.
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
anddevel
folders ?typically a symptom of a build script missing
add_dependencies(..)
.Yes, that was exactly one of my issues as the second answer of #q288890 suggested.
See my edited answer! Pretty much what y’all were saying