|
| 1 | +import os |
| 2 | +from tempfile import NamedTemporaryFile |
| 3 | +from launch import LaunchDescription |
| 4 | +from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription |
| 5 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 6 | +from launch.substitutions import LaunchConfiguration, Command |
| 7 | +from launch_ros.descriptions import ParameterValue |
| 8 | +from ament_index_python.packages import get_package_share_directory |
| 9 | +from launch_ros.actions import Node |
| 10 | +from xacro import process_file |
| 11 | + |
| 12 | + |
| 13 | +def generate_launch_description(): |
| 14 | + path_ros_gazebo_sim = get_package_share_directory("ros_gz_sim") |
| 15 | + path_urc_hw_description = get_package_share_directory("urc_hw_description") |
| 16 | + path_urc_bringup = get_package_share_directory("urc_bringup") |
| 17 | + |
| 18 | + # <-- ADDED paths for the Leo Rover packages |
| 19 | + path_leo_description = get_package_share_directory("leo_description") |
| 20 | + path_leo_gz_bringup = get_package_share_directory("leo_gz_bringup") |
| 21 | + |
| 22 | + # <-- CHANGED to use the Leo Rover's controller config |
| 23 | + controller_config_file_dir = os.path.join( |
| 24 | + path_leo_gz_bringup, "config", "controllers.yaml" |
| 25 | + ) |
| 26 | + |
| 27 | + # controller_config_file_dir = os.path.join( |
| 28 | + # path_urc_bringup, "config", "test_controllers.yaml" |
| 29 | + # ) |
| 30 | + |
| 31 | + sim_world_arg = DeclareLaunchArgument( |
| 32 | + "world", |
| 33 | + # default_value=os.path.join(path_urc_hw_description, "world", "leo_world.sdf"), |
| 34 | + default_value=os.path.join(path_urc_hw_description, "world", "marsyard2020.sdf"), |
| 35 | + description="Path to gz world file", |
| 36 | + ) |
| 37 | + |
| 38 | + # <-- CHANGED default_value to point to the Leo Rover's xacro file |
| 39 | + # (I kept your variable name 'walli_xacro' for minimal changes, |
| 40 | + # but you could rename it to 'robot_xacro') |
| 41 | + walli_xacro = DeclareLaunchArgument( |
| 42 | + "walli_xacro", |
| 43 | + default_value=os.path.join( |
| 44 | + path_leo_description, |
| 45 | + "urdf", |
| 46 | + "leo.urdf.xacro", |
| 47 | + ), |
| 48 | + description="Path to xacro file", |
| 49 | + ) |
| 50 | + # walli_xacro = DeclareLaunchArgument( |
| 51 | + # "walli_xacro", |
| 52 | + # default_value=os.path.join( |
| 53 | + # path_urc_hw_description, |
| 54 | + # "urdf/simplified_swerve", |
| 55 | + # "simplified_swerve.urdf.xacro", |
| 56 | + # ), |
| 57 | + # description="Path to xacro file", |
| 58 | + # ) |
| 59 | + |
| 60 | + bridge_yaml = DeclareLaunchArgument( |
| 61 | + "bridge_yaml", |
| 62 | + default_value=os.path.join(path_urc_bringup, "config", "sim_config.yaml"), |
| 63 | + description="bridge YAML config", |
| 64 | + ) |
| 65 | + |
| 66 | + world = LaunchConfiguration("world") |
| 67 | + walli_xacro_config = LaunchConfiguration("walli_xacro") |
| 68 | + |
| 69 | + """ |
| 70 | + robot_urdf_file = process_file( |
| 71 | + ParameterValue(walli_xacro_config, value_type = str), |
| 72 | + mappings = {"use_sim": "true"} |
| 73 | + ).toxml() |
| 74 | + """ |
| 75 | + |
| 76 | + robot_urdf_file = ParameterValue( |
| 77 | + Command( |
| 78 | + [ |
| 79 | + "xacro ", |
| 80 | + walli_xacro_config, |
| 81 | + " use_sim:=", |
| 82 | + "true", |
| 83 | + ] |
| 84 | + ), |
| 85 | + value_type=str, |
| 86 | + ) |
| 87 | + |
| 88 | + gz_sim = IncludeLaunchDescription( |
| 89 | + PythonLaunchDescriptionSource( |
| 90 | + os.path.join(path_ros_gazebo_sim, "launch", "gz_sim.launch.py") |
| 91 | + ), |
| 92 | + launch_arguments={"gz_args": world}.items(), |
| 93 | + ) |
| 94 | + |
| 95 | + bridge = Node( |
| 96 | + package="ros_gz_bridge", |
| 97 | + executable="parameter_bridge", |
| 98 | + name="ros_gz_bridge", |
| 99 | + output="screen", |
| 100 | + parameters=[{"config_file": LaunchConfiguration("bridge_yaml")}], |
| 101 | + ) |
| 102 | + |
| 103 | + robot_state_publisher_node = Node( |
| 104 | + package="robot_state_publisher", |
| 105 | + executable="robot_state_publisher", |
| 106 | + name="robot_state_publisher", |
| 107 | + parameters=[{"robot_description": robot_urdf_file}], |
| 108 | + output="screen", |
| 109 | + ) |
| 110 | + |
| 111 | + control_node = Node( |
| 112 | + package="controller_manager", |
| 113 | + executable="ros2_control_node", |
| 114 | + parameters=[controller_config_file_dir], |
| 115 | + output="screen", |
| 116 | + remappings=[("/controller_manager/robot_description", "/robot_description")], |
| 117 | + ) |
| 118 | + |
| 119 | +# <-- ADDED spawner for the Leo Rover's differential drive controller |
| 120 | + load_diff_drive_controller = Node( |
| 121 | + package="controller_manager", |
| 122 | + executable="spawner", |
| 123 | + arguments=["-p", controller_config_file_dir, "diff_drive_controller"], |
| 124 | + ) |
| 125 | + load_joint_state_broadcaster = Node( |
| 126 | + package="controller_manager", |
| 127 | + executable="spawner", |
| 128 | + arguments=["-p", controller_config_file_dir, "joint_state_broadcaster"], |
| 129 | + ) |
| 130 | + |
| 131 | + # load_position_controller = Node( |
| 132 | + # package="controller_manager", |
| 133 | + # executable="spawner", |
| 134 | + # arguments=["-p", controller_config_file_dir, "position_controller"], |
| 135 | + # ) |
| 136 | + |
| 137 | + # load_velocity_controller = Node( |
| 138 | + # package="controller_manager", |
| 139 | + # executable="spawner", |
| 140 | + # arguments=["-p", controller_config_file_dir, "velocity_controller"], |
| 141 | + # ) |
| 142 | + |
| 143 | + spawn = Node( |
| 144 | + package="ros_gz_sim", |
| 145 | + executable="create", |
| 146 | + output="screen", |
| 147 | + arguments=[ |
| 148 | + "-name", |
| 149 | + "leo", # "walli", |
| 150 | + "-x", |
| 151 | + "0", |
| 152 | + "-y", |
| 153 | + "0", |
| 154 | + "-z", |
| 155 | + "10.5", |
| 156 | + "-R", |
| 157 | + "0", |
| 158 | + "-P", |
| 159 | + "0", |
| 160 | + "-Y", |
| 161 | + "0", |
| 162 | + "-topic", |
| 163 | + "robot_description", |
| 164 | + ], |
| 165 | + ) |
| 166 | + |
| 167 | + return LaunchDescription( |
| 168 | + [ |
| 169 | + sim_world_arg, |
| 170 | + walli_xacro, |
| 171 | + gz_sim, |
| 172 | + spawn, |
| 173 | + bridge_yaml, |
| 174 | + bridge, |
| 175 | + control_node, |
| 176 | + robot_state_publisher_node, |
| 177 | + load_joint_state_broadcaster, |
| 178 | + load_diff_drive_controller, # <-- ADDED |
| 179 | + # <-- REMOVED old controllers |
| 180 | + ] |
| 181 | + ) |
| 182 | + |
| 183 | + # return LaunchDescription( |
| 184 | + # [ |
| 185 | + # sim_world_arg, |
| 186 | + # walli_xacro, |
| 187 | + # gz_sim, |
| 188 | + # spawn, |
| 189 | + # bridge_yaml, |
| 190 | + # bridge, |
| 191 | + # control_node, |
| 192 | + # robot_state_publisher_node, |
| 193 | + # load_joint_state_broadcaster, |
| 194 | + # load_position_controller, |
| 195 | + # load_velocity_controller, |
| 196 | + # ] |
| 197 | + # ) |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
0 commit comments