analyzer_node.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2008, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
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 # Randomly generate result if given random keyword
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 # block until the test_result service is available
00118 rospy.wait_for_service('test_result')
00119 result_service.call(r)
00120 rospy.spin()
00121 


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34