|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# BSD 3-Clause License |
| 4 | +# |
| 5 | +# Copyright 2025 Ekumen, Inc. |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# Redistribution and use in source and binary forms, with or without |
| 9 | +# modification, are permitted provided that the following conditions are met: |
| 10 | +# |
| 11 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 12 | +# list of conditions and the following disclaimer. |
| 13 | +# |
| 14 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | +# this list of conditions and the following disclaimer in the documentation |
| 16 | +# and/or other materials provided with the distribution. |
| 17 | +# |
| 18 | +# 3. Neither the name of the copyright holder nor the names of its |
| 19 | +# contributors may be used to endorse or promote products derived from |
| 20 | +# this software without specific prior written permission. |
| 21 | +# |
| 22 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 23 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 25 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 26 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 27 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 28 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 29 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 30 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | + |
| 33 | + |
| 34 | +from ament_index_python.packages import get_package_share_directory |
| 35 | +from launch import LaunchDescription |
| 36 | +from launch_ros.actions import Node |
| 37 | +import xacro |
| 38 | + |
| 39 | +import os |
| 40 | + |
| 41 | + |
| 42 | +def get_robot_description(): |
| 43 | + return |
| 44 | + |
| 45 | + |
| 46 | +def generate_launch_description(): |
| 47 | + this_pkg_share = get_package_share_directory("ar4_mujoco_sim") |
| 48 | + |
| 49 | + robot_description_file = os.path.join( |
| 50 | + this_pkg_share, |
| 51 | + "urdf", |
| 52 | + "mj_ar4.urdf.xacro", |
| 53 | + ) |
| 54 | + |
| 55 | + robot_description_urdf = xacro.process_file(robot_description_file).toprettyxml( |
| 56 | + indent=" " |
| 57 | + ) |
| 58 | + |
| 59 | + mujoco_model = os.path.join( |
| 60 | + this_pkg_share, |
| 61 | + "mjcf", |
| 62 | + "scene.xml", |
| 63 | + ) |
| 64 | + |
| 65 | + controller_config_file = os.path.join( |
| 66 | + get_package_share_directory("ar4_moveit_config"), |
| 67 | + "config", |
| 68 | + "ros2_controllers.yaml", |
| 69 | + ) |
| 70 | + |
| 71 | + mujoco_ros2_control_params = { |
| 72 | + "robot_description": robot_description_urdf, |
| 73 | + "mujoco_model_path": mujoco_model, |
| 74 | + } |
| 75 | + |
| 76 | + mujoco_sim_node = Node( |
| 77 | + package="mujoco_ros2_control", |
| 78 | + executable="mujoco_ros2_control", |
| 79 | + output="screen", |
| 80 | + parameters=[ |
| 81 | + mujoco_ros2_control_params, |
| 82 | + controller_config_file, |
| 83 | + ], |
| 84 | + ) |
| 85 | + |
| 86 | + # this nodes is launched with the HAL-specific nodes because we need to load |
| 87 | + # the simulation specific version |
| 88 | + robot_state_publisher_node = Node( |
| 89 | + package="robot_state_publisher", |
| 90 | + executable="robot_state_publisher", |
| 91 | + name="robot_state_publisher", |
| 92 | + output="screen", |
| 93 | + parameters=[ |
| 94 | + { |
| 95 | + "robot_description": robot_description_urdf, |
| 96 | + } |
| 97 | + ], |
| 98 | + ) |
| 99 | + |
| 100 | + spawn_joint_state_broadcaster_controller = Node( |
| 101 | + package="controller_manager", |
| 102 | + executable="spawner", |
| 103 | + arguments=["joint_state_broadcaster"], |
| 104 | + output="screen", |
| 105 | + ) |
| 106 | + |
| 107 | + spawn_joint_trajectory_controller = Node( |
| 108 | + package="controller_manager", |
| 109 | + executable="spawner", |
| 110 | + arguments=["arm_controller"], |
| 111 | + output="screen", |
| 112 | + ) |
| 113 | + |
| 114 | + return LaunchDescription( |
| 115 | + [ |
| 116 | + mujoco_sim_node, |
| 117 | + robot_state_publisher_node, |
| 118 | + spawn_joint_state_broadcaster_controller, |
| 119 | + spawn_joint_trajectory_controller, |
| 120 | + ] |
| 121 | + ) |
0 commit comments