We will go over how to write launch files to run the realsense camera node, rtabmap node, and aruco/head pose script.
Create a package called rs_rtab to run launch files:
catkin_create_pkg rs_rtab std_msgs rospy roscpp
Make folders for the launch files and the aruco pose estimation script:
mkdir launch
mkdir scripts
Mapping Mode:
<?xml version="1.0"?>
<launch>
<!-- Include the RealSense camera launch file -->
<include file="$(find realsense2_camera)/launch/rs_camera.launch">
<!-- Pass necessary arguments if required -->
<arg name="align_depth" value="true" />
<arg name="enable_sync" value="true" />
</include>
<!-- Include the RTAB-Map launch file for mapping mode -->
<include file="$(find rtabmap_launch)/launch/rtabmap_new.launch">
<!-- Pass RTAB-Map arguments for mapping mode -->
<arg name="rtabmap_args" value="--delete_db_on_start --Grid/NoiseFilteringRadius 0.15 --Grid/NoiseFilteringMinNeighbors 2 --Grid/DepthMax 3" />
<!-- Pass the camera topics -->
<arg name="depth_topic" value="/camera/aligned_depth_to_color/image_raw" />
<arg name="rgb_topic" value="/camera/color/image_raw" />
<arg name="camera_info_topic" value="/camera/color/camera_info" />
<!-- Pass approx_sync parameter for synchronized topics -->
<arg name="approx_sync" value="true" />
<!-- Enable RTAB-Map's incremental memory to build a map -->
<param name="Mem/IncrementalMemory" value="true" /> <!-- Enable map generation -->
<param name="Rtabmap/Localize" value="false" /> <!-- Disable localization (we're mapping, not localizing) -->
</include>
<!-- Launch RViz for visualization -->
<node name="rviz" pkg="rviz" type="rviz" />
</launch>
Localization Mode:
<?xml version="1.0"?>
<launch>
<!-- Include the RealSense camera launch file -->
<include file="$(find realsense2_camera)/launch/rs_camera.launch">
<!-- Pass necessary arguments if required -->
<arg name="align_depth" value="true" />
<arg name="enable_sync" value="true" />
</include>
<!-- Include the RTAB-Map launch file for localization mode -->
<include file="$(find rtabmap_launch)/launch/rtabmap_new.launch">
<!-- Localization Mode -->
<arg name="localization" default="true"/>
<arg name="rtabmap_args" value="--Grid/NoiseFilteringRadius 0.15 --Grid/NoiseFilteringMinNeighbors 2 --Grid/DepthMax 3" />
<param if="$(arg localization)" name="Mem/IncrementalMemory" type="string" value="false"/>
<param name="Mem/InitWMWithAllNodes" type="string" value="$(arg localization)"/>
<param name="Mem/IncrementalMemory" value="false" /> <!-- Disable incremental memory for localization -->
<param name="RGBD/Thread/Enabled" value="true" /> <!-- Enable processing thread -->
<!-- Pass the camera topics -->
<arg name="depth_topic" value="/camera/aligned_depth_to_color/image_raw" />
<arg name="rgb_topic" value="/camera/color/image_raw" />
<arg name="camera_info_topic" value="/camera/color/camera_info" />
<!-- Pass approx_sync parameter for synchronized topics -->
<arg name="approx_sync" value="true" />
<!-- Prevent resetting the database -->
<param name="Rtabmap/DatabasePath" value="~/.ros/rtabmap.db" /> <!-- Point to the pre-existing map database -->
<param name="Rtabmap/SaveData" value="true" /> <!-- Prevent overwriting the map -->
</include>
<!-- Run the ArUco pose detection Python script -->
<node name="run_aruco_pose_detection" pkg="rs_rtab" type="aruco_cube_pose.py" output="screen" />
<!-- Launch RViz for visualization -->
<node name="rviz" pkg="rviz" type="rviz" />
</launch>
Make sure you already mapped the environment before running the localization script.
To run these launch files run:
roslaunch mapping.launch
roslaunch localization.launch