7 myc1_running=
'my_controller1 - hardware_interface::EffortJointInterface ( running )\n' 8 myc1_stopped=
'my_controller1 - hardware_interface::EffortJointInterface ( stopped )\n' 9 myc2_running=
'my_controller2 - hardware_interface::EffortJointInterface ( running )\n' 10 myc2_stopped=
'my_controller2 - hardware_interface::EffortJointInterface ( stopped )\n' 14 loaded_fmt =
'Loaded %s\n' 15 unloaded_fmt =
'Unloaded %s successfully\n' 16 stopped_fmt =
"Stopped ['%s'] successfully\n" 17 started_fmt =
"Started ['%s'] successfully\n" 19 no_controllers =
'No controllers are loaded in mechanism control\n' 20 reload_response =
'Restore: False\nSuccessfully reloaded libraries\n' 24 return subprocess.check_output(
'rosrun controller_manager controller_manager ' +
' '.join(args), shell=
True)
28 return run_cm(
'load', name), loaded_fmt % name
31 return run_cm(
'unload', name), unloaded_fmt % name
34 return run_cm(
'stop', name), stopped_fmt % name
37 return run_cm(
'start', name), started_fmt % name
40 return run_cm(
'spawn', name), loaded_fmt % name + started_fmt % name
43 return run_cm(
'kill', name), stopped_fmt % name + unloaded_fmt % name
47 rospy.wait_for_service(
"/controller_manager/list_controllers", 2.0)
50 listed_types =
run_cm(
'list-types').split()
51 self.assertIn(
'controller_manager_tests/EffortTestController', listed_types)
54 self.assertEqual(
run_cm(
'list'), no_controllers)
57 s1 = subprocess.Popen(
'rosrun controller_manager spawner my_controller1 __name:=myspawner', shell=
True)
59 self.assertEqual(
run_cm(
'list'), myc1_running)
62 self.assertEqual(*
load_c(
'my_controller2'))
63 self.assertEqual(
run_cm(
'list'), myc1_running + myc2_stopped)
66 self.assertEqual(*
stop_c(
'my_controller1'))
67 self.assertEqual(
run_cm(
'list'), myc1_stopped + myc2_stopped)
70 self.assertEqual(*
start_c(
'my_controller2'))
71 self.assertEqual(
run_cm(
'list'), myc1_stopped + myc2_running)
74 self.assertEqual(*
stop_c(
'my_controller2'))
75 self.assertEqual(
run_cm(
'list'), myc1_stopped + myc2_stopped)
78 self.assertEqual(*
start_c(
'my_controller1'))
79 self.assertEqual(
run_cm(
'list'), myc1_running + myc2_stopped)
82 u1 = subprocess.Popen(
'rosrun controller_manager unspawner my_controller1 __name:=myunspawner', shell=
True)
84 self.assertEqual(
run_cm(
'list'), myc1_stopped + myc2_stopped)
87 subprocess.check_call(
'rosnode kill /myunspawner', shell=
True)
88 self.assertEqual(u1.wait(), 0)
89 self.assertEqual(
run_cm(
'list'), myc1_running + myc2_stopped)
92 subprocess.check_call(
'rosnode kill /myspawner', shell=
True)
93 self.assertEqual(0, s1.wait())
94 self.assertEqual(
run_cm(
'list'), myc2_stopped)
97 self.assertEqual(*
spawn_c(
'my_controller1'))
98 self.assertEqual(
run_cm(
'list'), myc2_stopped + myc1_running)
101 self.assertEqual(*
kill_c(
'my_controller1'))
102 self.assertEqual(
run_cm(
'list'), myc2_stopped)
105 self.assertEqual(*
unload_c(
'my_controller2'))
106 self.assertEqual(
run_cm(
'list'), no_controllers)
108 self.assertEqual(
run_cm(
'reload-libraries'), reload_response)
110 if __name__ ==
'__main__':
112 rostest.rosrun(
'controller_manager_msgs',
113 'controller_manager_scripts_rostest',