|
| 1 | +# Copyright 2021 Stogl Robotics Consulting UG (haftungsbeschränkt) |
| 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 | +# Copyright 2023 HURON Project |
| 16 | + |
| 17 | +import os |
| 18 | +from ament_index_python.packages import get_package_share_directory |
| 19 | +from launch import LaunchDescription |
| 20 | +from launch.actions import DeclareLaunchArgument |
| 21 | +from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution |
| 22 | + |
| 23 | +from launch_ros.actions import Node |
| 24 | +from launch_ros.substitutions import FindPackageShare |
| 25 | + |
| 26 | + |
| 27 | +def generate_launch_description(): |
| 28 | + # Declare arguments |
| 29 | + declared_arguments = [] |
| 30 | + declared_arguments.append( |
| 31 | + DeclareLaunchArgument( |
| 32 | + "description_package", |
| 33 | + default_value="cartpole_description", |
| 34 | + description="Description package with robot URDF/xacro files. Usually the argument \ |
| 35 | + is not set, it enables use of a custom description.", |
| 36 | + ) |
| 37 | + ) |
| 38 | + declared_arguments.append( |
| 39 | + DeclareLaunchArgument( |
| 40 | + "description_file", |
| 41 | + default_value="cartpole.urdf", |
| 42 | + description="URDF/XACRO description file with the robot.", |
| 43 | + ) |
| 44 | + ) |
| 45 | + declared_arguments.append( |
| 46 | + DeclareLaunchArgument( |
| 47 | + "prefix", |
| 48 | + default_value='""', |
| 49 | + description="Prefix of the joint names, useful for \ |
| 50 | + multi-robot setup. If changed than also joint names in the controllers' configuration \ |
| 51 | + have to be updated.", |
| 52 | + ) |
| 53 | + ) |
| 54 | + |
| 55 | + # Initialize Arguments |
| 56 | + description_package = LaunchConfiguration("description_package") |
| 57 | + description_file = LaunchConfiguration("description_file") |
| 58 | + prefix = LaunchConfiguration("prefix") |
| 59 | + |
| 60 | + # Load URDF |
| 61 | + urdf_file_name = 'cartpole.urdf' |
| 62 | + urdf = os.path.join( |
| 63 | + get_package_share_directory('cartpole_description'), |
| 64 | + 'urdf', |
| 65 | + urdf_file_name) |
| 66 | + with open(urdf, 'r') as infp: |
| 67 | + robot_desc = infp.read() |
| 68 | + robot_description = {"robot_description": robot_desc} |
| 69 | + |
| 70 | + # rviz_config_file = PathJoinSubstitution( |
| 71 | + # [FindPackageShare(description_package), "config", "huron.rviz"] |
| 72 | + # ) |
| 73 | + |
| 74 | + joint_state_publisher_node = Node( |
| 75 | + package="joint_state_publisher_gui", |
| 76 | + executable="joint_state_publisher_gui", |
| 77 | + ) |
| 78 | + robot_state_publisher_node = Node( |
| 79 | + package="robot_state_publisher", |
| 80 | + executable="robot_state_publisher", |
| 81 | + output="both", |
| 82 | + parameters=[robot_description], |
| 83 | + arguments=[urdf] |
| 84 | + ) |
| 85 | + rviz_node = Node( |
| 86 | + package="rviz2", |
| 87 | + executable="rviz2", |
| 88 | + name="rviz2", |
| 89 | + output="log", |
| 90 | + # arguments=["-d", rviz_config_file], |
| 91 | + ) |
| 92 | + |
| 93 | + nodes = [ |
| 94 | + joint_state_publisher_node, |
| 95 | + robot_state_publisher_node, |
| 96 | + rviz_node, |
| 97 | + ] |
| 98 | + |
| 99 | + return LaunchDescription(declared_arguments + nodes) |
0 commit comments