|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from ament_index_python import get_package_share_directory |
| 4 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 5 | +from launch import LaunchDescription |
| 6 | +from launch.actions import DeclareLaunchArgument |
| 7 | +from launch.substitutions import LaunchConfiguration |
| 8 | +from launch_ros.actions import Node |
| 9 | +from launch.conditions import IfCondition |
| 10 | +from launch.actions import IncludeLaunchDescription |
| 11 | + |
| 12 | + |
| 13 | +def generate_launch_description(): |
| 14 | + return LaunchDescription([ |
| 15 | + DeclareLaunchArgument("enable_front_camera", |
| 16 | + default_value="true", |
| 17 | + description="Включить (true) или отключить (false) ноду нижней камеры"), |
| 18 | + DeclareLaunchArgument('front_camera_topic', |
| 19 | + default_value='/stingray/topics/camera/front', |
| 20 | + description='Топик с изображениями для первой камеры'), |
| 21 | + DeclareLaunchArgument("front_camera_info_topic", |
| 22 | + default_value='/stingray/topics/camera/front/camera_info'), |
| 23 | + DeclareLaunchArgument("front_camera_path", |
| 24 | + default_value='/dev/video0'), |
| 25 | + DeclareLaunchArgument("front_camera_calibration_path", |
| 26 | + default_value="package://sauvc_cam/configs/front_camera.yaml"), |
| 27 | + DeclareLaunchArgument('front_camera_output_width', |
| 28 | + default_value='640', |
| 29 | + description='Ширина видео'), |
| 30 | + DeclareLaunchArgument('front_camera_output_height', |
| 31 | + default_value='480', |
| 32 | + description='Высота видео'), |
| 33 | + DeclareLaunchArgument('front_camera_framerate', |
| 34 | + default_value='30.0', |
| 35 | + description='Частота кадров видео'), |
| 36 | + # bottom camera |
| 37 | + DeclareLaunchArgument("enable_bottom_camera", |
| 38 | + default_value="true", |
| 39 | + description="Включить (true) или отключить (false) ноду нижней камеры"), |
| 40 | + DeclareLaunchArgument('bottom_camera_topic', |
| 41 | + default_value='/stingray/topics/camera/bottom', |
| 42 | + description='Топик с изображениями для второй камеры'), |
| 43 | + DeclareLaunchArgument("bottom_camera_info_topic", |
| 44 | + default_value='/stingray/topics/camera/bottom/camera_info'), |
| 45 | + DeclareLaunchArgument("bottom_camera_path", |
| 46 | + default_value='/dev/video0'), |
| 47 | + DeclareLaunchArgument("bottom_camera_calibration_path", |
| 48 | + default_value="package://sauvc_cam/configs/bottom_camera.yaml"), |
| 49 | + DeclareLaunchArgument('bottom_camera_output_width', |
| 50 | + default_value='640', |
| 51 | + description='Ширина видео'), |
| 52 | + DeclareLaunchArgument('bottom_camera_output_height', |
| 53 | + default_value='480', |
| 54 | + description='Высота видео'), |
| 55 | + DeclareLaunchArgument('bottom_camera_framerate', |
| 56 | + default_value='30.0', |
| 57 | + description='Частота кадров видео'), |
| 58 | + # recorder |
| 59 | + DeclareLaunchArgument("enable_recording_front_camera", |
| 60 | + default_value="true", |
| 61 | + description="Включить (true) или отключить (false) ноду нижней камеры"), |
| 62 | + DeclareLaunchArgument("enable_recording_bottom_camera", |
| 63 | + default_value="true", |
| 64 | + description="Включить(true) или отключить(false) ноду нижней камеры"), |
| 65 | + DeclareLaunchArgument('output_fps', |
| 66 | + default_value='30', |
| 67 | + description='Частота кадров видео'), |
| 68 | + DeclareLaunchArgument('output_format', |
| 69 | + default_value='h264', |
| 70 | + description='Формат видео (FourCC)'), |
| 71 | + DeclareLaunchArgument('record_dir', |
| 72 | + default_value='./records/', |
| 73 | + description='Путь к папке для сохранения записей'), |
| 74 | + DeclareLaunchArgument("enable_recording_topic", |
| 75 | + default_value='/stingray/topics/enable_recording'), |
| 76 | + |
| 77 | + IncludeLaunchDescription( |
| 78 | + PythonLaunchDescriptionSource(str(Path( |
| 79 | + get_package_share_directory('stingray_launch'), 'zbar.launch.py'))), |
| 80 | + launch_arguments={ |
| 81 | + 'zbar_camera_topic': LaunchConfiguration("front_camera_topic"), |
| 82 | + }.items(), |
| 83 | + ), |
| 84 | + |
| 85 | + # Нода фронтальной камеры |
| 86 | + Node( |
| 87 | + package='usb_cam', |
| 88 | + executable='usb_cam_node_exe', |
| 89 | + name='front_camera_node', |
| 90 | + remappings=[ |
| 91 | + ('/image_raw', LaunchConfiguration("front_camera_topic")), |
| 92 | + ('/camera_info', LaunchConfiguration("front_camera_info_topic")), |
| 93 | + ], |
| 94 | + parameters=[ |
| 95 | + {'framerate': LaunchConfiguration("front_camera_framerate")}, |
| 96 | + {'video_device': LaunchConfiguration("front_camera_path")}, |
| 97 | + {'camera_info_url': LaunchConfiguration( |
| 98 | + "front_camera_calibration_path")}, |
| 99 | + {'camera_name': 'front_camera'}, |
| 100 | + {'image_width': LaunchConfiguration( |
| 101 | + "front_camera_output_width")}, |
| 102 | + {'image_height': LaunchConfiguration( |
| 103 | + "front_camera_output_height")}, |
| 104 | + ], |
| 105 | + respawn=True, |
| 106 | + respawn_delay=1, |
| 107 | + condition=IfCondition(LaunchConfiguration('enable_front_camera')) |
| 108 | + ), |
| 109 | + # Нода нижней камеры (запускается при enable_bottom_camera==true) |
| 110 | + Node( |
| 111 | + package='usb_cam', |
| 112 | + executable='usb_cam_node_exe', |
| 113 | + name='bottom_camera_node', |
| 114 | + remappings=[ |
| 115 | + ('/image_raw', LaunchConfiguration("bottom_camera_topic")), |
| 116 | + ('/camera_info', LaunchConfiguration("bottom_camera_info_topic")), |
| 117 | + ], |
| 118 | + parameters=[ |
| 119 | + {'framerate': LaunchConfiguration("bottom_camera_framerate")}, |
| 120 | + {'video_device': LaunchConfiguration("bottom_camera_path")}, |
| 121 | + {'camera_info_url': LaunchConfiguration( |
| 122 | + "bottom_camera_calibration_path")}, |
| 123 | + {'camera_name': 'bottom_camera'}, |
| 124 | + {'image_width': LaunchConfiguration( |
| 125 | + "bottom_camera_output_width")}, |
| 126 | + {'image_height': LaunchConfiguration( |
| 127 | + "bottom_camera_output_height")}, |
| 128 | + ], |
| 129 | + respawn=True, |
| 130 | + respawn_delay=1, |
| 131 | + condition=IfCondition(LaunchConfiguration('enable_bottom_camera')) |
| 132 | + ), |
| 133 | + |
| 134 | + IncludeLaunchDescription( |
| 135 | + PythonLaunchDescriptionSource(str(Path( |
| 136 | + get_package_share_directory('stingray_launch'), 'recorder.launch.py'))), |
| 137 | + launch_arguments={ |
| 138 | + 'recorder_name': 'front_camera_recorder', |
| 139 | + 'source_topic': LaunchConfiguration('front_camera_topic'), |
| 140 | + 'output_width': LaunchConfiguration('front_camera_output_width'), |
| 141 | + 'output_height': LaunchConfiguration('front_camera_output_height'), |
| 142 | + 'output_fps': LaunchConfiguration('output_fps'), |
| 143 | + 'output_format': LaunchConfiguration('output_format'), |
| 144 | + 'record_dir': LaunchConfiguration('record_dir'), |
| 145 | + 'enable_recording_topic': LaunchConfiguration('enable_recording_topic'), |
| 146 | + }.items(), |
| 147 | + condition=IfCondition(LaunchConfiguration('enable_recording_front_camera')) |
| 148 | + ), |
| 149 | + |
| 150 | + IncludeLaunchDescription( |
| 151 | + PythonLaunchDescriptionSource(str(Path( |
| 152 | + get_package_share_directory('stingray_launch'), 'recorder.launch.py'))), |
| 153 | + launch_arguments={ |
| 154 | + 'recorder_name': 'bottom_camera_recorder', |
| 155 | + 'source_topic': LaunchConfiguration('bottom_camera_topic'), |
| 156 | + 'output_width': LaunchConfiguration('bottom_camera_output_width'), |
| 157 | + 'output_height': LaunchConfiguration('bottom_camera_output_height'), |
| 158 | + 'output_fps': LaunchConfiguration('output_fps'), |
| 159 | + 'output_format': LaunchConfiguration('output_format'), |
| 160 | + 'record_dir': LaunchConfiguration('record_dir'), |
| 161 | + 'enable_recording_topic': LaunchConfiguration('enable_recording_topic'), |
| 162 | + }.items(), |
| 163 | + condition=IfCondition(LaunchConfiguration('enable_recording_bottom_camera')) |
| 164 | + ), |
| 165 | + ]) |
0 commit comments