|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright 2024 Clearpath Robotics, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# @author Hilary Luo ([email protected]) |
| 18 | + |
| 19 | +from ament_index_python.packages import get_package_share_directory |
| 20 | +from launch import LaunchDescription |
| 21 | +from launch.actions.declare_launch_argument import DeclareLaunchArgument |
| 22 | +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution |
| 23 | +from launch_ros.actions import Node |
| 24 | + |
| 25 | +from nav2_common.launch import RewrittenYaml |
| 26 | + |
| 27 | + |
| 28 | +def generate_launch_description(): |
| 29 | + namespace = LaunchConfiguration('namespace') |
| 30 | + ffmpeg_param_file = LaunchConfiguration('ffmpeg_param_file') |
| 31 | + |
| 32 | + turtlebot4_vision_tutorials = get_package_share_directory('turtlebot4_vision_tutorials') |
| 33 | + |
| 34 | + arg_parameters = DeclareLaunchArgument( |
| 35 | + 'ffmpeg_param_file', |
| 36 | + default_value=PathJoinSubstitution( |
| 37 | + [turtlebot4_vision_tutorials, 'config', 'ffmpeg.yaml']), |
| 38 | + description='Turtlebot4 ffmpeg compression param file' |
| 39 | + ) |
| 40 | + |
| 41 | + arg_namespace = DeclareLaunchArgument( |
| 42 | + 'namespace', |
| 43 | + default_value='') |
| 44 | + |
| 45 | + parameters = RewrittenYaml( |
| 46 | + source_file=ffmpeg_param_file, |
| 47 | + root_key=namespace, |
| 48 | + param_rewrites={}, |
| 49 | + convert_types=True) |
| 50 | + |
| 51 | + ffmpeg_node = Node( |
| 52 | + package='image_transport', |
| 53 | + executable='republish', |
| 54 | + namespace=namespace, |
| 55 | + name='ffmpeg_encoder', |
| 56 | + remappings=[ |
| 57 | + ('in', "oakd/rgb/preview/image_raw"), |
| 58 | + ('out/ffmpeg', "oakd/rgb/preview/encoded/ffmpeg"), |
| 59 | + ], |
| 60 | + arguments=['raw', 'ffmpeg'], |
| 61 | + parameters=[parameters], |
| 62 | + ) |
| 63 | + |
| 64 | + ld = LaunchDescription() |
| 65 | + ld.add_action(arg_parameters) |
| 66 | + ld.add_action(arg_namespace) |
| 67 | + ld.add_action(ffmpeg_node) |
| 68 | + |
| 69 | + return ld |
0 commit comments