|
| 1 | +# Copyright 2023 ICube Laboratory, University of Strasbourg |
| 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 | +from launch import LaunchDescription |
| 16 | +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration |
| 17 | +from launch.actions import DeclareLaunchArgument |
| 18 | + |
| 19 | +from launch_ros.actions import Node |
| 20 | +from launch_ros.substitutions import FindPackageShare |
| 21 | + |
| 22 | + |
| 23 | +def generate_launch_description(): |
| 24 | + |
| 25 | + # Declare arguments |
| 26 | + declared_arguments = [] |
| 27 | + declared_arguments.append( |
| 28 | + DeclareLaunchArgument( |
| 29 | + 'description_file', |
| 30 | + default_value='motor_drive.config.xacro', |
| 31 | + description='URDF/XACRO description file with the axis.', |
| 32 | + ) |
| 33 | + ) |
| 34 | + |
| 35 | + description_file = LaunchConfiguration('description_file') |
| 36 | + |
| 37 | + # Get URDF via xacro |
| 38 | + robot_description_content = Command( |
| 39 | + [ |
| 40 | + PathJoinSubstitution([FindExecutable(name="xacro")]), |
| 41 | + " ", |
| 42 | + PathJoinSubstitution( |
| 43 | + [ |
| 44 | + FindPackageShare("ethercat_motor_drive"), |
| 45 | + "description/config", |
| 46 | + description_file, |
| 47 | + ] |
| 48 | + ), |
| 49 | + ] |
| 50 | + ) |
| 51 | + robot_description = {"robot_description": robot_description_content} |
| 52 | + |
| 53 | + robot_controllers = PathJoinSubstitution( |
| 54 | + [ |
| 55 | + FindPackageShare("ethercat_motor_drive"), |
| 56 | + "config", |
| 57 | + "controllers.yaml", |
| 58 | + ] |
| 59 | + ) |
| 60 | + |
| 61 | + control_node = Node( |
| 62 | + package="controller_manager", |
| 63 | + executable="ros2_control_node", |
| 64 | + parameters=[robot_description, robot_controllers], |
| 65 | + output="both", |
| 66 | + ) |
| 67 | + robot_state_pub_node = Node( |
| 68 | + package="robot_state_publisher", |
| 69 | + executable="robot_state_publisher", |
| 70 | + output="both", |
| 71 | + parameters=[robot_description], |
| 72 | + ) |
| 73 | + |
| 74 | + joint_state_broadcaster_spawner = Node( |
| 75 | + package="controller_manager", |
| 76 | + executable="spawner", |
| 77 | + arguments=["joint_state_broadcaster", "-c", "/controller_manager"], |
| 78 | + ) |
| 79 | + |
| 80 | + trajectory_controller_spawner = Node( |
| 81 | + package="controller_manager", |
| 82 | + executable="spawner", |
| 83 | + arguments=["trajectory_controller", "-c", "/controller_manager"], |
| 84 | + ) |
| 85 | + |
| 86 | + velocity_controller_spawner = Node( |
| 87 | + package="controller_manager", |
| 88 | + executable="spawner", |
| 89 | + arguments=["velocity_controller", "-c", "/controller_manager"], |
| 90 | + ) |
| 91 | + |
| 92 | + effort_controller_spawner = Node( |
| 93 | + package="controller_manager", |
| 94 | + executable="spawner", |
| 95 | + arguments=["effort_controller", "-c", "/controller_manager"], |
| 96 | + ) |
| 97 | + |
| 98 | + nodes = [ |
| 99 | + control_node, |
| 100 | + robot_state_pub_node, |
| 101 | + joint_state_broadcaster_spawner, |
| 102 | + trajectory_controller_spawner, |
| 103 | + # velocity_controller_spawner, |
| 104 | + # effort_controller_spawner, |
| 105 | + ] |
| 106 | + |
| 107 | + return LaunchDescription( |
| 108 | + declared_arguments + |
| 109 | + nodes) |
0 commit comments