Read OctoMap file with Robotics System Toolbox

Hello,
I am trying to read OctoMap files like the ones that can be found here: OctoMap datasets
I have the Robotics System Toolbox which comes with the OccupancyMap3D class, but the documentation only shows how to read an OctoMap ROS message. In general, it seems that everything related to occupancy maps is restricted to be used with ROS. Alternatively, I could create a ROS message and fill the data field with the content of the file, however I lack understanding of the OctoMap file format (resolution, additional rgb data, octree).
Does anybody know how to import an OctoMap from file into Matlab?
Thank you in advance

 Accepted Answer

I don't think there's a direct way to read unless you parse the file yourself. As you said, you can either create your own file reader in MATLAB...
... or you can use the octomap_server package to publish a ROS message directly from the file, assuming it's a .bt file, and then subscribe to it from MATLAB.
rosrun octomap_server filename.bt
If it's a one-time thing, I'd recommend saving the OccupancyMap3D object as a .mat file in MATLAB so you can easily reload it later. Else, if the map is dynamically changing, you may as well use ROS pub-sub.
- Sebastian

7 Comments

Hello, First thank you for your suggestion,I want to know the occupation information(gray value) of the .bt file through matlab. Now,I have subscribed to the topic which published by octomap-serve using matlab, but I don't know how to save the information as a .mat file.Can you give me some advice? Thank you in advance
Once you have the ROS message, you can read it with the readOccupancyMap3D function.
Then, whatever OccupancyMap3D object you get you can save to a MAT-file:
>> save myFileName myMapName
- Sebastian
Thanks for your reply, follow your steps, I subscribed the topic published by octomap_server in matlab, but I don't have the ROS message, so I entered load octomap_msgs in matlab,It prompts that the octomap_msgs file cannot be read, the load function can only read files.I just learned ROS soon, so I don't know much about it.I am looking forward to your reply. Thank you.
Once you run octomap_server, you should have 2 topics available according to this Web page.
If you subscribe to either the octomap_binary or octomap_full topics, you can then do:
mapSub = rossubscriber('/octomap_full');
mapMsg = receive(mapSub);
map = readOccupancyMap3D(mapMsg);
show(map)
save mapFile map
- Sebastian
OK, so octomap_server must only send the message once at the beginning and the subscriber in MATLAB is stuck waiting to get a new message that never comes around.
I guess octomap_server seems to have a service to retrieve the latest binary map; else you need to make sure MATLAB is already listening by the time octomap_server publishes the occupancy map.
I'll let you figure that one out since you have it all installed on your system.
Thanks for your help.When I type mapMsg = receive(mapSub), matlab will get into the loop and there will be no result for a long time.The error is as follows
I think I may know the reason of it.I was wrong at the beginning. The topic did not post a message when I rosrun octomap_server filename.what do you think about it?

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!