pr2_controller_manager_interface.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # Wrappers around the services provided by MechanismControlNode
3 
4 import roslib; roslib.load_manifest('pr2_controller_manager')
5 
6 import sys
7 
8 import rospy
9 from pr2_mechanism_msgs.srv import *
10 
12  rospy.wait_for_service('pr2_controller_manager/list_controller_types')
13  s = rospy.ServiceProxy('pr2_controller_manager/list_controller_types', ListControllerTypes)
14  resp = s.call(ListControllerTypesRequest())
15  for t in resp.types:
16  print(t)
17 
18 def reload_libraries(force_kill, restore = False):
19  rospy.wait_for_service('pr2_controller_manager/reload_controller_libraries')
20  s = rospy.ServiceProxy('pr2_controller_manager/reload_controller_libraries', ReloadControllerLibraries)
21 
22  list_srv = rospy.ServiceProxy('pr2_controller_manager/list_controllers', ListControllers)
23  load_srv = rospy.ServiceProxy('pr2_controller_manager/load_controller', LoadController)
24  switch_srv = rospy.ServiceProxy('pr2_controller_manager/switch_controller', SwitchController)
25 
26  print("Restore:", restore)
27  if restore:
28  originally = list_srv.call(ListControllersRequest())
29 
30  resp = s.call(ReloadControllerLibrariesRequest(force_kill))
31  if resp.ok:
32  print("Successfully reloaded libraries")
33  result = True
34  else:
35  print("Failed to reload libraries. Do you still have controllers loaded?")
36  result = False
37 
38  if restore:
39  for c in originally.controllers:
40  load_srv(c)
41  to_start = []
42  for c, s in zip(originally.controllers, originally.state):
43  if s == 'running':
44  to_start.append(c)
45  switch_srv(start_controllers = to_start,
46  stop_controllers = [],
47  strictness = SwitchControllerRequest.BEST_EFFORT)
48  print("Controllers restored to original state")
49  return result
50 
51 
53  rospy.wait_for_service('pr2_controller_manager/list_controllers')
54  s = rospy.ServiceProxy('pr2_controller_manager/list_controllers', ListControllers)
55  resp = s.call(ListControllersRequest())
56  if len(resp.controllers) == 0:
57  print("No controllers are loaded in mechanism control")
58  else:
59  for c, s in zip(resp.controllers, resp.state):
60  print(c, "(",s,")")
61 
62 def load_controller(name):
63  rospy.wait_for_service('pr2_controller_manager/load_controller')
64  s = rospy.ServiceProxy('pr2_controller_manager/load_controller', LoadController)
65  resp = s.call(LoadControllerRequest(name))
66  if resp.ok:
67  print("Loaded", name)
68  return True
69  else:
70  print("Error when loading", name)
71  return False
72 
74  rospy.wait_for_service('pr2_controller_manager/unload_controller')
75  s = rospy.ServiceProxy('pr2_controller_manager/unload_controller', UnloadController)
76  resp = s.call(UnloadControllerRequest(name))
77  if resp.ok == 1:
78  print("Unloaded %s successfully" % name)
79  return True
80  else:
81  print("Error when unloading", name)
82  return False
83 
84 def start_controller(name):
85  return start_stop_controllers([name], True)
86 
87 def start_controllers(names):
88  return start_stop_controllers(names, True)
89 
90 def stop_controller(name):
91  return start_stop_controllers([name], False)
92 
93 def stop_controllers(names):
94  return start_stop_controllers(name, False)
95 
96 def start_stop_controllers(names, st):
97  rospy.wait_for_service('pr2_controller_manager/switch_controller')
98  s = rospy.ServiceProxy('pr2_controller_manager/switch_controller', SwitchController)
99  start = []
100  stop = []
101  strictness = SwitchControllerRequest.STRICT
102  if st:
103  start = names
104  else:
105  stop = names
106  resp = s.call(SwitchControllerRequest(start, stop, strictness))
107  if resp.ok == 1:
108  if st:
109  print("Started %s successfully" % names)
110  else:
111  print("Stopped %s successfully" % names)
112  return True
113  else:
114  if st:
115  print("Error when starting ", names)
116  else:
117  print("Error when stopping ", names)
118  return False
pr2_controller_manager.pr2_controller_manager_interface.load_controller
def load_controller(name)
Definition: pr2_controller_manager_interface.py:62
srv
pr2_controller_manager.pr2_controller_manager_interface.list_controller_types
def list_controller_types()
Definition: pr2_controller_manager_interface.py:11
pr2_controller_manager.pr2_controller_manager_interface.unload_controller
def unload_controller(name)
Definition: pr2_controller_manager_interface.py:73
pr2_controller_manager.pr2_controller_manager_interface.start_controller
def start_controller(name)
Definition: pr2_controller_manager_interface.py:84
pr2_controller_manager.pr2_controller_manager_interface.start_stop_controllers
def start_stop_controllers(names, st)
Definition: pr2_controller_manager_interface.py:96
pr2_controller_manager.pr2_controller_manager_interface.start_controllers
def start_controllers(names)
Definition: pr2_controller_manager_interface.py:87
pr2_controller_manager.pr2_controller_manager_interface.list_controllers
def list_controllers()
Definition: pr2_controller_manager_interface.py:52
pr2_controller_manager.pr2_controller_manager_interface.stop_controller
def stop_controller(name)
Definition: pr2_controller_manager_interface.py:90
pr2_controller_manager.pr2_controller_manager_interface.stop_controllers
def stop_controllers(names)
Definition: pr2_controller_manager_interface.py:93
pr2_controller_manager.pr2_controller_manager_interface.reload_libraries
def reload_libraries(force_kill, restore=False)
Definition: pr2_controller_manager_interface.py:18


pr2_controller_manager
Author(s): Eric Berger berger@willowgarage.com, Stuart Glaser, Wim Meeussen
autogenerated on Mon Mar 6 2023 03:49:21