Skip to content

Commit

Permalink
Use launch_utils instead of a spawner per controller (backport #666) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 16, 2024
1 parent 2faa6d2 commit fc9898f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 73 deletions.
9 changes: 8 additions & 1 deletion example_13/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ install(
)

if(BUILD_TESTING)
find_package(ament_cmake_ros REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)
find_package(ament_cmake_pytest REQUIRED)

ament_add_pytest_test(example_13_urdf_xacro test/test_urdf_xacro.py)
ament_add_pytest_test(view_example_13_launch test/test_view_robot_launch.py)
ament_add_pytest_test(run_example_13_launch test/test_three_robots_launch.py)

function(add_ros_isolated_launch_test path)
set(RUNNER "${ament_cmake_ros_DIR}/run_test_isolated.py")
add_launch_test("${path}" RUNNER "${RUNNER}" ${ARGN})
endfunction()
add_ros_isolated_launch_test(test/test_three_robots_launch.py)
endif()

## EXPORTS
Expand Down
105 changes: 37 additions & 68 deletions example_13/bringup/launch/three_robots.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from controller_manager.launch_utils import generate_controllers_spawner_launch_description


def generate_launch_description():
Expand Down Expand Up @@ -87,7 +88,10 @@ def generate_launch_description():
control_node = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[robot_description, robot_controllers],
parameters=[robot_controllers],
remappings=[
("~/robot_description", "/robot_description"),
],
)
robot_state_pub_node = Node(
package="robot_state_publisher",
Expand All @@ -104,73 +108,44 @@ def generate_launch_description():
condition=IfCondition(gui),
)

# Separate robot state publishers for each robot

# Global joint state broadcaster
joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster"],
# global broadcaster and initially active controllers from RRBot
general_ctrl_spawner = generate_controllers_spawner_launch_description(
[
# Global joint state broadcaster
"joint_state_broadcaster",
# RRBot controllers
"rrbot_joint_state_broadcaster",
"rrbot_position_controller",
# External FTS broadcaster
"rrbot_external_fts_broadcaster",
],
controller_params_files=[robot_controllers],
)

# RRBot controllers
rrbot_joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["rrbot_joint_state_broadcaster"],
)
rrbot_position_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["rrbot_position_controller"],
)
# External FTS broadcaster
rrbot_external_fts_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["rrbot_external_fts_broadcaster"],
# RRBot with sensors controllers, initially active
rrbot_sensor_ctrl_spawner_active = generate_controllers_spawner_launch_description(
["rrbot_with_sensor_joint_state_broadcaster", "rrbot_with_sensor_fts_broadcaster"],
controller_params_files=[robot_controllers],
)

# RRBot controllers
rrbot_with_sensor_joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["rrbot_with_sensor_joint_state_broadcaster"],
)
rrbot_with_sensor_position_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=[
# RRBot with sensors controllers, initially inactive
rrbot_sensor_ctrl_spawner_inactive = generate_controllers_spawner_launch_description(
[
"rrbot_with_sensor_position_controller",
"--inactive",
],
)
rrbot_with_sensor_fts_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["rrbot_with_sensor_fts_broadcaster"],
controller_params_files=[robot_controllers],
extra_spawner_args=["--inactive"],
)

# ThreeDofBot controllers
threedofbot_joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=[
# ThreeDofBot controllers, initially inactive
threedofbot_ctrl_spawner = generate_controllers_spawner_launch_description(
[
"threedofbot_joint_state_broadcaster",
"-c",
"/controller_manager",
"--inactive",
"threedofbot_position_controller",
"threedofbot_pid_gain_controller",
],
)
threedofbot_position_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["threedofbot_position_controller", "--inactive"],
)
threedofbot_pid_gain_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["threedofbot_pid_gain_controller", "--inactive"],
controller_params_files=[robot_controllers],
extra_spawner_args=["--inactive"],
)

# Command publishers
Expand All @@ -197,16 +172,10 @@ def generate_launch_description():
control_node,
robot_state_pub_node,
rviz_node,
joint_state_broadcaster_spawner,
rrbot_joint_state_broadcaster_spawner,
rrbot_position_controller_spawner,
rrbot_external_fts_broadcaster_spawner,
rrbot_with_sensor_joint_state_broadcaster_spawner,
rrbot_with_sensor_position_controller_spawner,
rrbot_with_sensor_fts_broadcaster_spawner,
threedofbot_joint_state_broadcaster_spawner,
threedofbot_position_controller_spawner,
threedofbot_pid_gain_controller_spawner,
general_ctrl_spawner,
rrbot_sensor_ctrl_spawner_active,
rrbot_sensor_ctrl_spawner_inactive,
threedofbot_ctrl_spawner,
rrbot_position_command_publisher,
rrbot_with_sensor_position_command_publisher,
threedofbot_position_command_publisher,
Expand Down
7 changes: 6 additions & 1 deletion example_13/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
<exec_depend>xacro</exec_depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>launch_testing_ros</test_depend>
<test_depend>ament_cmake_ros</test_depend>
<test_depend>launch_ros</test_depend>
<test_depend>launch_testing_ament_cmake</test_depend>
<test_depend>launch_testing</test_depend>
<test_depend>launch</test_depend>
<test_depend>liburdfdom-tools</test_depend>
<test_depend>rclpy</test_depend>
<test_depend>ros2_control_demo_testing</test_depend>
<test_depend>xacro</test_depend>

Expand Down
4 changes: 1 addition & 3 deletions example_13/test/test_three_robots_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# Author: Christoph Froehlich

import os
import pytest
import unittest
import subprocess

Expand All @@ -48,8 +47,7 @@
)


# Executes the given launch file and checks if all nodes can be started
@pytest.mark.rostest
# Executes the given launch file
def generate_test_description():
launch_include = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
Expand Down

0 comments on commit fc9898f

Please sign in to comment.