Skip to content

Commit 61b00da

Browse files
authored
Fix for Controller Switching Issue and Refactor Controller Spawning (#1093)
- make all controllers inactive initially - active the initial_joint_controller if needed - reduce the number of spawners from 3 to 2 (active controllers and inactive controllers) Fixes the issue when forward_position_controller is the initial controller, the user can't switch to scaled_joint_trajectory_controller because it's never spawned.
1 parent 1d1f4c5 commit 61b00da

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

ur_robot_driver/launch/ur_control.launch.py

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,26 @@
2929
#
3030
# Author: Denis Stogl
3131

32-
from launch_ros.actions import Node
33-
from launch_ros.parameter_descriptions import ParameterFile
34-
from launch_ros.substitutions import FindPackageShare
35-
3632
from launch import LaunchDescription
37-
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
33+
from launch.actions import (
34+
DeclareLaunchArgument,
35+
IncludeLaunchDescription,
36+
OpaqueFunction,
37+
)
3838
from launch.conditions import IfCondition, UnlessCondition
39+
from launch.launch_description_sources import AnyLaunchDescriptionSource
3940
from launch.substitutions import (
4041
AndSubstitution,
4142
LaunchConfiguration,
4243
NotSubstitution,
4344
PathJoinSubstitution,
4445
)
45-
from launch.launch_description_sources import AnyLaunchDescriptionSource
46+
from launch_ros.actions import Node
47+
from launch_ros.parameter_descriptions import ParameterFile
48+
from launch_ros.substitutions import FindPackageShare
4649

4750

48-
def launch_setup():
51+
def launch_setup(context):
4952
# Initialize Arguments
5053
ur_type = LaunchConfiguration("ur_type")
5154
robot_ip = LaunchConfiguration("robot_ip")
@@ -163,38 +166,20 @@ def controller_spawner(controllers, active=True):
163166
"speed_scaling_state_broadcaster",
164167
"force_torque_sensor_broadcaster",
165168
]
166-
controllers_inactive = ["forward_position_controller"]
167-
168-
controller_spawners = [controller_spawner(controllers_active)] + [
169-
controller_spawner(controllers_inactive, active=False)
169+
controllers_inactive = [
170+
"scaled_joint_trajectory_controller",
171+
"joint_trajectory_controller",
172+
"forward_velocity_controller",
173+
"forward_position_controller",
170174
]
175+
if activate_joint_controller.perform(context) == "true":
176+
controllers_active.append(initial_joint_controller.perform(context))
177+
controllers_inactive.remove(initial_joint_controller.perform(context))
171178

172-
# There may be other controllers of the joints, but this is the initially-started one
173-
initial_joint_controller_spawner_started = Node(
174-
package="controller_manager",
175-
executable="spawner",
176-
arguments=[
177-
initial_joint_controller,
178-
"-c",
179-
"/controller_manager",
180-
"--controller-manager-timeout",
181-
controller_spawner_timeout,
182-
],
183-
condition=IfCondition(activate_joint_controller),
184-
)
185-
initial_joint_controller_spawner_stopped = Node(
186-
package="controller_manager",
187-
executable="spawner",
188-
arguments=[
189-
initial_joint_controller,
190-
"-c",
191-
"/controller_manager",
192-
"--controller-manager-timeout",
193-
controller_spawner_timeout,
194-
"--inactive",
195-
],
196-
condition=UnlessCondition(activate_joint_controller),
197-
)
179+
controller_spawners = [
180+
controller_spawner(controllers_active),
181+
controller_spawner(controllers_inactive, active=False),
182+
]
198183

199184
rsp = IncludeLaunchDescription(
200185
AnyLaunchDescriptionSource(description_launchfile),
@@ -212,8 +197,6 @@ def controller_spawner(controllers, active=True):
212197
urscript_interface,
213198
rsp,
214199
rviz_node,
215-
initial_joint_controller_spawner_stopped,
216-
initial_joint_controller_spawner_started,
217200
] + controller_spawners
218201

219202
return nodes_to_start
@@ -328,6 +311,12 @@ def generate_launch_description():
328311
DeclareLaunchArgument(
329312
"initial_joint_controller",
330313
default_value="scaled_joint_trajectory_controller",
314+
choices=[
315+
"scaled_joint_trajectory_controller",
316+
"joint_trajectory_controller",
317+
"forward_velocity_controller",
318+
"forward_position_controller",
319+
],
331320
description="Initially loaded robot controller.",
332321
)
333322
)
@@ -479,4 +468,4 @@ def generate_launch_description():
479468
],
480469
)
481470
)
482-
return LaunchDescription(declared_arguments + launch_setup())
471+
return LaunchDescription(declared_arguments + [OpaqueFunction(function=launch_setup)])

0 commit comments

Comments
 (0)