|
| 1 | +# Copyright 2021 Open Source Robotics Foundation, Inc. |
| 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 | + |
| 16 | +from launch import LaunchDescription |
| 17 | +from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription |
| 18 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 19 | +from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution |
| 20 | +from launch.conditions import IfCondition, UnlessCondition |
| 21 | + |
| 22 | +from launch_ros.actions import Node |
| 23 | +from launch_ros.substitutions import FindPackageShare |
| 24 | + |
| 25 | +# Necessary dirty work that lets us import modules from the meta_bringup package |
| 26 | +import os |
| 27 | +import sys |
| 28 | +from ament_index_python.packages import get_package_share_directory |
| 29 | +sys.path.append(os.path.join(get_package_share_directory('meta_bringup'), 'launch')) |
| 30 | + |
| 31 | +from launch_utils import load_controller, register_loading_order, register_sequential_loading |
| 32 | + |
| 33 | +ARGUMENTS = [ |
| 34 | + DeclareLaunchArgument( |
| 35 | + 'enable_simulation', |
| 36 | + default_value='false', |
| 37 | + description='If true, the simulation will be started'), |
| 38 | +] |
| 39 | + |
| 40 | +def generate_launch_description(): |
| 41 | + # Launch Arguments |
| 42 | + enable_simulation = LaunchConfiguration('enable_simulation') |
| 43 | + |
| 44 | + # Get URDF via xacro |
| 45 | + robot_description_content = Command([ |
| 46 | + PathJoinSubstitution([FindExecutable(name='xacro')]), |
| 47 | + ' ', |
| 48 | + PathJoinSubstitution([FindPackageShare('metav_description'), 'urdf', 'playground', 'cjh_chassis.xacro']), |
| 49 | + ' ', |
| 50 | + 'is_simulation:=', enable_simulation, |
| 51 | + ]) |
| 52 | + |
| 53 | + node_robot_state_publisher = Node( |
| 54 | + package='robot_state_publisher', |
| 55 | + executable='robot_state_publisher', |
| 56 | + parameters=[ |
| 57 | + {'use_sim_time': enable_simulation, |
| 58 | + 'robot_description': robot_description_content, |
| 59 | + 'publish_frequency': 100.0} |
| 60 | + ], |
| 61 | + output='both', |
| 62 | + emulate_tty=True |
| 63 | + ) |
| 64 | + |
| 65 | + robot_config = PathJoinSubstitution([FindPackageShare('meta_bringup'), 'config', 'cjh_chassis.yaml']) |
| 66 | + controller_manager = Node( |
| 67 | + package="controller_manager", |
| 68 | + executable="ros2_control_node", |
| 69 | + parameters=[robot_config], |
| 70 | + remappings=[ |
| 71 | + ("~/robot_description", "/robot_description"), |
| 72 | + ], |
| 73 | + output='both', |
| 74 | + emulate_tty=True, |
| 75 | + condition=UnlessCondition(enable_simulation) |
| 76 | + ) |
| 77 | + |
| 78 | + load_joint_state_broadcaster = load_controller('joint_state_broadcaster') |
| 79 | + |
| 80 | + # List of controllers to be loaded sequentially |
| 81 | + # Order in this list is IMPORTANT |
| 82 | + load_controllers = [ |
| 83 | + load_controller('wheels_pid_controller'), |
| 84 | + load_controller('omni_chassis_controller'), |
| 85 | + ] |
| 86 | + |
| 87 | + hero_vehicle_node = Node( |
| 88 | + package='hero_vehicle', |
| 89 | + executable='hero_vehicle_node', |
| 90 | + name='hero_vehicle', |
| 91 | + output='both', |
| 92 | + parameters=[robot_config], |
| 93 | + emulate_tty=True |
| 94 | + ) |
| 95 | + dbus_control_node = Node( |
| 96 | + package='dbus_control', |
| 97 | + executable='dbus_control_node', |
| 98 | + name='dbus_control_node', |
| 99 | + parameters=[robot_config], |
| 100 | + output='both', |
| 101 | + emulate_tty=True, |
| 102 | + ) |
| 103 | + return LaunchDescription([ |
| 104 | + # Launch Arguments |
| 105 | + *ARGUMENTS, |
| 106 | + # Load robot state publisher |
| 107 | + node_robot_state_publisher, |
| 108 | + # Launch controller manager (if not in simulation) |
| 109 | + controller_manager, |
| 110 | + # Load joint state broadcaster |
| 111 | + load_joint_state_broadcaster, |
| 112 | + # Load controllers |
| 113 | + *register_sequential_loading(load_joint_state_broadcaster, *load_controllers), |
| 114 | + hero_vehicle_node, |
| 115 | + dbus_control_node |
| 116 | + ]) |
0 commit comments