0
$\begingroup$

Rosanswers logo

I have a package called "motor_driver" that has a 'src' folder and an 'include' folder along with the CMakeLists.txt and the Package.xml. In the 'src' folder I have a file called ego_points.cpp and in the 'include' folder i have a header file called motor_driver.h.

In the ego_points.cpp file, I include the motor_driver.h file but when I run catkin_make in my workspace I get the following error:

/home/student/Desktop/Naes_Thesis/src/motor_driver/src/ego_points.cpp:7:26: fatal error: motor_driver.h: No such file or directory  
    #include "motor_driver.h"
                             ^
    compilation terminated.
    make[2]: *** [motor_driver/CMakeFiles/motor_driver_node.dir/src/ego_points.cpp.o] Error 1
    make[1]: *** [motor_driver/CMakeFiles/motor_driver_node.dir/all] Error 2
    make: *** [all] Error 2
    Invoking "make -j8 -l8" failed

My CMakeLists.txt and my ego_points.cpp are provided below. Could someone please tell me what I am doing wrong? Thank you in advance.

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(motor_driver)

find_package(catkin REQUIRED COMPONENTS
  rplidar_ros
  roscpp
  serial
  std_msgs
  sensor_msgs
  message_generation
)

add_message_files(FILES
  Motor_speeds.msg
  cartesian.msg
)

generate_messages(DEPENDENCIES
  std_msgs
  sensor_msgs
  motor_driver
)

catkin_package(
     INCLUDE_DIRS include
     CATKIN_DEPENDS rospy roscpp serial std_msgs message_runtime rplidar_ros sensor_msgs
)

include_directories(
   /src
   /launch
   /include
   ${catkin_INCLUDE_DIRS}
)

add_executable(${PROJECT_NAME}_node src/ego_points.cpp)
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES})

add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

install(TARGETS ${PROJECT_NAME}_node
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY include 
   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
   FILES_MATCHING PATTERN "*.h"
)

install(FILES
ego_points.launch
   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

ego_points.cpp:

#include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"
#include "iostream"
#include "string"
#include "motor_driver/Motor_speeds.h"
#include "motor_driver/cartesian.h"
#include "motor_driver.h"

using namespace std;
using namespace motor_driver;

Points p1;

int main(int argc, char** argv) {
        ros::init(argc, argv, "motor_driver_node");
        ros::NodeHandle nh;
    ros::Subscriber sub;
    p1 = new Points();
    ros::Rate r(1);
        while (ros::ok) {
                sub = nh.subscribe<sensor_msgs::LaserScan>("/scan",10, &p1.ScanCallback);
        cout << "This is in the main loop" << endl;
        cout << "This is the first value of p1 scanned data: " << p1.scannedData[0] << endl; 
        r.sleep();
                ros::spin();
    }
    return 0;
}

Originally posted by tylernaes on ROS Answers with karma: 23 on 2017-05-27

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I think the bigger problem here is that the include path isn't setup correctly:

include_directories(
   /src
   /launch
   /include
   ...
)

these are all absolute paths, and I doubt the OP has his headers in a dir called include in the root of his partition.

This should be enough:

include_directories(
   include
   ${catkin_INCLUDE_DIRS}
)

The paths in your CMakeLists.txt are relative to the file itself. Since CMakeLists.txt is in the root of your package -- as is your include directory -- specifying include is enough.


Originally posted by gvdhoorn with karma: 86574 on 2017-05-28

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by gvdhoorn on 2017-05-28:
Also: @tylernaes: src and launch are not supposed to be on the include path (src maybe in certain special situations, but not for a simple package/node).

Comment by gvdhoorn on 2017-05-28:
Btw: whether the suggestion of @Haibo works depends on whether you created a subdir called motor_driver in your include directory. If not, then leave off the motor_driver/ prefix.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.