|
| 1 | +# Copyright 2019 Carlos San Vicente |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | + |
| 17 | +from launch import LaunchDescription |
| 18 | +from launch.actions import DeclareLaunchArgument |
| 19 | +from launch.conditions import IfCondition |
| 20 | +import launch.substitutions |
| 21 | +from launch.substitutions import LaunchConfiguration |
| 22 | +from launch_ros.actions import Node |
| 23 | +from launch_ros.substitutions import FindPackageShare |
| 24 | + |
| 25 | + |
| 26 | +def generate_launch_description(): |
| 27 | + # Get the bringup directory |
| 28 | + bringup_dir = FindPackageShare('pendulum_bringup').find('pendulum_bringup') |
| 29 | + |
| 30 | + # Set robot description parameters |
| 31 | + urdf_file = os.path.join(bringup_dir, 'urdf', 'pendulum.urdf') |
| 32 | + with open(urdf_file, 'r') as infp: |
| 33 | + robot_desc = infp.read() |
| 34 | + rsp_params = {'robot_description': robot_desc} |
| 35 | + |
| 36 | + # Set parameter file path |
| 37 | + param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml') |
| 38 | + param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path]) |
| 39 | + |
| 40 | + # Set rviz config path |
| 41 | + rviz_cfg_path = os.path.join(bringup_dir, 'rviz/pendulum.rviz') |
| 42 | + |
| 43 | + # Create the launch configuration variables |
| 44 | + autostart_param = DeclareLaunchArgument( |
| 45 | + name='autostart', |
| 46 | + default_value='True', |
| 47 | + description='Automatically start lifecycle nodes') |
| 48 | + priority_param = DeclareLaunchArgument( |
| 49 | + name='priority', |
| 50 | + default_value='0', |
| 51 | + description='Set process priority') |
| 52 | + cpu_affinity_param = DeclareLaunchArgument( |
| 53 | + name='cpu-affinity', |
| 54 | + default_value='0', |
| 55 | + description='Set process CPU affinity') |
| 56 | + with_lock_memory_param = DeclareLaunchArgument( |
| 57 | + name='lock-memory', |
| 58 | + default_value='False', |
| 59 | + description='Lock the process memory') |
| 60 | + lock_memory_size_param = DeclareLaunchArgument( |
| 61 | + name='lock-memory-size', |
| 62 | + default_value='0', |
| 63 | + description='Set lock memory size in MB') |
| 64 | + config_child_threads_param = DeclareLaunchArgument( |
| 65 | + name='config-child-threads', |
| 66 | + default_value='False', |
| 67 | + description='Configure process child threads (typically DDS threads)') |
| 68 | + with_rviz_param = DeclareLaunchArgument( |
| 69 | + 'rviz', |
| 70 | + default_value='False', |
| 71 | + description='Launch RVIZ2 in addition to other nodes' |
| 72 | + ) |
| 73 | + |
| 74 | + # Node definitions |
| 75 | + |
| 76 | + robot_state_publisher_runner = Node( |
| 77 | + package='robot_state_publisher', |
| 78 | + executable='robot_state_publisher', |
| 79 | + output='screen', |
| 80 | + parameters=[rsp_params], |
| 81 | + condition=IfCondition(LaunchConfiguration('rviz')) |
| 82 | + ) |
| 83 | + |
| 84 | + rviz_runner = Node( |
| 85 | + package='rviz2', |
| 86 | + executable='rviz2', |
| 87 | + name='rviz2', |
| 88 | + arguments=['-d', str(rviz_cfg_path)], |
| 89 | + condition=IfCondition(LaunchConfiguration('rviz')) |
| 90 | + ) |
| 91 | + |
| 92 | + pendulum_state_publisher_runner = Node( |
| 93 | + package='pendulum_state_publisher', |
| 94 | + executable='pendulum_state_publisher', |
| 95 | + condition=IfCondition(LaunchConfiguration('rviz')) |
| 96 | + ) |
| 97 | + |
| 98 | + ld = LaunchDescription() |
| 99 | + |
| 100 | + ld.add_action(autostart_param) |
| 101 | + ld.add_action(priority_param) |
| 102 | + ld.add_action(cpu_affinity_param) |
| 103 | + ld.add_action(with_lock_memory_param) |
| 104 | + ld.add_action(lock_memory_size_param) |
| 105 | + ld.add_action(config_child_threads_param) |
| 106 | + ld.add_action(with_rviz_param) |
| 107 | + ld.add_action(robot_state_publisher_runner) |
| 108 | + #ld.add_action(pendulum_demo_runner) |
| 109 | + ld.add_action(rviz_runner) |
| 110 | + ld.add_action(pendulum_state_publisher_runner) |
| 111 | + |
| 112 | + return ld |
0 commit comments