|
1 |
| -from typing import List |
| 1 | +from launch import LaunchDescription |
| 2 | +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution |
| 3 | +from lbr_bringup.description import GazeboMixin, LBRDescriptionMixin |
| 4 | +from lbr_bringup.ros2_control import LBRROS2ControlMixin |
2 | 5 |
|
3 |
| -from launch import LaunchContext, LaunchDescription, LaunchDescriptionEntity |
4 |
| -from launch.actions import DeclareLaunchArgument, OpaqueFunction, RegisterEventHandler |
5 |
| -from launch.conditions import IfCondition |
6 |
| -from launch.event_handlers import OnProcessExit |
7 |
| -from launch.substitutions import ( |
8 |
| - AndSubstitution, |
9 |
| - LaunchConfiguration, |
10 |
| - NotSubstitution, |
11 |
| - PathJoinSubstitution, |
12 |
| -) |
13 |
| -from launch_mixins.lbr_bringup import LBRMoveGroupMixin |
14 |
| -from launch_mixins.lbr_description import GazeboMixin, LBRDescriptionMixin, RVizMixin |
15 |
| -from launch_mixins.lbr_ros2_control import LBRROS2ControlMixin |
16 | 6 |
|
17 |
| - |
18 |
| -def launch_setup(context: LaunchContext) -> List[LaunchDescriptionEntity]: |
| 7 | +def generate_launch_description() -> LaunchDescription: |
19 | 8 | ld = LaunchDescription()
|
20 | 9 |
|
21 |
| - robot_description = LBRDescriptionMixin.param_robot_description(sim=True) |
22 |
| - world_robot_tf = [0, 0, 0, 0, 0, 0] # keep zero |
23 |
| - ld.add_action(GazeboMixin.include_gazebo()) # Gazebo has its own controller manager |
24 |
| - spawn_entity = GazeboMixin.node_spawn_entity(tf=world_robot_tf) |
25 |
| - ld.add_action(spawn_entity) |
26 |
| - joint_state_broadcaster = LBRROS2ControlMixin.node_controller_spawner( |
27 |
| - controller="joint_state_broadcaster" |
28 |
| - ) |
29 |
| - ld.add_action(joint_state_broadcaster) |
30 |
| - robot_state_publisher = LBRROS2ControlMixin.node_robot_state_publisher( |
31 |
| - robot_description=robot_description, use_sim_time=True |
32 |
| - ) |
33 |
| - ld.add_action( |
34 |
| - robot_state_publisher |
35 |
| - ) # Do not condition robot state publisher on joint state broadcaster as Gazebo uses robot state publisher to retrieve robot description |
| 10 | + # launch arguments |
| 11 | + ld.add_action(LBRDescriptionMixin.arg_model()) |
| 12 | + ld.add_action(LBRDescriptionMixin.arg_robot_name()) |
36 | 13 | ld.add_action(
|
37 |
| - LBRROS2ControlMixin.node_controller_spawner( |
38 |
| - controller=LaunchConfiguration("ctrl") |
39 |
| - ) |
40 |
| - ) |
41 |
| - |
42 |
| - # MoveIt 2 |
43 |
| - ld.add_action(LBRMoveGroupMixin.arg_allow_trajectory_execution()) |
44 |
| - ld.add_action(LBRMoveGroupMixin.arg_capabilities()) |
45 |
| - ld.add_action(LBRMoveGroupMixin.arg_disable_capabilities()) |
46 |
| - ld.add_action(LBRMoveGroupMixin.arg_monitor_dynamics()) |
47 |
| - ld.add_action(LBRMoveGroupMixin.args_publish_monitored_planning_scene()) |
| 14 | + LBRROS2ControlMixin.arg_ctrl() |
| 15 | + ) # Gazebo loads controller configuration through lbr_description/gazebo/*.xacro from lbr_ros2_control/config/lbr_controllers.yaml |
48 | 16 |
|
49 |
| - # MoveGroup: |
50 |
| - # - requires world frame |
51 |
| - # - urdf only has robot_name/world |
52 |
| - # This transform needs publishing |
53 |
| - robot_name = LaunchConfiguration("robot_name").perform(context) |
| 17 | + # static transform world -> robot_name/world |
| 18 | + world_robot_tf = [0, 0, 0, 0, 0, 0] # keep zero |
54 | 19 | ld.add_action(
|
55 | 20 | LBRDescriptionMixin.node_static_tf(
|
56 | 21 | tf=world_robot_tf,
|
57 | 22 | parent="world",
|
58 |
| - child=PathJoinSubstitution( |
59 |
| - [ |
60 |
| - robot_name, |
61 |
| - "world", |
62 |
| - ] # results in robot_name/world |
63 |
| - ), |
64 |
| - parameters=[{"use_sim_time": True}], |
| 23 | + child=PathJoinSubstitution([LaunchConfiguration("robot_name"), "world"]), |
65 | 24 | )
|
66 | 25 | )
|
67 | 26 |
|
68 |
| - model = LaunchConfiguration("model").perform(context) |
69 |
| - moveit_configs_builder = LBRMoveGroupMixin.moveit_configs_builder( |
70 |
| - robot_name=model, |
71 |
| - package_name=f"{model}_moveit_config", |
72 |
| - ) |
73 |
| - move_group_params = LBRMoveGroupMixin.params_move_group() |
| 27 | + # robot description |
| 28 | + robot_description = LBRDescriptionMixin.param_robot_description(mode="gazebo") |
74 | 29 |
|
75 |
| - ld.add_action( |
76 |
| - LBRMoveGroupMixin.node_move_group( |
77 |
| - parameters=[ |
78 |
| - moveit_configs_builder.to_dict(), |
79 |
| - move_group_params, |
80 |
| - {"use_sim_time": True}, |
81 |
| - ], |
82 |
| - condition=IfCondition(LaunchConfiguration("moveit")), |
83 |
| - namespace=robot_name, |
84 |
| - ) |
85 |
| - ) |
86 |
| - |
87 |
| - # RViz and MoveIt |
88 |
| - rviz_moveit = RVizMixin.node_rviz( |
89 |
| - rviz_config_pkg=f"{model}_moveit_config", |
90 |
| - rviz_config="config/moveit.rviz", |
91 |
| - parameters=LBRMoveGroupMixin.params_rviz( |
92 |
| - moveit_configs=moveit_configs_builder.to_moveit_configs() |
93 |
| - ) |
94 |
| - + [{"use_sim_time": True}], |
95 |
| - condition=IfCondition( |
96 |
| - AndSubstitution(LaunchConfiguration("moveit"), LaunchConfiguration("rviz")) |
97 |
| - ), |
98 |
| - remappings=[ |
99 |
| - ("display_planned_path", robot_name + "/display_planned_path"), |
100 |
| - ("joint_states", robot_name + "/joint_states"), |
101 |
| - ("monitored_planning_scene", robot_name + "/monitored_planning_scene"), |
102 |
| - ("planning_scene", robot_name + "/planning_scene"), |
103 |
| - ("planning_scene_world", robot_name + "/planning_scene_world"), |
104 |
| - ("robot_description", robot_name + "/robot_description"), |
105 |
| - ("robot_description_semantic", robot_name + "/robot_description_semantic"), |
106 |
| - ], |
107 |
| - ) |
108 |
| - |
109 |
| - # RViz no MoveIt |
110 |
| - rviz = RVizMixin.node_rviz( |
111 |
| - rviz_config_pkg="lbr_bringup", |
112 |
| - rviz_config="config/config.rviz", |
113 |
| - condition=IfCondition( |
114 |
| - AndSubstitution( |
115 |
| - LaunchConfiguration("rviz"), |
116 |
| - NotSubstitution(LaunchConfiguration("moveit")), |
117 |
| - ) |
118 |
| - ), |
119 |
| - ) |
120 |
| - |
121 |
| - # RViz event handler |
122 |
| - rviz_event_handler = RegisterEventHandler( |
123 |
| - OnProcessExit(target_action=spawn_entity, on_exit=[rviz_moveit, rviz]) |
| 30 | + # robot state publisher |
| 31 | + robot_state_publisher = LBRROS2ControlMixin.node_robot_state_publisher( |
| 32 | + robot_description=robot_description, use_sim_time=True |
124 | 33 | )
|
125 |
| - ld.add_action(rviz_event_handler) |
126 |
| - |
127 |
| - return ld.entities |
| 34 | + ld.add_action( |
| 35 | + robot_state_publisher |
| 36 | + ) # Do not condition robot state publisher on joint state broadcaster as Gazebo uses robot state publisher to retrieve robot description |
128 | 37 |
|
| 38 | + # Gazebo |
| 39 | + ld.add_action(GazeboMixin.include_gazebo()) # Gazebo has its own controller manager |
| 40 | + spawn_entity = GazeboMixin.node_spawn_entity(tf=world_robot_tf) |
| 41 | + ld.add_action(spawn_entity) |
129 | 42 |
|
130 |
| -def generate_launch_description() -> LaunchDescription: |
131 |
| - ld = LaunchDescription() |
132 |
| - ld.add_action(LBRDescriptionMixin.arg_model()) |
133 |
| - ld.add_action(LBRDescriptionMixin.arg_robot_name()) |
134 |
| - ld.add_action( |
135 |
| - DeclareLaunchArgument( |
136 |
| - name="moveit", |
137 |
| - default_value="false", |
138 |
| - description="Whether to launch MoveIt 2.", |
139 |
| - ) |
| 43 | + # controllers |
| 44 | + joint_state_broadcaster = LBRROS2ControlMixin.node_controller_spawner( |
| 45 | + controller="joint_state_broadcaster" |
140 | 46 | )
|
| 47 | + ld.add_action(joint_state_broadcaster) |
141 | 48 | ld.add_action(
|
142 |
| - DeclareLaunchArgument( |
143 |
| - name="rviz", default_value="true", description="Whether to launch RViz." |
| 49 | + LBRROS2ControlMixin.node_controller_spawner( |
| 50 | + controller=LaunchConfiguration("ctrl") |
144 | 51 | )
|
145 | 52 | )
|
146 |
| - ld.add_action( |
147 |
| - LBRROS2ControlMixin.arg_ctrl() |
148 |
| - ) # Gazebo loads controller configuration through lbr_description/gazebo/*.xacro from lbr_ros2_control/config/lbr_controllers.yaml |
149 |
| - ld.add_action(OpaqueFunction(function=launch_setup)) |
150 | 53 | return ld
|
0 commit comments