|
| 1 | +# Copyright 2019 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Redistribution and use in source and binary forms, with or without |
| 4 | +# modification, are permitted provided that the following conditions |
| 5 | +# are met: |
| 6 | +# |
| 7 | +# 1. Redistributions of source code must retain the above copyright |
| 8 | +# notice, this list of conditions and the following disclaimer. |
| 9 | +# |
| 10 | +# 2. Redistributions in binary form must reproduce the above |
| 11 | +# copyright notice, this list of conditions and the following |
| 12 | +# disclaimer in the documentation and/or other materials provided |
| 13 | +# with the distribution. |
| 14 | +# |
| 15 | +# 3. Neither the name of the copyright holder nor the names of its |
| 16 | +# contributors may be used to endorse or promote products derived |
| 17 | +# from this software without specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 22 | +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 23 | +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 25 | +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 26 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 27 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 29 | +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | +# POSSIBILITY OF SUCH DAMAGE. |
| 31 | + |
| 32 | +"""Launch the velodyne driver, pointcloud, and laserscan nodes in a composable container with default configuration.""" |
| 33 | + |
| 34 | +import os |
| 35 | +import yaml |
| 36 | + |
| 37 | +import ament_index_python.packages |
| 38 | +from launch import LaunchDescription |
| 39 | +from launch_ros.actions import ComposableNodeContainer |
| 40 | +from launch_ros.descriptions import ComposableNode |
| 41 | + |
| 42 | + |
| 43 | +def generate_launch_description(): |
| 44 | + driver_share_dir = ament_index_python.packages.get_package_share_directory('velodyne_driver') |
| 45 | + driver_params_file = os.path.join(driver_share_dir, 'config', 'VLS128-velodyne_driver_node-params.yaml') |
| 46 | + with open(driver_params_file, 'r') as f: |
| 47 | + driver_params = yaml.safe_load(f)['velodyne_driver_node']['ros__parameters'] |
| 48 | + |
| 49 | + convert_share_dir = ament_index_python.packages.get_package_share_directory('velodyne_pointcloud') |
| 50 | + convert_params_file = os.path.join(convert_share_dir, 'config', 'VLS128-velodyne_transform_node-params.yaml') |
| 51 | + with open(convert_params_file, 'r') as f: |
| 52 | + convert_params = yaml.safe_load(f)['velodyne_transform_node']['ros__parameters'] |
| 53 | + convert_params['calibration'] = os.path.join(convert_share_dir, 'params', 'VLS128.yaml') |
| 54 | + |
| 55 | + laserscan_share_dir = ament_index_python.packages.get_package_share_directory('velodyne_laserscan') |
| 56 | + laserscan_params_file = os.path.join(laserscan_share_dir, 'config', 'default-velodyne_laserscan_node-params.yaml') |
| 57 | + with open(laserscan_params_file, 'r') as f: |
| 58 | + laserscan_params = yaml.safe_load(f)['velodyne_laserscan_node']['ros__parameters'] |
| 59 | + |
| 60 | + container = ComposableNodeContainer( |
| 61 | + name='velodyne_container', |
| 62 | + namespace='', |
| 63 | + package='rclcpp_components', |
| 64 | + executable='component_container', |
| 65 | + composable_node_descriptions=[ |
| 66 | + ComposableNode( |
| 67 | + package='velodyne_driver', |
| 68 | + plugin='velodyne_driver::VelodyneDriver', |
| 69 | + name='velodyne_driver_node', |
| 70 | + parameters=[driver_params]), |
| 71 | + ComposableNode( |
| 72 | + package='velodyne_pointcloud', |
| 73 | + plugin='velodyne_pointcloud::Transform', |
| 74 | + name='velodyne_transform_node', |
| 75 | + parameters=[convert_params]), |
| 76 | + ComposableNode( |
| 77 | + package='velodyne_laserscan', |
| 78 | + plugin='velodyne_laserscan::VelodyneLaserScan', |
| 79 | + name='velodyne_laserscan_node', |
| 80 | + parameters=[laserscan_params]), |
| 81 | + ], |
| 82 | + output='both', |
| 83 | + ) |
| 84 | + |
| 85 | + return LaunchDescription([container]) |
0 commit comments