Octomap in ROS and ROS2 - ashBabu/Utilities GitHub Wiki

ROS2

  • sudo apt install ros-humble-octomap-server ros-humble-octomap-rviz-plugins
node_octomap_server = Node(
        package='octomap_server',
        executable='octomap_server_node',
        name="octomap_server",
        parameters=[
            {"frame_id": 'map'},
        ],
        remappings=[
            ("cloud_in", arg_cloud_in),
        ],
        output='screen',
    )
    ld.add_action(node_octomap_server)
  • ros2 run octomap_server octomap_saver_node --ros-args -p octomap_path:=map.bt ## saves octomap
  • ros2 run octomap_server octomap_server_node --ros-args -p octomap_path:=map.bt ## loads octomap
  • Open Rviz (ros2 run rviz2 rviz2), Add-->OccupancyGrid-->Topic-->/occupancy_full

ROS

Pre-requisites

sudo apt-get install ros-kinetic-octomap ros-kinetic-octomap-msgs ros-melodic-octomap-ros ros-melodic-octomap-rviz-plugins ros-melodic-octomap-server ros-melodic-octomap-mapping

Instructions for cloning and building

Octomap_server is used to generate and save octomaps as .bt (binary) or .ot (oct-tree) files. Clone octo_mapping and build using catkin_make in the catkin workspace

The procedures for building an octmap for visualization in Rviz are follows:

  1. roslaunch camera_setup start_cameras.launch # to launch the kinect 3D sensor here. Read the readme to create the camera_setup package
  2. roslaunch octomap_server octomap_mapping.launch # 2 things need to be changed 1) frame_id 2) remap cloud_in. check the forked octomap_mapping.launch here
  3. rosrun rviz rviz
  4. Add MarkerArray in Rviz and select the topic as '/occupied_cells_vis_array'. Set the same frame_id above (in 2) in the Global option --> Fixed frame in Rviz
  5. rosrun octomap_server octomap_saver -f map_name.bt (or .ot) # to save the octomap

Visualize octomap in Rviz

  1. Close all the above
  2. roscore
  3. rosrun rviz rviz
  4. rosrun octomap_server octomap_server_node map_name.bt
  5. Add MarkerArray in Rviz and select the topic as '/occupied_cells_vis_array'. Set the same frame_id as it was recorded in the Global option --> Fixed frame in Rviz. There might be a chance that the octomap wont show up. Then write frame id as map which should solve the problem