Skip to content

Commit

Permalink
Remove rrbot_base.launch.py from example folders (#268)
Browse files Browse the repository at this point in the history
* Example 3: remove rrbot_base launch file

* Example 4: remove rrbot_base launch file

* Example 5: remove rrbot_base launch file

* Example 6: remove rrbot_base launch file

* Example 8: remove rrbot_base launch file
  • Loading branch information
christophfroehlich authored Jun 22, 2023
1 parent a1ab06c commit fa1c2e4
Show file tree
Hide file tree
Showing 11 changed files with 578 additions and 1,122 deletions.
205 changes: 0 additions & 205 deletions example_3/bringup/launch/rrbot_base.launch.py

This file was deleted.

144 changes: 128 additions & 16 deletions example_3/bringup/launch/rrbot_system_multi_interface.launch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Department of Engineering Cybernetics, NTNU.
# Copyright 2021 Stogl Robotics Consulting UG (haftungsbeschränkt)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,13 @@
# limitations under the License.

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, ThisLaunchFileDir
from launch.actions import DeclareLaunchArgument, RegisterEventHandler
from launch.conditions import IfCondition
from launch.event_handlers import OnProcessExit
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
Expand All @@ -30,6 +34,21 @@ def generate_launch_description():
have to be updated.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"use_mock_hardware",
default_value="false",
description="Start robot with mock hardware mirroring command to its states.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"mock_sensor_commands",
default_value="false",
description="Enable fake command interfaces for sensors used for simple simulations. \
Used only if 'use_mock_hardware' parameter is true.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"slowdown", default_value="50.0", description="Slowdown factor of the RRbot."
Expand All @@ -42,23 +61,116 @@ def generate_launch_description():
description="Robot controller to start.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"start_rviz",
default_value="true",
description="Start RViz2 automatically with this launch file.",
)
)

# Initialize Arguments
prefix = LaunchConfiguration("prefix")
use_mock_hardware = LaunchConfiguration("use_mock_hardware")
mock_sensor_commands = LaunchConfiguration("mock_sensor_commands")
slowdown = LaunchConfiguration("slowdown")
robot_controller = LaunchConfiguration("robot_controller")
start_rviz = LaunchConfiguration("start_rviz")

# Get URDF via xacro
robot_description_content = Command(
[
PathJoinSubstitution([FindExecutable(name="xacro")]),
" ",
PathJoinSubstitution(
[
FindPackageShare("ros2_control_demo_example_3"),
"urdf",
"rrbot_system_multi_interface.urdf.xacro",
]
),
" ",
"prefix:=",
prefix,
" ",
"use_mock_hardware:=",
use_mock_hardware,
" ",
"mock_sensor_commands:=",
mock_sensor_commands,
" ",
"slowdown:=",
slowdown,
]
)
robot_description = {"robot_description": robot_description_content}

base_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), "/rrbot_base.launch.py"]),
launch_arguments={
"controllers_file": "rrbot_multi_interface_forward_controllers.yaml",
"description_file": "rrbot_system_multi_interface.urdf.xacro",
"prefix": prefix,
"use_mock_hardware": "false",
"mock_sensor_commands": "false",
"slowdown": slowdown,
"robot_controller": robot_controller,
}.items(),
robot_controllers = PathJoinSubstitution(
[
FindPackageShare("ros2_control_demo_example_3"),
"config",
"rrbot_multi_interface_forward_controllers.yaml",
]
)
rviz_config_file = PathJoinSubstitution(
[FindPackageShare("ros2_control_demo_example_3"), "rviz", "rrbot.rviz"]
)

return LaunchDescription(declared_arguments + [base_launch])
control_node = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[robot_description, robot_controllers],
output="both",
)
robot_state_pub_node = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
output="both",
parameters=[robot_description],
)
rviz_node = Node(
package="rviz2",
executable="rviz2",
name="rviz2",
output="log",
arguments=["-d", rviz_config_file],
condition=IfCondition(start_rviz),
)

joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"],
)

robot_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=[robot_controller, "--controller-manager", "/controller_manager"],
)

# Delay rviz start after `joint_state_broadcaster`
delay_rviz_after_joint_state_broadcaster_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_broadcaster_spawner,
on_exit=[rviz_node],
)
)

# Delay start of robot_controller after `joint_state_broadcaster`
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_broadcaster_spawner,
on_exit=[robot_controller_spawner],
)
)

nodes = [
control_node,
robot_state_pub_node,
joint_state_broadcaster_spawner,
delay_rviz_after_joint_state_broadcaster_spawner,
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner,
]

return LaunchDescription(declared_arguments + nodes)
Loading

0 comments on commit fa1c2e4

Please sign in to comment.