Skip to content

Commit

Permalink
Use global description package and update launch files
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed Aug 18, 2023
1 parent ff06aa4 commit 1994f4e
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 591 deletions.
2 changes: 1 addition & 1 deletion example_14/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install(
DESTINATION include/ros2_control_demo_example_14
)
install(
DIRECTORY description/launch description/ros2_control description/urdf description/rviz
DIRECTORY description/launch description/ros2_control description/urdf
DESTINATION share/ros2_control_demo_example_14
)
install(
Expand Down
216 changes: 0 additions & 216 deletions example_14/bringup/launch/rrbot_base.launch.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021, Stogl Robotics Consulting UG (haftungsbeschränkt)
# 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 @@ -26,8 +30,8 @@ def generate_launch_description():
"prefix",
default_value='""',
description="Prefix of the joint names, useful for \
multi-robot setup. If changed, joint names in the controllers' configuration \
also have to be updated.",
multi-robot setup. If changed than also joint names in the controllers' configuration \
have to be updated.",
)
)
declared_arguments.append(
Expand All @@ -42,22 +46,108 @@ def generate_launch_description():
description="Robot controller to start.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"gui",
default_value="true",
description="Start RViz2 automatically with this launch file.",
)
)

# Initialize Arguments
prefix = LaunchConfiguration("prefix")
slowdown = LaunchConfiguration("slowdown")
robot_controller = LaunchConfiguration("robot_controller")
gui = LaunchConfiguration("gui")

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

robot_controllers = PathJoinSubstitution(
[
FindPackageShare("ros2_control_demo_example_14"),
"config",
"rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.yaml",
]
)
rviz_config_file = PathJoinSubstitution(
[FindPackageShare("ros2_control_demo_description"), "rrbot/rviz", "rrbot.rviz"]
)

base_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), "/rrbot_base.launch.py"]),
launch_arguments={
"controllers_file": "rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.yaml",
"description_file": "rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.urdf.xacro",
"prefix": prefix,
"use_fake_hardware": "false",
"slowdown": slowdown,
"robot_controller": robot_controller,
}.items(),
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(gui),
)

return LaunchDescription(declared_arguments + [base_launch])
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 1994f4e

Please sign in to comment.