Skip to content

Commit 2d18c40

Browse files
committed
ros2_control 4.42.2 bug workaround
1 parent f8b3390 commit 2d18c40

1 file changed

Lines changed: 47 additions & 7 deletions

File tree

src/robot_description/launch/robot.launch.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from launch_ros.actions import Node
4646
from launch_ros.substitutions import FindPackageShare
4747

48+
import yaml
4849
import xacro
4950

5051

@@ -70,7 +71,26 @@ def launch_setup(context, *_args, **_kwargs):
7071

7172
robot_description_content = xacro.process_file(description_file).toxml()
7273

73-
# The Controller Manager (CM) connects the controllers’ and
74+
with open(controllers_config_file, "r") as f:
75+
controllers_config = yaml.safe_load(f)
76+
77+
# NOTE: ros2_control 4.42.2 bug workaround.
78+
# When ros2_control_node spawns a controller it passes its own --params-file
79+
# arguments down to the controller sub-node. File paths are silently lost in
80+
# that propagation (the path becomes empty), which causes every controller to
81+
# crash on load:
82+
# "Couldn't parse trailing --params-file flag. No file path provided."
83+
# Only parameters passed as Python dicts (written to a temp file by the
84+
# launch system) survive the propagation correctly.
85+
# Fix: pass the controller_manager section of the YAML as a dict, and
86+
# supply the controller-specific parameters (joints, etc.) to each spawner
87+
# via --param-file, which uses the parameter service and is unaffected.
88+
# TODO: revert to passing controllers_config_file directly once fixed.
89+
controller_manager_params = controllers_config.get("controller_manager", {}).get(
90+
"ros__parameters", {}
91+
)
92+
93+
# The Controller Manager (CM) connects the controllers' and
7494
# hardware-abstraction sides of the ros2_control framework. It also serves
7595
# as the entry-point for users through ROS services.
7696
# https://control.ros.org/master/doc/getting_started/getting_started.html#architecture
@@ -79,7 +99,7 @@ def launch_setup(context, *_args, **_kwargs):
7999
executable="ros2_control_node",
80100
parameters=[
81101
{"robot_description": robot_description_content},
82-
controllers_config_file,
102+
controller_manager_params,
83103
],
84104
output={
85105
"stdout": "screen",
@@ -97,25 +117,39 @@ def launch_setup(context, *_args, **_kwargs):
97117
"joint_state_broadcaster",
98118
"--controller-manager",
99119
"/controller_manager",
120+
"--param-file",
121+
controllers_config_file,
100122
],
101123
)
102124

103-
# This is a controller that work using the velocity joint command
125+
# This is a controller that work using the "velocity" joint command
104126
# interface.
105127
# https://control.ros.org/master/doc/ros2_controllers/velocity_controllers/doc/userdoc.html
106128
velocity_controller_spawner = Node(
107129
package="controller_manager",
108130
executable="spawner",
109-
arguments=["velocity_controller", "-c", "/controller_manager"],
131+
arguments=[
132+
"velocity_controller",
133+
"-c",
134+
"/controller_manager",
135+
"--param-file",
136+
controllers_config_file,
137+
],
110138
)
111139

112-
# This is a controller that work using the position joint command
140+
# This is a controller that work using the "position" joint command
113141
# interface.
114142
# https://control.ros.org/master/doc/ros2_controllers/position_controllers/doc/userdoc.html
115143
position_controller_spawner = Node(
116144
package="controller_manager",
117145
executable="spawner",
118-
arguments=["position_controller", "-c", "/controller_manager"],
146+
arguments=[
147+
"position_controller",
148+
"-c",
149+
"/controller_manager",
150+
"--param-file",
151+
controllers_config_file,
152+
],
119153
)
120154

121155
# Controller for executing joint-space trajectories on a group of joints.
@@ -127,7 +161,13 @@ def launch_setup(context, *_args, **_kwargs):
127161
joint_trajectory_controller_spawner = Node(
128162
package="controller_manager",
129163
executable="spawner",
130-
arguments=["joint_trajectory_controller", "-c", "/controller_manager"],
164+
arguments=[
165+
"joint_trajectory_controller",
166+
"-c",
167+
"/controller_manager",
168+
"--param-file",
169+
controllers_config_file,
170+
],
131171
)
132172

133173
# robot_state_publisher uses the URDF specified by the parameter robot

0 commit comments

Comments
 (0)