Files
rtabmap_ros/rtabmap_demos/launch/find_object_demo.launch.py
T

147 lines
6.6 KiB
Python
Raw Normal View History

# Requirements:
# find_object_2d package installed
# Download rosbag:
2026-10-10 12:23:49 -07:00
# * demo_find_object_bag.zip: https://github.com/introlab/rtabmap_ros/releases/download/0.23.13/demo_find_object_bag.zip
#
# Example:
#
# SLAM:
# $ ros2 launch rtabmap_demos find_object_demo.launch.py
#
# Rosbag:
2026-10-10 12:23:49 -07:00
# $ ros2 bag play demo_find_object_bag --clock
#
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch.conditions import IfCondition, UnlessCondition
from launch_ros.actions import Node
from launch_ros.actions import SetParameter
import os
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
localization = LaunchConfiguration('localization')
parameters={
'frame_id':'base_footprint',
'odom_frame_id':'odom',
'odom_tf_linear_variance':0.001,
'odom_tf_angular_variance':0.001,
'subscribe_rgbd':True,
'subscribe_scan':True,
'approx_sync':True,
'sync_queue_size': 10,
# RTAB-Map's internal parameters should be strings
'RGBD/NeighborLinkRefining': 'true', # Do odometry correction with consecutive laser scans
'Reg/Strategy': '1', # 0=Visual, 1=ICP, 2=Visual+ICP
'Reg/Force3DoF': 'true', # 2D SLAM
2026-10-10 12:23:49 -07:00
# The objects find_object_2d detects become landmarks (see find_object_to_landmarks.py,
# which sets their covariance from these, as rtabmap does for its own markers).
# Range and bearing only (GTSAM): the objects' orientation is the least reliable
# part of find_object_2d's estimate. Linear: the range variance (m^2), angular:
# the bearing variance (rad^2).
'Marker/VarianceLinear': '0.001',
'Marker/VarianceAngular': '0.01',
'Marker/VarianceOrientationIgnored': 'true',
'Optimizer/Strategy': '2', # GTSAM
}
remappings=[
('rgb/image', '/camera/data_throttled_image'),
('depth/image', '/camera/data_throttled_image_depth'),
('rgb/camera_info', '/camera/data_throttled_camera_info'),
('scan', '/base_scan')]
config_rviz = os.path.join(
get_package_share_directory('rtabmap_demos'), 'config', 'demo_robot_mapping.rviz'
)
config_find_object = os.path.join(
get_package_share_directory('rtabmap_demos'), 'config', 'find_object.ini'
)
data_find_object = os.path.join(
get_package_share_directory('rtabmap_demos'), 'data', 'books'
)
return LaunchDescription([
# Launch arguments
DeclareLaunchArgument('rtabmap_viz', default_value='false', description='Launch RTAB-Map UI (optional).'),
DeclareLaunchArgument('rviz', default_value='true', description='Launch RVIZ (optional).'),
2026-10-10 12:23:49 -07:00
DeclareLaunchArgument('find_object_gui', default_value='true', description='Show the Find-Object window (false: headless).'),
DeclareLaunchArgument('localization', default_value='false', description='Launch in localization mode.'),
DeclareLaunchArgument('rviz_cfg', default_value=config_rviz, description='Configuration path of rviz2.'),
SetParameter(name='use_sim_time', value=True),
# Nodes to launch
# Uncompress images for find_object
Node(
package='image_transport', executable='republish', name='republish_rgb', output='screen',
2026-10-10 12:23:49 -07:00
# The transports: as arguments up to humble, as parameters from jazzy.
arguments=['compressed', 'raw'],
2026-10-10 12:23:49 -07:00
parameters=[{'in_transport': 'compressed', 'out_transport': 'raw'}],
remappings=[('in/compressed', '/camera/data_throttled_image/compressed'),
('out', '/camera/data_throttled_image')]),
Node(
package='image_transport', executable='republish', name='republish_depth', output='screen',
2026-10-10 12:23:49 -07:00
# The transports: as arguments up to humble, as parameters from jazzy.
arguments=['compressedDepth', 'raw'],
2026-10-10 12:23:49 -07:00
parameters=[{'in_transport': 'compressedDepth', 'out_transport': 'raw'}],
remappings=[('in/compressedDepth', '/camera/data_throttled_image_depth/compressedDepth'),
('out', '/camera/data_throttled_image_depth')]),
Node(
package='rtabmap_sync', executable='rgbd_sync', output='screen',
parameters=[parameters,
{'approx_sync_max_interval': 0.02}],
remappings=remappings),
# SLAM mode:
Node(
condition=UnlessCondition(localization),
package='rtabmap_slam', executable='rtabmap', output='screen',
parameters=[parameters],
remappings=remappings,
arguments=['-d']), # This will delete the previous database (~/.ros/rtabmap.db)
# Localization mode:
Node(
condition=IfCondition(localization),
package='rtabmap_slam', executable='rtabmap', output='screen',
parameters=[parameters,
{'Mem/IncrementalMemory':'False',
'Mem/InitWMWithAllNodes':'True'}],
remappings=remappings),
# Visualization:
Node(
package='rtabmap_viz', executable='rtabmap_viz', output='screen',
condition=IfCondition(LaunchConfiguration("rtabmap_viz")),
parameters=[parameters],
remappings=remappings),
Node(
package='rviz2', executable='rviz2', name="rviz2", output='screen',
condition=IfCondition(LaunchConfiguration("rviz")),
arguments=[["-d"], [LaunchConfiguration("rviz_cfg")]]),
# Find-Object
Node(
package='find_object_2d', executable='find_object_2d', output='screen',
2026-10-10 12:23:49 -07:00
parameters=[{'gui': LaunchConfiguration('find_object_gui'),
'subscribe_depth': True,
'settings_path': config_find_object,
'objects_path': data_find_object}],
remappings=[('rgb/image_rect_color', '/camera/data_throttled_image'),
('depth_registered/image_raw', '/camera/data_throttled_image_depth'),
('depth_registered/camera_info', '/camera/data_throttled_camera_info')]),
2026-10-10 12:23:49 -07:00
# Its detections as landmarks for rtabmap (landmark_detections)
Node(
package='rtabmap_demos', executable='find_object_to_landmarks.py', output='screen',
parameters=[parameters]),
])