runtime/rbs_bringup/launch/single_robot.launch.py

285 lines
11 KiB
Python
Raw Normal View History

2024-04-18 13:29:36 +00:00
from launch import LaunchDescription
2023-07-24 14:57:23 +03:00
from launch.actions import (
DeclareLaunchArgument,
IncludeLaunchDescription,
2024-04-18 13:29:36 +00:00
OpaqueFunction
2023-07-24 14:57:23 +03:00
)
2023-07-27 12:06:36 +03:00
from launch.conditions import IfCondition
2023-07-24 14:57:23 +03:00
from launch.launch_description_sources import PythonLaunchDescriptionSource
2024-04-18 13:29:36 +00:00
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
2023-07-24 14:57:23 +03:00
from launch_ros.substitutions import FindPackageShare
2024-04-18 13:29:36 +00:00
from launch_ros.actions import Node
import os
from ament_index_python.packages import get_package_share_directory
from nav2_common.launch import RewrittenYaml
def launch_setup(context, *args, **kwargs):
# Initialize Arguments
robot_type = LaunchConfiguration("robot_type")
# General arguments
with_gripper_condition = LaunchConfiguration("with_gripper")
controllers_file = LaunchConfiguration("controllers_file")
cartesian_controllers = LaunchConfiguration("cartesian_controllers")
description_package = LaunchConfiguration("description_package")
description_file = LaunchConfiguration("description_file")
robot_name = LaunchConfiguration("robot_name")
start_joint_controller = LaunchConfiguration("start_joint_controller")
initial_joint_controller = LaunchConfiguration("initial_joint_controller")
launch_simulation = LaunchConfiguration("launch_sim")
launch_moveit = LaunchConfiguration("launch_moveit")
launch_task_planner = LaunchConfiguration("launch_task_planner")
launch_perception = LaunchConfiguration("launch_perception")
moveit_config_package = LaunchConfiguration("moveit_config_package")
moveit_config_file = LaunchConfiguration("moveit_config_file")
use_sim_time = LaunchConfiguration("use_sim_time")
sim_gazebo = LaunchConfiguration("sim_gazebo")
hardware = LaunchConfiguration("hardware")
env_manager = LaunchConfiguration("env_manager")
launch_controllers = LaunchConfiguration("launch_controllers")
gazebo_gui = LaunchConfiguration("gazebo_gui")
gripper_name = LaunchConfiguration("gripper_name")
sim_gazebo = LaunchConfiguration("sim_gazebo")
launch_simulation = LaunchConfiguration("launch_sim")
simulation = IncludeLaunchDescription(
PythonLaunchDescriptionSource([
PathJoinSubstitution([
FindPackageShare('rbs_simulation'),
'launch',
'simulation_gazebo.launch.py'
])
]),
launch_arguments={
'sim_gazebo': sim_gazebo,
'debugger': "false",
2024-05-27 00:20:17 +03:00
'launch_env_manager': "false",
'gazebo_world_filename': "asm2.sdf"
2024-04-18 13:29:36 +00:00
}.items(),
condition=IfCondition(launch_simulation)
)
2024-04-22 15:06:46 +03:00
# FIXME: namespaces
# configured_params = RewrittenYaml(
# source_file=os.path.join(
# get_package_share_directory(
# description_package.perform(context)),
# "config",
# controllers_file.perform(context)),
# root_key=robot_name.perform(context),
# param_rewrites={},
# convert_types=True,
# )
initial_joint_controllers_file_path = os.path.join(
get_package_share_directory('rbs_arm'), 'config', 'rbs_arm0_controllers.yaml'
2024-04-18 13:29:36 +00:00
)
2024-04-22 15:06:46 +03:00
# controller_paramfile = configured_params.perform(context)
# controller_paramfile = PathJoinSubstitution([
# FindPackageShare(robot_type), "config", "rbs_arm0_controllers.yaml"
# ])
2024-04-22 15:06:46 +03:00
# namespace = "/" + robot_name.perform(context)
namespace = ""
2024-04-18 13:29:36 +00:00
gz_spawner = Node(
package='ros_gz_sim',
executable='create',
arguments=[
'-name', robot_name.perform(context),
'-topic', namespace + '/robot_description'],
output='screen',
condition=IfCondition(sim_gazebo))
single_robot_setup = IncludeLaunchDescription(
PythonLaunchDescriptionSource([
PathJoinSubstitution([
FindPackageShare('rbs_bringup'),
"launch",
"rbs_robot.launch.py"
])
]),
launch_arguments={
"env_manager": env_manager,
"with_gripper": with_gripper_condition,
"gripper_name": gripper_name,
"controllers_file": controllers_file,
"robot_type": robot_type,
# "controllers_file": controller_paramfile,
2024-04-18 13:29:36 +00:00
"cartesian_controllers": cartesian_controllers,
"description_package": description_package,
"description_file": description_file,
2024-04-22 15:06:46 +03:00
"robot_name": robot_type,
2024-04-18 13:29:36 +00:00
"start_joint_controller": start_joint_controller,
"initial_joint_controller": initial_joint_controller,
"launch_simulation": launch_simulation,
"launch_moveit": launch_moveit,
"launch_task_planner": launch_task_planner,
"launch_perception": launch_perception,
"moveit_config_package": moveit_config_package,
"moveit_config_file": moveit_config_file,
"use_sim_time": use_sim_time,
"sim_gazebo": sim_gazebo,
"hardware": hardware,
"launch_controllers": "true",
"gazebo_gui": gazebo_gui,
2024-04-22 15:06:46 +03:00
# "x": "0.5",
# "y": "0.5",
# "z": "0.5"
2024-04-18 13:29:36 +00:00
}.items()
)
nodes_to_start = [
simulation,
gz_spawner,
single_robot_setup
]
return nodes_to_start
2023-07-24 14:57:23 +03:00
def generate_launch_description():
declared_arguments = []
declared_arguments.append(
DeclareLaunchArgument(
2024-04-18 13:29:36 +00:00
"robot_type",
2023-07-24 14:57:23 +03:00
description="Type of robot by name",
choices=["rbs_arm","ur3", "ur3e", "ur5", "ur5e", "ur10", "ur10e", "ur16e"],
default_value="rbs_arm",
2023-07-24 14:57:23 +03:00
)
)
# General arguments
declared_arguments.append(
DeclareLaunchArgument(
"controllers_file",
default_value="rbs_arm0_controllers.yaml",
description="YAML file with the controllers configuration.",
2023-07-24 14:57:23 +03:00
)
)
declared_arguments.append(
DeclareLaunchArgument(
"description_package",
default_value="rbs_arm",
2023-07-24 14:57:23 +03:00
description="Description package with robot URDF/XACRO files. Usually the argument \
is not set, it enables use of a custom description.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"description_file",
default_value="rbs_arm_modular.xacro",
2023-07-24 14:57:23 +03:00
description="URDF/XACRO description file with the robot.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
2024-04-18 13:29:36 +00:00
"robot_name",
default_value="arm0",
description="Name for robot, used to apply namespace for specific robot in multirobot setup",
2023-07-24 14:57:23 +03:00
)
)
declared_arguments.append(
DeclareLaunchArgument(
"start_joint_controller",
2024-04-18 13:29:36 +00:00
default_value="false",
2023-07-24 14:57:23 +03:00
description="Enable headless mode for robot control",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"initial_joint_controller",
default_value="joint_trajectory_controller",
description="Robot controller to start.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"moveit_config_package",
default_value="rbs_arm",
2023-07-24 14:57:23 +03:00
description="MoveIt config package with robot SRDF/XACRO files. Usually the argument \
is not set, it enables use of a custom moveit config.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"moveit_config_file",
default_value="rbs_arm.srdf.xacro",
2023-07-24 14:57:23 +03:00
description="MoveIt SRDF/XACRO description file with the robot.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"use_sim_time",
default_value="true",
description="Make MoveIt to use simulation time.\
This is needed for the trajectory planing in simulation.",
2023-07-24 14:57:23 +03:00
)
)
declared_arguments.append(
2024-04-18 13:29:36 +00:00
DeclareLaunchArgument(
"gripper_name",
default_value="rbs_gripper",
choices=["rbs_gripper", ""],
description="choose gripper by name (leave empty if hasn't)",
)
)
2023-07-24 14:57:23 +03:00
declared_arguments.append(
2024-04-18 13:29:36 +00:00
DeclareLaunchArgument("with_gripper",
default_value="false",
2024-04-18 13:29:36 +00:00
description="With gripper or not?")
2023-07-24 14:57:23 +03:00
)
declared_arguments.append(
DeclareLaunchArgument("sim_gazebo",
default_value="true",
description="Gazebo Simulation")
2023-07-24 14:57:23 +03:00
)
declared_arguments.append(
DeclareLaunchArgument("env_manager",
2024-04-18 13:29:36 +00:00
default_value="false",
description="Launch env_manager?")
2023-07-24 14:57:23 +03:00
)
declared_arguments.append(
DeclareLaunchArgument("launch_sim",
default_value="true",
description="Launch simulator (Gazebo)?\
Most general arg")
2023-07-24 14:57:23 +03:00
)
declared_arguments.append(
DeclareLaunchArgument("launch_moveit",
2024-04-18 13:29:36 +00:00
default_value="false",
description="Launch moveit?")
2023-07-24 14:57:23 +03:00
)
declared_arguments.append(
DeclareLaunchArgument("launch_perception",
default_value="false",
description="Launch perception?")
)
declared_arguments.append(
DeclareLaunchArgument("launch_task_planner",
default_value="false",
description="Launch task_planner?")
)
declared_arguments.append(
DeclareLaunchArgument("cartesian_controllers",
2024-04-18 13:29:36 +00:00
default_value="true",
description="Load cartesian\
controllers?")
)
declared_arguments.append(
DeclareLaunchArgument("hardware",
choices=["gazebo", "mock"],
default_value="gazebo",
description="Choose your harware_interface")
)
declared_arguments.append(
DeclareLaunchArgument("launch_controllers",
default_value="true",
description="Launch controllers?")
)
declared_arguments.append(
DeclareLaunchArgument("gazebo_gui",
2024-04-18 13:29:36 +00:00
default_value="true",
description="Launch gazebo with gui?")
)
2023-07-24 14:57:23 +03:00
2024-04-18 13:29:36 +00:00
return LaunchDescription(declared_arguments + [OpaqueFunction(function=launch_setup)])