@@ -33,6 +33,7 @@ from control_msgs.msg import FollowJointTrajectoryAction, FollowJointTrajectoryG
3333from trajectory_msgs .msg import JointTrajectoryPoint
3434from controller_manager_msgs .srv import SwitchControllerRequest , SwitchController
3535from controller_manager_msgs .srv import LoadControllerRequest , LoadController
36+ from controller_manager_msgs .srv import ListControllers , ListControllersRequest
3637import geometry_msgs .msg as geometry_msgs
3738from cartesian_control_msgs .msg import (
3839 FollowCartesianTrajectoryAction ,
@@ -88,6 +89,7 @@ class TrajectoryClient:
8889 "controller_manager/switch_controller" , SwitchController
8990 )
9091 self .load_srv = rospy .ServiceProxy ("controller_manager/load_controller" , LoadController )
92+ self .list_srv = rospy .ServiceProxy ("controller_manager/list_controllers" , ListControllers )
9193 try :
9294 self .switch_srv .wait_for_service (timeout .to_sec ())
9395 except rospy .exceptions .ROSException as err :
@@ -265,6 +267,12 @@ class TrajectoryClient:
265267
266268 other_controllers .remove (target_controller )
267269
270+ srv = ListControllersRequest ()
271+ response = self .list_srv (srv )
272+ for controller in response .controller :
273+ if controller .name == target_controller and controller .state == "running" :
274+ return
275+
268276 srv = LoadControllerRequest ()
269277 srv .name = target_controller
270278 self .load_srv (srv )
0 commit comments