2024-09-04 00:46:44 -07:00
# Requirements:
# A ZED camera
# Install zed ros2 wrapper package (https://github.com/stereolabs/zed-ros2-wrapper)
# Example:
# $ ros2 launch rtabmap_examples zed.launch.py camera_model:=zed2i
import os
from ament_index_python.packages import get_package_share_directory
2024-09-05 21:05:50 -07:00
from launch import LaunchDescription , LaunchContext
2024-09-04 19:38:05 -07:00
from launch.actions import DeclareLaunchArgument
2024-09-04 00:46:44 -07:00
from launch_ros.actions import Node
2024-09-05 21:05:50 -07:00
from launch.actions import IncludeLaunchDescription , OpaqueFunction
2024-09-04 00:46:44 -07:00
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
2024-09-04 19:38:05 -07:00
from launch.conditions import UnlessCondition
2024-09-04 00:46:44 -07:00
import tempfile
2024-09-05 21:05:50 -07:00
parameters = []
remappings = []
def launch_setup ( context : LaunchContext , * args , ** kwargs ):
2024-09-04 00:46:44 -07:00
# Hack to override grab_resolution parameter without changing any files
with tempfile . NamedTemporaryFile ( mode = 'w+t' , delete = False ) as zed_override_file :
zed_override_file . write ( "--- \n " +
"/**: \n " +
" ros__parameters: \n " +
" general: \n " +
" grab_resolution: 'VGA'" )
parameters = [{ 'frame_id' : 'zed_camera_link' ,
'subscribe_rgbd' : True ,
'approx_sync' : False ,
'wait_imu_to_init' : True }]
remappings = [( 'imu' , '/zed/zed_node/imu/data' )]
2024-09-05 21:05:50 -07:00
if LaunchConfiguration ( 'use_zed_odometry' ) . perform ( context ) in [ "True" , "true" ]:
2024-09-04 19:38:05 -07:00
remappings . append (( 'odom' , '/zed/zed_node/odom' ))
2024-09-05 21:05:50 -07:00
else :
parameters . append ({ 'subscribe_odom_info' : True })
return [
2024-09-04 00:46:44 -07:00
# Launch camera driver
IncludeLaunchDescription (
PythonLaunchDescriptionSource ([ os . path . join (
get_package_share_directory ( 'zed_wrapper' ), 'launch' ),
'/zed_camera.launch.py' ]),
2024-09-05 21:05:50 -07:00
launch_arguments = { 'camera_model' : LaunchConfiguration ( 'camera_model' ),
'ros_params_override_path' : zed_override_file . name ,
'publish_tf' : LaunchConfiguration ( 'use_zed_odometry' ),
'publish_map_tf' : 'false' } . items (),
2024-09-04 00:46:44 -07:00
),
2024-11-30 17:28:16 -08:00
# Sync rgb/depth/camera_info together
2024-09-04 00:46:44 -07:00
Node (
package = 'rtabmap_sync' , executable = 'rgbd_sync' , output = 'screen' ,
parameters = parameters ,
remappings = [( 'rgb/image' , '/zed/zed_node/rgb/image_rect_color' ),
( 'rgb/camera_info' , '/zed/zed_node/rgb/camera_info' ),
( 'depth/image' , '/zed/zed_node/depth/depth_registered' )]),
# Visual odometry
Node (
package = 'rtabmap_odom' , executable = 'rgbd_odometry' , output = 'screen' ,
2024-09-05 21:05:50 -07:00
condition = UnlessCondition ( LaunchConfiguration ( 'use_zed_odometry' )),
2024-09-04 00:46:44 -07:00
parameters = parameters ,
2024-09-04 19:38:05 -07:00
remappings = remappings ,),
2024-09-04 00:46:44 -07:00
# VSLAM
Node (
package = 'rtabmap_slam' , executable = 'rtabmap' , output = 'screen' ,
parameters = parameters ,
remappings = remappings ,
arguments = [ '-d' ]),
# Visualization
Node (
package = 'rtabmap_viz' , executable = 'rtabmap_viz' , output = 'screen' ,
parameters = parameters ,
remappings = remappings )
2024-09-05 21:05:50 -07:00
]
def generate_launch_description ():
return LaunchDescription ([
# Launch arguments
DeclareLaunchArgument (
'use_zed_odometry' , default_value = 'false' ,
description = 'Use zed \' s computed odometry instead of using rtabmap \' s odometry.' ),
2024-11-30 17:28:16 -08:00
DeclareLaunchArgument (
'camera_model' , default_value = '' ,
description = "[REQUIRED] The model of the camera. Using a wrong camera model can disable camera features. Valid choices are: ['zed', 'zedm', 'zed2', 'zed2i', 'zedx', 'zedxm', 'virtual']" ),
2024-09-05 21:05:50 -07:00
OpaqueFunction ( function = launch_setup )
2024-09-04 00:46:44 -07:00
])