ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Action Header Returns "no such file or directory" When I Include It In cpp.

asked 2020-05-10 10:28:26 -0500

ROSman gravatar image

I'm trying to get a c++ action client example running. When I include the actions header, the console returns "no such file or directory". I'm guessing I did something wrong with the CMakeList.txt. I'm fairly new to ROS and CMake. Below is my console output, c++ action client code, and my CMakeList.txt files.

CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
project(demo_pkg2)

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

add_service_files(
FILES
demo_srv.srv
)

add_action_files(
DIRECTORY action
FILES
demo_action.action
)

generate_messages(
DEPENDENCIES
actionlib_msgs
actionlib
std_msgs
)

catkin_package(
INCLUDE_DIRS include
LIBRARIES demo_pkg2
CATKIN_DEPENDS actionlib actionlib_msgs roscpp std_msgs
DEPENDS system_lib
message_runtime
)

include_directories(
include
${catkin_INCLUDE_DIRS}
)

add_executable(client src/client.cpp)
add_executable(server src/server.cpp)
add_executable(act_client src/act_client.cpp)

add_dependencies(client demo_pkg2_generate_messages_cpp)
add_dependencies(server demo_pkg2_generate_messages_cpp)
add_dependencies(act_client ${PROJECT_NAME}_EXPORTED_TARGETS)

target_link_libraries(client   ${catkin_LIBRARIES})
target_link_libraries(server   ${catkin_LIBRARIES})
target_link_libraries(act_client ${catkin_LIBRARIES})

project.xml

<?xml version="1.0"?>
<package format="2">
   <name>demo_pkg2</name>
   <version>0.0.0</version>
   <description>The demo_pkg2 package</description>
   <maintainer email="daniel@todo.todo">daniel</maintainer>
   <license>TODO</license>
       <build_depend>message_generation</build_depend>
       <exec_depend>message_runtime</exec_depend>
        <buildtool_depend>catkin</buildtool_depend>
        <build_depend>actionlib</build_depend>
        <build_depend>actionlib_msgs</build_depend>
        <build_depend>roscpp</build_depend>
        <build_depend>std_msgs</build_depend>
        <build_export_depend>actionlib</build_export_depend>
        <build_export_depend>actionlib_msgs</build_export_depend>
        <build_export_depend>roscpp</build_export_depend>
        <build_export_depend>std_msgs</build_export_depend>
        <exec_depend>actionlib</exec_depend>
        <exec_depend>actionlib_msgs</exec_depend>
        <exec_depend>roscpp</exec_depend>
        <exec_depend>std_msgs</exec_depend>

      <export>
      </export>
</package>

act_client.cpp

#include <ros/ros.h>
#include <actionlib/client/simple_action_client.h>
#include <actionlib/client/terminal_state.h>
#include <demo_pkg2/demo_action.h>
#include <iostream>

int main(int argc, char **argv)
{

ros::init(argc,argv,"act_client");

//create action client
//true makes client spin its own thread

actionlib::SimpleActionClient<demo_pkg2::demo_action> ac("action_server",true);

ROS_INFO("Waiting for action server to start!");
ac.waitForServer();//wait forever fot the server to start

ROS_INFO("Actio server started, sending goal.");
//send goal to action
demo_pkg2::demo_actionGoal goal;
goal.order = 20; //set the goal
goal.sendGoal(goal); //send the goal to the server

//wait for the action to return

bool finished_before_timeout = ac.waitForResult(ros::Duration(30.0));

if(finshed_before_timeout)
{
    actionlib::SimpleClientGoalState state = ac.goalState();
    ROS_INFO("Action finished: %s",state.toString().c_str());
}
else
{
    ROS_INFO("Action did not finish before the time out.");
    //exit
    return 0;
}
return 1;
}

console output

/home/daniel/catkin_ws/src/demo_pkg2/src/act_client.cpp:4:10: fatal error: demo_pkg2/demo_action.h: No such file or      directory
#include <demo_pkg2/demo_action.h>
      ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
demo_pkg2/CMakeFiles/act_client.dir/build.make:62: recipe for target   '    demo_pkg2/CMakeFiles/act_client.dir/src/act_client.cpp.o' failed
make[2]: *** [demo_pkg2/CMakeFiles/act_client.dir/src/act_client.cpp.o] Error 1
CMakeFiles/Makefile2:1756: recipe for target 'demo_pkg2/CMakeFiles/act_client.dir/all' failed
make[1]: *** [demo_pkg2/CMakeFiles/act_client.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-13 15:26:27 -0500

ipa-jba gravatar image

Hi,

you are missing a set of ${} in your CMakeList. Try changingadd_dependencies(act_client ${PROJECT_NAME}_EXPORTED_TARGETS) toadd_dependencies(act_client ${${PROJECT_NAME}_EXPORTED_TARGETS}).

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-05-10 10:28:26 -0500

Seen: 995 times

Last updated: May 13 '20