0
$\begingroup$

Rosanswers logo

Hello, I am following the tutorial on how to create and launch a grid_map. Because I am not familiar with this tool offered by ROS I had to follow it precisely. However, despite that there is an error that is keeping the compiler to build the project. I was afraid that some of the function were deprecated from a previous pull request #67 as explained here but I am not totally sure it could be related. The tutorial I am following is the first one called grid_map/grid_map_demos/src/simple_demo_node.cpp of the link I provided. The errors I am obtaining are highlighted as <-- Error Here in my code.

Below the snipped of code I amusing:

#include <ros/ros.h>
#include <grid_map_ros/grid_map_ros.hpp>
#include <grid_map_msgs/GridMap.h>
#include <cmath>
#include <iostream>

using namespace grid_map;

int main(int argc, char** argv)
{
        // initialize node and publisher
    ros::init(argc, argv, "grid_map_test");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise<grid_map::GridMap>("grid_map", 1, true);

    // create grid map
    GridMap map({"elevation"});
    map.setFrameId("map");
    map.setGeometry(Length(1.2, 2.0), 0.03);
    ROS_INFO("Created map with size %f x %f m (%i x %i cells).",
             map.getLength().x(), map.getLength().y(), // <-- Error Here
             map.getSize()(0), map.getSize()(1)); // <-- Error Here

    // work with grid-map in a loop
    ros::Rate rate(30.0);
    while (nh.ok()) {
        // add data to grid-map.
        ros::Time time = ros::Time::now();
        for(GridMapIterator it(map); !it.isPastEnd(); ++it) // <-- Error Here
        {
            Position position;
            map.getPosition(*it, position);
            map.at("elevation", *it) = -0.04 + 0.2 * std::sin(3.0 * time.toSec() + 5.0 * position.y()) * position.x(); // <-- Error Here
        }

        // publish a grid map
        map.setTimestamp(time.toNSec());
        grid_map_msgs::GridMap msg;
        GridMapRosConverter::toMessage(map, msg);
        pub.publish(msg);
        ROS_INFO_THROTTLE(1.0, "Grid map (timestamp %f) published.", msg.info.header.stamp.toSec());

        // wait for next cycle
        rate.sleep();

    }
    return 0;
}

What I tried so far:

1) I found this which seems to be resolved in here. It seems that my problem could be (but I am not sure) due to CMake and I am including the CMakeLists.txt file below for completeness. Also if I include Eigen3 or if I do not include Eigen3 it does not change the result unfortunately. The code below is the one I am currently using:

cmake_minimum_required(VERSION 2.8.3)
project(map_ros)
add_compile_options(-std=c++11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

find_package(PCL 1.8 REQUIRED)
find_package(octomap REQUIRED)
find_package(catkin REQUIRED COMPONENTS
    roscpp
    sensor_msgs
    std_msgs
    message_generation
    pcl_ros
    pcl_conversions
    geometry_msgs
    nav_msgs
    grid_map_core
    grid_map_ros
    grid_map_cv
    grid_map_filters
    grid_map_loader
    grid_map_msgs
    grid_map_octomap
    grid_map_rviz_plugin
    grid_map_visualization
    cv_bridge
    octomap_msgs
    filters
    eigen3
    )

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES ${PROJECT_NAME}
  DEPENDS
      roscpp
      sensor_msgs
      std_msgs
      message_generation
      pcl_ros
      pcl_conversions
      geometry_msgs
      nav_msgs
      grid_map_core
      grid_map_ros
      grid_map_cv
      grid_map_filters
      grid_map_loader
      grid_map_msgs
      grid_map_octomap
      grid_map_rviz_plugin
      grid_map_visualization
      cv_bridge
      octomap_msgs
      filters
      eigen3
)

###########
## Build ##
###########

include_directories(${catkin_INCLUDE_DIRS})
include_directories(${roscpp_INCLUDE_DIRS})
include_directories(${std_msgs_INCLUDE_DIRS})
include_directories(${OCTOMAP_INCLUDE_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${EIGEN3_INCLUDE_DIRS})

link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
link_libraries(${OCTOMAP_LIBRARIES})

link_directories(${OCTOMAP_INCLUDE_DIRS})
link_directories(${catkin_INCLUDE_DIRS})
link_directories(${EIGEN3_INCLUDE_DIRS})
link_directories(${roscpp_INCLUDE_DIRS})

add_executable(map_test src/map_test.cpp ${SRCS})
target_link_libraries(map_test
    ${catkin_LIBRARIES}
    ${OCTOMAP_LIBRARIES})

2) Adding the following line as advised by the pull out request didn't work:

CATKIN_DEPENDS
  DEPENDS
    #Eigen3
  CFG_EXTRAS ${PROJECT_NAME}-extras.cmake

3) I am not sure if this is a solution but I added from this source the following code at the beginning of the CMake file:

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

4) Always from the same source I added the following lines [because point 3) didnt work] at the the CMake:

find_package(Eigen3 REQUIRED)
SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
IF( NOT EIGEN3_INCLUDE_DIR )
    MESSAGE( FATAL_ERROR "Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.")
ENDIF()
INCLUDE_DIRECTORIES ( "${EIGEN3_INCLUDE_DIR}" )

And with my surprise those lines lead to the following warning: CMake Error at map_ros/CMakeLists.txt:12 (MESSAGE): Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.

And the strange fact is that Eigen3 is installed on my laptop.

In case you would like to see the out of my laptop see:

error

The following messages were received: no member named 'y' in 'Eigen::Matrix<double, 2, 1, 0, 2, 1>' no member named 'x' in 'Eigen::Matrix<double, 2, 1, 0, 2, 1>'

no member named 'y' in 'Eigen::Array<double, 2, 1, 0, 2, 1>' no member named 'x' in 'Eigen::Array<double, 2, 1, 0, 2, 1>'

But I don't know if this could be relevant to my problem.

Compiler Errors:

Error 1 /opt/ros/melodic/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::MD5Sum<M>::value() [with M = grid_map::GridMap]’: /opt/ros/melodic/include/ros/message_traits.h:228:102: required from ‘const char* ros::message_traits::md5sum() [with M = grid_map::GridMap]’ /opt/ros/melodic/include/ros/advertise_options.h:92:39: required from ‘void ros::AdvertiseOptions::init(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&) [with M = grid_map::GridMap; std::__cxx11::string = std::__cxx11::basic_string<char>; uint32_t = unsigned int; ros::SubscriberStatusCallback = boost::function<void(const ros::SingleSubscriberPublisher&)>]’ /opt/ros/melodic/include/ros/node_handle.h:252:7: required from ‘ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool) [with M = grid_map::GridMap; std::__cxx11::string = std::__cxx11::basic_string<char>; uint32_t = unsigned int]’ /home/emanuele/catkin_ws/src/map_ros/src/map_test.cpp:15:77: required from here /opt/ros/melodic/include/ros/message_traits.h:121:28: error: ‘__s_getMD5Sum’ is not a member of ‘grid_map::GridMap’ return M::__s_getMD5Sum().c_str();

Error 2 /home/emanuele/catkin_ws/src/map_ros/src/map_test.cpp:15:77: required from here /opt/ros/melodic/include/ros/message_traits.h:138:30: error: ‘__s_getDataType’ is not a member of ‘grid_map::GridMap’ return M::__s_getDataType().c_str();

Error 3 /home/emanuele/catkin_ws/src/map_ros/src/map_test.cpp:15:77: required from here /opt/ros/melodic/include/ros/message_traits.h:155:39: error: ‘__s_getMessageDefinition’ is not a member of ‘grid_map::GridMap’ return M::__s_getMessageDefinition().c_str();

CONCLUSION: I am left with this possibilities and I am not sure on what the problem could be:

  1. Possible CMake error?

  2. Pull Request not working properly/or deprecated?

  3. Eigen3 error?

I have tried all I was able to think about and I am short in ideas now. If anyone notice something or can point to the right direction to solve this problem it would be great.


Originally posted by RayROS on ROS Answers with karma: 108 on 2019-06-03

Post score: 0


Original comments

Comment by gvdhoorn on 2019-06-04:
Not an answer but some observations:

  • remove the link_directories(..): they should not be needed (if they are, something else is broken)
  • apart from eigen3, all the pkgs that you list under DEPENDS in your catkin_package(..) call should be listed as CATKIN_DEPENDS
  • the eigen3 under DEPENDS should be listed as EIGEN3 (note the full caps).
  • you already have pcl_ros and pcl_conversions listed as COMPONENTS in find_package(catkin ..), so don't do a find_package(PCL 1.8 REQUIRED) separately. There is no need.
  • all the pkgs that you find_package(catkin ..) do not need individual include_directories(..) or find_package(..) statements. Remove them. catkin_INCLUDE_DIRS and catkin_LIBRARIES will be the union of all of them, so it takes care of them.
  • remove the CFG_EXTRAS if you still have it: it's not needed in your pkg

finally: please don't pose screenshots of code. It's all text. Just copy-paste it into your question.

Comment by RayROS on 2019-06-04:
Thanks gvdhoorn for taking the time to read my question. It was indeed a CMake problem and all the observations you listed did solve the problem. My CMake is not complaining anymore and the program is compiling :). I will post the updated CMake response for other users in case needed

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Following the observations of gvdhoorn, I am adding below the CMake file that was causing the non-compilation problem. All the listed observations needs to be followed and applied and below I am providing the correct template for your CMake project in case you need for the future:

cmake_minimum_required(VERSION 2.8.3)
project(map_ros)

add_compile_options(-std=c++11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(octomap REQUIRED)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

find_package(catkin REQUIRED COMPONENTS
    roscpp
    sensor_msgs
    std_msgs
    message_generation
    pcl_ros
    pcl_conversions
    geometry_msgs
    nav_msgs
    grid_map_core
    grid_map_ros
    grid_map_cv
    grid_map_filters
    grid_map_loader
    grid_map_msgs
    grid_map_octomap
    grid_map_rviz_plugin
    grid_map_visualization
    cv_bridge
    octomap_msgs
    filters
    )

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES ${PROJECT_NAME}
  CATKIN_DEPENDS
      roscpp
      sensor_msgs
      std_msgs
      message_generation
      pcl_ros
      pcl_conversions
      geometry_msgs
      nav_msgs
      grid_map_core
      grid_map_ros
      grid_map_cv
      grid_map_filters
      grid_map_loader
      grid_map_msgs
      grid_map_octomap
      grid_map_rviz_plugin
      grid_map_visualization
      cv_bridge
      octomap_msgs
      filters
      DEPENDS EIGEN3
)

###########
## Build ##
###########

include_directories(${catkin_INCLUDE_DIRS})
add_executable(map_test src/map_test.cpp ${SRCS})
target_link_libraries(map_test ${catkin_LIBRARIES})

Originally posted by RayROS with karma: 108 on 2019-06-04

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by gvdhoorn on 2019-06-04:
you have this:

find_package(catkin REQUIRED COMPONENTS [..] Eigen3)

Eigen3 is not a catkin package, so you cannot use find_package(catkin ..) to find it. You have to use find_package(Eigen3 REQUIRED) instead.

Also: why do you still have things like:

include_directories(${roscpp_INCLUDE_DIRS})
include_directories(${std_msgs_INCLUDE_DIRS})
include_directories(${OCTOMAP_INCLUDE_DIRS})
include_directories(${PCL_INCLUDE_DIRS})

those are not needed, as they are included in catkin_INCLUDE_DIRS.

octomap is also a ROS package, so no need to find_package(..) it separately.

Comment by RayROS on 2019-06-04:
Thanks for noticing ad sorry for the error but I have been working on this all night. I update the answer :)

Comment by gvdhoorn on 2019-06-04:
You now still have a separate link_libraries(${OCTOMAP_LIBRARIES}) which should not be necessary either. And you also have it in the target_link_libraries(..) which is not needed.

And if we're being strict: you should add a DEPENDS EIGEN3 to your catkin_package(..) call.

Comment by RayROS on 2019-06-04:
Thanks for catching the other parts! I updated the CMake file with all the comments.

Comment by gvdhoorn on 2019-06-04:
But now you added Eigen3 to find_package(catkin ..): why? It is not a Catkin package.

Other comments:

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})

this doesn't make sense to me: are you including custom .cmake snippets?

find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

I believe it should be EIGEN3_INCLUDE_DIRS (note the S).

set(CMAKE_INCLUDE_CURRENT_DIR ON)

this should also not be required, unless you have headers in the root of your ROS package.

Comment by RayROS on 2019-06-04:
Oops! :) Corrected! sorry about that!

$\endgroup$

Your Answer

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