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

Error when including .h from another package in the same workspace?

asked 2021-07-02 14:45:40 -0500

Eman.m gravatar image

Hello

I have created a package GA_palnner for a custom global planner based on Genetic Algorithm.

Under src of GA_palnner:

CrossPoint.cpp , GA_global_planner_ros.cpp , GenericPathPlanner.cpp , Map.cpp , OccupancyGridMap.cpp , Path.cpp , Population.cpp

Under include of GA_palnner:

CrossPoint.h , GA_global_planner_ros.h , GenericPathPlanner.h , Map.h , OccupancyGridMap.h , Path.h , Population.h

The GA_planner works successfully as global planner plugin and I am able to move my robot in Gazeo using this planner.

Now, I created a package ros_global_planners_experiment to compare the performance of navfn and GA_planner ( gives the path length and running time for each).

In ros_global_planners_experiment_node.cpp

#include <ros/ros.h>
#include <costmap_2d/costmap_2d_ros.h>

#include <navfn/navfn_ros.h> // packageName/headerFile.h
#include "GA_planner/GA_global_planner_ros.h"

Gives me error:

fatal error: GA_global_planner_ros.h: No such file or directory #include "GA_global_planner_ros.h"

This is the package .xml and cMakeLists.txt for both GA_planner and ros_global_planners_experiment

GA_planner package.xml

<?xml version="1.0"?>
<package format="2">
  <name>GA_planner</name>
  <version>0.0.0</version>
  <description>The GA_planner package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  <maintainer email="evadro@todo.todo">evadro</maintainer>


  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>costmap_2d</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>nav_core</build_depend>
  <build_depend>nav_msgs</build_depend>
  <build_depend>pluginlib</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>tf</build_depend>

  <exec_depend>costmap_2d</exec_depend>
  <exec_depend>geometry_msgs</exec_depend>
  <exec_depend>nav_core</exec_depend>
  <exec_depend>nav_msgs</exec_depend>
  <exec_depend>pluginlib</exec_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>tf</exec_depend>


  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->
<nav_core plugin="${prefix}/GA_planner_plugin.xml"/>
  </export>
</package>

GA_planner cMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(GA_planner)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  costmap_2d
  geometry_msgs
  nav_core
  nav_msgs
  pluginlib
  roscpp
  rospy
  std_msgs
  tf
)


catkin_package(
  INCLUDE_DIRS include
#  LIBRARIES GA_planner
  CATKIN_DEPENDS costmap_2d geometry_msgs nav_core nav_msgs pluginlib roscpp rospy std_msgs tf
#  DEPENDS system_lib
)

include_directories(
 include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/GA_planner.cpp
# )

add_library(GA_planner_lib src/GA_global_planner_ros.cpp src/GenericPathPlanner.cpp src/Map.cpp src/OccupancyGridMap.cpp src/Path.cpp src/CrossPoint.cpp src/Population.cpp)

target_link_libraries(GA_planner_lib
    ${catkin_LIBRARIES}
    )
add_dependencies(GA_planner_lib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

ros_global_planners_experiment package.xml

<?xml version="1.0"?>
<package format="2">
  <name>ros_global_planners_experiment</name>
  <version>0.0.0</version>
  <description>The ros_global_planners_experiment package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  <maintainer email="evadro@todo.todo">evadro</maintainer>


  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost ...
(more)
edit retag flag offensive close merge delete

Comments

In what directory have you put your GA_global_planner_ros.h file ? To use std rules in your CMakeLists.txt, it must be in a specific place. I suggest your take a look at any other c++ package.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-07-03 08:06:46 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-04 10:18:34 -0500

404RobotNotFound gravatar image

It isn't said specifically in your information, but usually an include directory for a package is pkg_name/inlcude/pkg_name/header_file.h. From your question, it seems like they are in pkg_name/include/header_file.h. As an example, this is the costmap_2d packages (notice header files are in include/costmap_2d).

So, your header file should be in GA_palnner/include/GA_palnner/GA_global_planner_ros.h.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-07-02 14:45:40 -0500

Seen: 207 times

Last updated: Jul 04 '21