get_diagnostic_data.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import roslib; roslib.load_manifest('pr2_motor_diagnostic_tool')
3 import rospy
5 from pr2_mechanism_msgs.srv import LoadController, UnloadController, SwitchController, SwitchControllerRequest, ListControllers
6 from std_msgs.msg import Float64
7 from sensor_msgs.msg import Joy
8 import time
9 import sys
10 import argparse
11 from yaml import dump
12 
13 load_controller = rospy.ServiceProxy('pr2_controller_manager/load_controller', LoadController)
14 unload_controller = rospy.ServiceProxy('pr2_controller_manager/unload_controller',UnloadController)
15 switch_controller = rospy.ServiceProxy('pr2_controller_manager/switch_controller',SwitchController)
16 list_controllers = rospy.ServiceProxy('pr2_controller_manager/list_controllers',ListControllers)
17 
18 flag1 = False
19 flag2 = False
20 
21 #dictionary of actuators and their resistances
22 r_arm_actuators = ['r_wrist_r_motor','r_wrist_l_motor','r_forearm_roll_motor','r_upper_arm_roll_motor', 'r_elbow_flex_motor','r_shoulder_lift_motor','r_shoulder_pan_motor']
23 l_arm_actuators = ['l_wrist_r_motor','l_wrist_l_motor','l_forearm_roll_motor','l_upper_arm_roll_motor', 'l_elbow_flex_motor','l_shoulder_lift_motor','l_shoulder_pan_motor']
24 head_actuators = ['head_pan_motor','head_tilt_motor']
25 
26 def wait_for_X():
27  global flag1
28  flag1 = False
29  while not (flag1):
30  rospy.sleep(0.01)
31 
33  global flag2
34  flag2 = False
35  while not (flag2):
36  rospy.sleep(0.01)
37 
38 def start_diag_controller(actuator_name):
39  rospy.set_param('diagnostic_controller/type', 'pr2_motor_diagnostic_controller/DiagnosticControllerPlugin')
40  rospy.set_param('diag_actuator_name',str(actuator_name))
41  resp = load_controller('diagnostic_controller')
42 
43  if resp.ok:
44  rospy.loginfo("loaded controller dianostic_controller")
45  switch_controller(['diagnostic_controller'],[],SwitchControllerRequest.STRICT)
46  rospy.loginfo("Running diagnostic controller")
47  else:
48  raise RuntimeError("Couldn't load contorller")
49 
50 def get_diag_data(actuator_name):
51  #flag2 = False
52  get_data = rospy.ServiceProxy('diagnostic_controller/get_diagnostic_data',DiagnosticData)
53  rospy.loginfo("getting data for %s, wait 2 seconds",actuator_name)
54 
55  foo = DiagnosticDataRequest();
56  rv = get_data(foo)
57  stream = file(str(actuator_name) + "_results" + '.yaml', 'w')
58  dump(rv,stream)
59 
60  switch_controller([],['diagnostic_controller'], SwitchControllerRequest.STRICT)
61  rospy.loginfo("stopped diagnostic_controller")
62 
63  unload_controller("diagnostic_controller")
64  rospy.loginfo("unload diagnostic_controller")
65 
66 
67 def callback(data):
68  global flag1
69  global flag2
70 
71  if (data.buttons[14] == 1):
72  flag1 = True
73 
74  if (data.buttons[13] == 1):
75  flag2 = True
76 
77 def main():
78  rospy.init_node('get_data', anonymous=True)
79  rospy.Subscriber("joy", Joy, callback)
80  parser = argparse.ArgumentParser("script to get data for Pr2 arms for diagnostic analysis")
81  parser.add_argument("parts", help="Specifiy left, right or both for the arms you want to get diagnostic data for and head for the head.")
82  args = parser.parse_args()
83  actuator_list = []
84  if (args.parts == 'left'):
85  actuator_list = l_arm_actuators
86  elif (args.parts == 'right'):
87  actuator_list = r_arm_actuators
88  elif (args.parts == 'both'):
89  actuator_list = r_arm_actuators + l_arm_actuators
90  elif (args.parts == 'head'):
91  actuator_list = head
92  else:
93  print "Bad arguments, exiting"
94  sys.exit()
95 
96  switch_controller([],['diagnostic_controller'],SwitchControllerRequest.STRICT)
97  unload_controller('diagnostic_controller')
98 
99  for actuator_name in actuator_list:
100  print "Press X to start or for next joint"
101  wait_for_X()
102  start_diag_controller(actuator_name)
103  print "start moving %s for about 5 seconds" %(actuator_name)
104  rospy.sleep(5.0)
105  print "press circle when your done"
106  #rospy.loginfo("move %s for about 5 seconds and then press circle when done", joint_name)
108  get_diag_data(actuator_name)
109 
110 if __name__ == '__main__':
111  try:
112  #test_controller()
113  main()
114  except rospy.ROSInterruptException: pass
115 
def start_diag_controller(actuator_name)
def get_diag_data(actuator_name)


pr2_motor_diagnostic_tool
Author(s): Rahul Udasi
autogenerated on Wed Jan 6 2021 03:39:21