|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright 2024 Trossen Robotics |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# * Redistributions of source code must retain the above copyright |
| 9 | +# notice, this list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# * Redistributions in binary form must reproduce the above copyright |
| 12 | +# notice, this list of conditions and the following disclaimer in the |
| 13 | +# documentation and/or other materials provided with the distribution. |
| 14 | +# |
| 15 | +# * Neither the name of the copyright holder nor the names of its |
| 16 | +# contributors may be used to endorse or promote products derived from |
| 17 | +# this software without specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | +# POSSIBILITY OF SUCH DAMAGE. |
| 30 | + |
| 31 | +from typing import List |
| 32 | + |
| 33 | +from launch import LaunchDescription |
| 34 | +from launch.actions import ( |
| 35 | + IncludeLaunchDescription, |
| 36 | + DeclareLaunchArgument, |
| 37 | + OpaqueFunction |
| 38 | +) |
| 39 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 40 | +from launch.substitutions import ( |
| 41 | + LaunchConfiguration, |
| 42 | + PathJoinSubstitution, |
| 43 | +) |
| 44 | +from launch_ros.actions import Node |
| 45 | +from launch_ros.substitutions import FindPackageShare |
| 46 | + |
| 47 | + |
| 48 | +def launch_setup(context, *args, **kwargs): |
| 49 | + # Define the launch arguments |
| 50 | + robot_model_launch_arg = LaunchConfiguration('robot_model') |
| 51 | + robot_name_launch_arg = LaunchConfiguration('robot_name') |
| 52 | + motor_specs_launch_arg = LaunchConfiguration('motor_specs') |
| 53 | + |
| 54 | + # Create the gravity compensation node |
| 55 | + gravity_compensation_node = Node( |
| 56 | + package='interbotix_gravity_compensation', |
| 57 | + executable='interbotix_gravity_compensation', |
| 58 | + name='gravity_compensation', |
| 59 | + namespace=robot_name_launch_arg, |
| 60 | + output='screen', |
| 61 | + emulate_tty=True, |
| 62 | + parameters=[{'motor_specs': motor_specs_launch_arg}] |
| 63 | + ) |
| 64 | + |
| 65 | + # include the xsarm_control_launch with arguments |
| 66 | + xsarm_control_launch = IncludeLaunchDescription( |
| 67 | + PythonLaunchDescriptionSource([ |
| 68 | + PathJoinSubstitution([ |
| 69 | + FindPackageShare('interbotix_xsarm_control'), |
| 70 | + 'launch', |
| 71 | + 'xsarm_control.launch.py' |
| 72 | + ]) |
| 73 | + ]), |
| 74 | + launch_arguments={ |
| 75 | + 'robot_model': robot_model_launch_arg, |
| 76 | + 'robot_name': robot_name_launch_arg, |
| 77 | + }.items() |
| 78 | + ) |
| 79 | + |
| 80 | + return [gravity_compensation_node, xsarm_control_launch] |
| 81 | + |
| 82 | + |
| 83 | +def generate_launch_description(): |
| 84 | + # Create a list of all the launch arguments |
| 85 | + declared_arguments: List[DeclareLaunchArgument] = [] |
| 86 | + declared_arguments.append( |
| 87 | + DeclareLaunchArgument( |
| 88 | + 'robot_model', |
| 89 | + choices=('wx250s', 'aloha_wx250s'), |
| 90 | + description='model type of the Interbotix Arm such as `wx200` or `rx150`.' |
| 91 | + ) |
| 92 | + ) |
| 93 | + declared_arguments.append( |
| 94 | + DeclareLaunchArgument( |
| 95 | + 'robot_name', |
| 96 | + default_value=LaunchConfiguration('robot_model'), |
| 97 | + description=( |
| 98 | + 'name of the robot (typically equal to `robot_model`, but could be anything).' |
| 99 | + ), |
| 100 | + ) |
| 101 | + ) |
| 102 | + declared_arguments.append( |
| 103 | + DeclareLaunchArgument( |
| 104 | + 'motor_specs', |
| 105 | + default_value=[PathJoinSubstitution([ |
| 106 | + FindPackageShare('interbotix_xsarm_gravity_compensation'), |
| 107 | + 'config', |
| 108 | + "motor_specs_"]), LaunchConfiguration('robot_model'), '.yaml' |
| 109 | + ], |
| 110 | + description="the file path to the 'motor specs' YAML file.", |
| 111 | + ) |
| 112 | + ) |
| 113 | + return LaunchDescription(declared_arguments + [OpaqueFunction(function=launch_setup)]) |
0 commit comments