2023-01-16 16:26:53 -08:00
# Requirements:
# A realsense D435i
# Install realsense2 ros2 package (ros-$ROS_DISTRO-realsense2-camera)
# Example:
2023-02-26 18:05:08 -08:00
# $ ros2 launch rtabmap_examples realsense_d435i_stereo.launch.py
2025-11-01 13:09:39 -07:00
#
#
#
#
# VINS-Fusion example:
# Add to your ros2 workspace the package https://github.com/zinuok/VINS-Fusion-ROS2
# Apply this patch https://gist.github.com/matlabbe/ebbb343cd744da9d6d6d6ded2e1557fd
# -> Revert "#define USE_GPU" change if you want to build VINS-Fusion with GPU support.
# That may be counterintuitive, but we need to build VINS-Fusion first, then rebuild rtabmap with VINS-Fusion support.
# -> in your ros2 workspace, do "colcon build --packages-select vins"
# -> go back under rtabmap library repo, then rebuild/install with "cmake -DWITH_VINS_FUSION=ON ..."
# -> do "colcon build" in your ros2 workspace again to rebuild rtabmap_ros
# $ ros2 launch rtabmap_examples realsense_d435i_stereo.launch.py odom_args:="--Odom/Strategy 9 OdomVINSFusion/ConfigPath ~/ros2_ws/src/VINS-Fusion-ROS2/config/realsense_d435i/realsense_stereo_imu_config.yaml"
# -> set "imu: 1" in realsense_stereo_imu_config.yaml to do stereo inertial odometry, otherwise only stereo odometry is done.
#
2024-09-04 00:46:44 -07:00
import os
from ament_index_python.packages import get_package_share_directory
2023-01-16 16:26:53 -08:00
from launch import LaunchDescription
2024-09-04 00:46:44 -07:00
from launch_ros.actions import Node , SetParameter
from launch.actions import IncludeLaunchDescription
2024-11-30 17:28:16 -08:00
from launch.actions import DeclareLaunchArgument , IncludeLaunchDescription
2024-09-04 00:46:44 -07:00
from launch.launch_description_sources import PythonLaunchDescriptionSource
2024-11-30 17:28:16 -08:00
from launch.substitutions import LaunchConfiguration
2023-01-16 16:26:53 -08:00
def generate_launch_description ():
2025-10-19 17:02:25 -07:00
parameters = {
2023-01-16 16:26:53 -08:00
'frame_id' : 'camera_link' ,
'subscribe_stereo' : True ,
'subscribe_odom_info' : True ,
2025-10-19 17:02:25 -07:00
'wait_imu_to_init' : True }
2023-01-16 16:26:53 -08:00
remappings = [
( 'imu' , '/imu/data' ),
( 'left/image_rect' , '/camera/infra1/image_rect_raw' ),
( 'left/camera_info' , '/camera/infra1/camera_info' ),
( 'right/image_rect' , '/camera/infra2/image_rect_raw' ),
( 'right/camera_info' , '/camera/infra2/camera_info' )]
return LaunchDescription ([
2024-11-30 17:28:16 -08:00
# Launch arguments
DeclareLaunchArgument (
'unite_imu_method' , default_value = '2' ,
description = '0-None, 1-copy, 2-linear_interpolation. Use unite_imu_method:="1" if imu topics stop being published.' ),
2024-09-04 00:46:44 -07:00
#Hack to disable IR emitter
SetParameter ( name = 'depth_module.emitter_enabled' , value = 0 ),
2025-10-19 17:02:25 -07:00
DeclareLaunchArgument (
'args' , default_value = '' ,
description = 'Extra arguments set to rtabmap and odometry nodes.' ),
DeclareLaunchArgument (
'odom_args' , default_value = '' ,
description = 'Extra arguments just for odometry node. If the same argument is already set in \" args \" , it will be overwritten by the one in \" odom_args \" .' ),
2024-09-04 00:46:44 -07:00
# Launch camera driver
IncludeLaunchDescription (
PythonLaunchDescriptionSource ([ os . path . join (
get_package_share_directory ( 'realsense2_camera' ), 'launch' ),
'/rs_launch.py' ]),
2024-10-17 00:04:25 -04:00
launch_arguments = { 'camera_namespace' : '' ,
'enable_gyro' : 'true' ,
2024-09-04 00:46:44 -07:00
'enable_accel' : 'true' ,
2024-11-30 17:28:16 -08:00
'unite_imu_method' : LaunchConfiguration ( 'unite_imu_method' ),
2024-09-04 00:46:44 -07:00
'enable_infra1' : 'true' ,
'enable_infra2' : 'true' ,
'enable_sync' : 'true' } . items (),
),
2023-01-16 16:26:53 -08:00
Node (
2023-02-26 18:05:08 -08:00
package = 'rtabmap_odom' , executable = 'stereo_odometry' , output = 'screen' ,
2025-10-19 17:02:25 -07:00
parameters = [ parameters ],
arguments = [ LaunchConfiguration ( "args" ), LaunchConfiguration ( "odom_args" )],
2023-01-16 16:26:53 -08:00
remappings = remappings ),
Node (
2023-02-26 18:05:08 -08:00
package = 'rtabmap_slam' , executable = 'rtabmap' , output = 'screen' ,
2025-10-19 17:02:25 -07:00
parameters = [ parameters ],
2023-01-16 16:26:53 -08:00
remappings = remappings ,
2025-10-19 17:02:25 -07:00
arguments = [ '-d' , LaunchConfiguration ( "args" )]),
2023-01-16 16:26:53 -08:00
Node (
2023-02-26 18:05:08 -08:00
package = 'rtabmap_viz' , executable = 'rtabmap_viz' , output = 'screen' ,
2025-10-19 17:02:25 -07:00
parameters = [ parameters ,
{ 'odometry_node_name' : "stereo_odometry" }],
2023-01-16 16:26:53 -08:00
remappings = remappings ),
# Compute quaternion of the IMU
Node (
package = 'imu_filter_madgwick' , executable = 'imu_filter_madgwick_node' , output = 'screen' ,
parameters = [{ 'use_mag' : False ,
'world_frame' : 'enu' ,
'publish_tf' : False }],
remappings = [( 'imu/data_raw' , '/camera/imu' )]),
])