Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import roslib
00036 roslib.load_manifest('qualification')
00037
00038 import sys
00039 import rospy
00040 from std_srvs.srv import Empty
00041 from pr2_self_test_msgs.srv import TestResult, TestResultRequest
00042 from pr2_self_test_msgs.msg import Plot, TestParam, TestValue
00043 import time
00044 import random
00045 import rospy
00046
00047 import matplotlib.pyplot as plt
00048 from StringIO import StringIO
00049
00050 if (len(sys.argv) <= 1):
00051 rospy.logerr('Must specify one of pass/fail/human/random')
00052 sys.exit(0)
00053
00054 rospy.init_node("test_analyzer")
00055
00056 test_service = rospy.ServiceProxy('self_test', Empty)
00057 result_service = rospy.ServiceProxy('test_result', TestResult)
00058
00059 rospy.wait_for_service('self_test')
00060 test_service()
00061
00062 r = TestResultRequest()
00063 r.plots = []
00064 r.params = []
00065 r.params.append(TestParam('P Gain', '5.0'))
00066 r.params.append(TestParam('I Gain', '1.0'))
00067 r.params.append(TestParam('D Gain', '0.0'))
00068 r.params.append(TestParam('I Clamp', '0.0'))
00069
00070 r.values = []
00071 r.values.append(TestValue('Effort', '4.0', '2.0', '5.0'))
00072 r.values.append(TestValue('Low Range', '-2.0', '', '-1.5'))
00073 r.values.append(TestValue('High Range', '2.0', '1.5', ''))
00074
00075 my_arg = sys.argv[1]
00076
00077
00078 if my_arg == "random":
00079 val = random.randint(0, 2)
00080 if val == 0:
00081 my_arg = "pass"
00082 elif val == 1:
00083 my_arg = "fail"
00084 else:
00085 my_arg = "human"
00086
00087 if (my_arg == "pass"):
00088 r.html_result = "<p>Test succeeded.</p>"
00089 r.text_summary = "Test passed."
00090 r.result = TestResultRequest.RESULT_PASS
00091 r.values.append(TestValue('Velocity', '2.0', '1.5', '2.5'))
00092 elif (my_arg == "fail"):
00093 r.html_result = "<p>Test failed.</p>"
00094 r.result = TestResultRequest.RESULT_FAIL
00095 r.text_summary = "Test Failed."
00096 r.values.append(TestValue('Velocity', '1.0', '1.5', '2.5'))
00097 else:
00098 r.text_summary = "Human input required."
00099 r.result = TestResultRequest.RESULT_HUMAN_REQUIRED
00100 r.values.append(TestValue('Velocity', '1.5', '1.5', '2.5'))
00101
00102 plt.plot([1,2,3,4],[16, 9, 4, 1], 'ro')
00103 plt.xlabel("Pirates")
00104 plt.ylabel("Ninjas")
00105 stream = StringIO()
00106 plt.savefig(stream, format="png")
00107 image = stream.getvalue()
00108
00109 r.html_result = "<p>Does the correlation between pirates and ninjas make sense?</p>\n<br><img src=\"IMG_PATH/pirates_and_ninjas.png\", width = 640, height = 480 />"
00110
00111 p = Plot()
00112 r.plots.append(p)
00113 p.image = image
00114 p.image_format = "png"
00115 p.title = "pirates_and_ninjas"
00116
00117
00118 rospy.wait_for_service('test_result')
00119 result_service.call(r)
00120 rospy.spin()
00121