grid_map not working properly on Melodic - Ubuntu 18.04
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 ...
Not an answer but some observations:
link_directories(..)
: they should not be needed (if they are, something else is broken)eigen3
, all the pkgs that you list underDEPENDS
in yourcatkin_package(..)
call should be listed asCATKIN_DEPENDS
eigen3
underDEPENDS
should be listed asEIGEN3
(note the full caps).pcl_ros
andpcl_conversions
listed asCOMPONENTS
infind_package(catkin ..)
, so don't do afind_package(PCL 1.8 REQUIRED)
separately. There is no need.find_package(catkin ..)
do not need individualinclude_directories(..)
orfind_package(..)
statements. Remove them.catkin_INCLUDE_DIRS
andcatkin_LIBRARIES
will be the union of all of them, so it takes care of them.CFG_EXTRAS
if you still have it: it's not needed in your pkgfinally: please don't pose screenshots of code. It's all text. Just copy-paste it into your question.
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. MyCMake
is not complaining anymore and the program is compiling :). I will post the updatedCMake
response for other users in case needed