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

Octomap Navigation? How to?

asked 2018-03-23 09:02:12 -0600

RoboRos gravatar image

updated 2018-03-24 05:35:57 -0600

How to use octomap for navigation?

After completing mapping process, i have a map in ".bt" or ".ot" format. Now i want to do amcl on it (say gmapping). But gmapping requires ".pgm" map format. In this case how come i use the map from octomap to do the navigation. I am unable to understand how to acheive this by reading the documentation.

Can someone please help.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2018-03-27 00:44:49 -0600

dljubic gravatar image

updated 2018-04-01 06:40:52 -0600

Hello RoboRos,

this is actually a very interesting question.
There exists a C++ library that could help you with your task. It is called grid_map. As stated on the link provided, the grid_map is:

... a C++ library with ROS interface to manage two-dimensional grid maps with multiple data layers. It is designed for mobile robotic mapping to store data such as elevation, variance, color, friction coefficient, foothold quality, surface normal, traversability etc.

Since using grid maps would be an entirely different topic, I will try to keep it short as possible by pointing out that there is a demonstration of an octomap conversion provided here. After installing the grid_map package, just change the path in the given launch file to point to your map - it will give you a quick demonstration of just what you could do with it.

However, I would advise you to play a bit with the package since the entire concept of grip maps is very interesting and above all, very useful.

If you have any further question, feel free to ask.

EDIT: To save the image of the conversion, in grid_map_demos/src/OctomapToGridmapDemo.cpp add the following lines of code:

#include <opencv2/imgcodecs.hpp>
#include "grid_map_cv/grid_map_cv.hpp"

You need to include opencv in order to use imwrite and grid_map_cv is needed, because it offers the function for grid map to image conversion. Then, find this part (it already exists):

// Publish as grid map.
grid_map_msgs::GridMap gridMapMessage;
grid_map::GridMapRosConverter::toMessage(map_, gridMapMessage);
gridMapPublisher_.publish(gridMapMessage);

At that point, grid map is already constructed and you can save it by adding the following:

cv::Mat map_img;
grid_map::GridMapCvConverter::toImage<unsigned char,1>(map_, "elevation", CV_8UC1, map_img);
cv::imwrite("/home/<username>/octomap_occupancy.pgm", map_img);

You create a standard OpenCV Mat object, call the template function for grid map conversion with all the arguments and then just save the resulting image. toImage function declaration is:

template<typename Type_, int NChannels_>
static bool toImage(const grid_map::GridMap& gridMap, const std::string& layer, const int encoding, cv::Mat& image)
edit flag offensive delete link more

Comments

Hi, Thanks for your response. This is really cool. However this is just downprojecting to a 2d map, right?

Not a full navigation solution. I am not able to save it in some other format e.g .pgm. I mean, with this i am not able to publish map node. I can acquire map from projected_map:=map anywayz

RoboRos gravatar image RoboRos  ( 2018-03-27 09:59:52 -0600 )edit

however i'll have to say that i am stunned by the quality of the map outputted by gridmap.

RoboRos gravatar image RoboRos  ( 2018-03-27 10:00:39 -0600 )edit

@ddljubic any help would be appreciated....!!!!

RoboRos gravatar image RoboRos  ( 2018-03-28 05:14:45 -0600 )edit

Sorry for the late response, I am quite busy these days. I don't have time for the next few days to write and post a solution. In the meantime, you could take a look at the grid_map_cv folder, because grid maps provide us with the ability to transform between OpenCV formats and grid maps.

dljubic gravatar image dljubic  ( 2018-03-28 14:57:47 -0600 )edit

@RoboRos I have edited my answer and added the code. Please let me know if it helps!

dljubic gravatar image dljubic  ( 2018-04-01 06:43:28 -0600 )edit

@dljubic Thank u for your response. Map has been saved in .pgm. Thanks alot for your help!!:)

RoboRos gravatar image RoboRos  ( 2018-04-03 09:05:52 -0600 )edit
1

@RoboRos Sorry for the slow answering and I am glad to help! :)

dljubic gravatar image dljubic  ( 2018-04-07 06:42:38 -0600 )edit

I didn't know about the grid_map package, very useful! thanks!

h3ct0r gravatar image h3ct0r  ( 2020-01-23 21:21:57 -0600 )edit
0

answered 2019-01-21 14:08:47 -0600

NickCitizen gravatar image
edit flag offensive delete link more
0

answered 2018-04-26 08:48:16 -0600

RoboRos gravatar image

updated 2018-04-26 08:48:43 -0600

Easy way to do this is by just using map_server.

rosrun map_server map_saver -f map_name.pgm (and 2d mapping topic from octomap)

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2018-03-23 09:02:12 -0600

Seen: 4,380 times

Last updated: Jan 21 '19