mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-04 08:47:45 +08:00
144 lines
5.4 KiB
Python
144 lines
5.4 KiB
Python
# Example:
|
|
#
|
|
# Bringup turtlebot3:
|
|
# $ export TURTLEBOT3_MODEL=waffle
|
|
# $ export LDS_MODEL=LDS-01
|
|
# $ ros2 launch turtlebot3_bringup robot.launch.py
|
|
#
|
|
# SLAM:
|
|
# $ ros2 launch rtabmap_demos turtlebot3_rgbd_fake_scan.launch.py
|
|
#
|
|
# Navigation (install nav2_bringup package):
|
|
# $ ros2 launch nav2_bringup navigation_launch.py
|
|
# $ ros2 launch nav2_bringup rviz_launch.py
|
|
#
|
|
# Teleop:
|
|
# $ ros2 run turtlebot3_teleop teleop_keyboard
|
|
|
|
from launch import LaunchDescription
|
|
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
|
|
from launch.substitutions import LaunchConfiguration
|
|
from launch.conditions import IfCondition, UnlessCondition
|
|
from launch_ros.actions import Node
|
|
|
|
|
|
def generate_launch_description():
|
|
|
|
use_sim_time = LaunchConfiguration('use_sim_time')
|
|
localization = LaunchConfiguration('localization')
|
|
|
|
parameters={
|
|
'frame_id':'base_footprint',
|
|
'use_sim_time':use_sim_time,
|
|
'subscribe_rgbd':True,
|
|
'subscribe_scan_cloud':True,
|
|
'use_action_for_goal':True,
|
|
'scan_cloud_is_2d': True,
|
|
# RTAB-Map's parameters should be strings:
|
|
'Reg/Strategy':'1',
|
|
'Reg/Force3DoF':'true',
|
|
'Optimizer/GravitySigma':'0' # Disable imu constraints (we are already in 2D)
|
|
}
|
|
|
|
remappings=[
|
|
('rgb/image', '/camera/image_raw'),
|
|
('rgb/camera_info', '/camera/camera_info'),
|
|
('depth/image', '/camera/depth/image_raw'),
|
|
('scan_cloud', 'assembled_cloud')]
|
|
|
|
return LaunchDescription([
|
|
|
|
# Launch arguments
|
|
DeclareLaunchArgument(
|
|
'use_sim_time', default_value='false',
|
|
description='Use simulation (Gazebo) clock if true'),
|
|
|
|
DeclareLaunchArgument(
|
|
'localization', default_value='false',
|
|
description='Launch in localization mode.'),
|
|
|
|
# Nodes to launch
|
|
Node(
|
|
package='rtabmap_sync', executable='rgbd_sync', output='screen',
|
|
parameters=[{'approx_sync':False, 'use_sim_time':use_sim_time}],
|
|
remappings=remappings),
|
|
|
|
# Convert middle row of depth pixels to a fake laser scan
|
|
Node(
|
|
package='depthimage_to_laserscan', executable='depthimage_to_laserscan_node', output='screen',
|
|
parameters=[{
|
|
'use_sim_time':use_sim_time,
|
|
'range_max': 5.0
|
|
}],
|
|
remappings=[
|
|
('depth', '/camera/depth/image_raw'),
|
|
('depth_camera_info', '/camera/camera_info'),
|
|
('scan', '/camera/scan')
|
|
]),
|
|
|
|
# Just to convert the fake laser scan to PointCloud2
|
|
Node(
|
|
package='rtabmap_util', executable='lidar_deskewing', output='screen',
|
|
parameters=[{'use_sim_time':use_sim_time,
|
|
'fixed_frame_id': 'camera_link'}], # use camera frame
|
|
remappings=[
|
|
('input_scan', '/camera/scan')
|
|
]),
|
|
|
|
# Assemble the fake laser scans using a circular buffer, then feed that cloud to rtabmap
|
|
Node(
|
|
package='rtabmap_util', executable='point_cloud_assembler', output='screen',
|
|
parameters=[{'use_sim_time':use_sim_time,
|
|
'max_clouds': 20,
|
|
'voxel_size': 0.05,
|
|
'wait_for_transform': 1.0,
|
|
'linear_update': 0.3,
|
|
'angular_update': 0.5,
|
|
'circular_buffer': True,
|
|
'frame_id': 'base_link'}],
|
|
remappings=[
|
|
('assembled_cloud', 'assembled_cloud'),
|
|
('cloud', '/camera/scan/deskewed')
|
|
]),
|
|
|
|
# SLAM Mode:
|
|
Node(
|
|
condition=UnlessCondition(localization),
|
|
package='rtabmap_slam', executable='rtabmap', output='screen',
|
|
parameters=[parameters],
|
|
remappings=remappings,
|
|
arguments=['-d']),
|
|
|
|
# Localization mode:
|
|
Node(
|
|
condition=IfCondition(localization),
|
|
package='rtabmap_slam', executable='rtabmap', output='screen',
|
|
parameters=[parameters,
|
|
{'Mem/IncrementalMemory':'False',
|
|
'Mem/InitWMWithAllNodes':'True'}],
|
|
remappings=remappings),
|
|
|
|
Node(
|
|
package='rtabmap_viz', executable='rtabmap_viz', output='screen',
|
|
parameters=[parameters],
|
|
remappings=remappings),
|
|
|
|
# Obstacle detection with the camera for nav2 local costmap.
|
|
# First, we need to convert depth image to a point cloud.
|
|
# Second, we segment the floor from the obstacles.
|
|
Node(
|
|
package='rtabmap_util', executable='point_cloud_xyz', output='screen',
|
|
parameters=[{'decimation': 2,
|
|
'max_depth': 3.0,
|
|
'voxel_size': 0.02}],
|
|
remappings=[('depth/image', '/camera/depth/image_raw'),
|
|
('depth/camera_info', '/camera/camera_info'),
|
|
('cloud', '/camera/cloud')]),
|
|
Node(
|
|
package='rtabmap_util', executable='obstacles_detection', output='screen',
|
|
parameters=[parameters],
|
|
remappings=[('cloud', '/camera/cloud'),
|
|
('obstacles', '/camera/obstacles'),
|
|
('ground', '/camera/ground')]),
|
|
])
|