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

grid_map not working properly on Melodic - Ubuntu 18.04

asked 2019-06-03 19:00:26 -0600

RayROS gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

1

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-04 02:30:34 -0600 )edit

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

RayROS gravatar image RayROS  ( 2019-06-04 06:11:28 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-04 06:17:18 -0600

RayROS gravatar image

updated 2019-06-04 08:04:15 -0600

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})
edit flag offensive delete link more

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-04 06:30:22 -0600 )edit

Thanks for noticing ad sorry for the error but I have been working on this all night. I update the answer :)

RayROS gravatar image RayROS  ( 2019-06-04 06:45:12 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-04 06:49:07 -0600 )edit

Thanks for catching the other parts! I updated the CMake file with all the comments.

RayROS gravatar image RayROS  ( 2019-06-04 08:00:57 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-04 08:03:04 -0600 )edit

Oops! :) Corrected! sorry about that!

RayROS gravatar image RayROS  ( 2019-06-04 08:04:54 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2019-06-03 19:00:26 -0600

Seen: 1,318 times

Last updated: Jun 04 '19