(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Writing Subtests for the PR2 Self Test System

Description: Shows how to write a subtest for the PR2 Self Test system

Tutorial Level:

Subtest Basics

The core of the qualification system are subtests. A subtest might test a particular feature of a component, or of the entire robot. Subtests use roslaunch files to load all parameters and nodes for a test, collect data and perform analysis, and call a "result service" with the results.

The PR2 Self Test manager does not do any analysis for any subtest. Different subtests written for PR2 components are:

  • Hysteresis analysis
  • Checkout (make sure all joints, actuators OK)
  • Counterbalance test
  • Self-test (for IMU, hokuyos, cameras)
  • Wrist symmetry test

Subtests on mechanical components, such as the hysteresis test, call a controller and an analyzer node. The analyzer node (qualification/scripts/hysteresis_sinesweep_analysis.py) processes the data from the controllers and reports the results.

All subtests must meet call a pr2_self_test_msg/TestResult service ('test_result') with the relevant data. The launch files will be shut down automatically by the qualification system.

Result Service Call

The pr2_self_test_msg/TestResult contains all the data the qualification system needs to analyze, display and record the data.

byte RESULT_PASS = 0
byte RESULT_FAIL = 1

byte result
Plot[] plots
string text_summary
string html_result
TestParam[] params
TestValue[] values
  • TestResultRequest/result values are handled as follows:
    • RESULT_PASS: Continue to the next subtest, or finish with success
    • RESULT_FAIL: Stop test and shutdown, record failure
    • RESULT_HUMAN_REQUIRED: The analysis will be presented to the operator, who may retry or fail the test
  • TestResultRequest/plots should be in "png" format, and can be generated by matplotlib in python.
  • The text_summary field should be several relevant lines of text summarizing the results.
  • The html_result contains properly formatted HTML that can completely document the results.
  • Parameters and values are for parameters and measurements of the subtest. They are designed to be a machine readable way of examining groups of components.

Formatting Subtest HTML Results

The html_result field of qualification/srv/TestResultRequest contains the complete documentation of the subtest. Emphasis should be on completeness. Any "quick facts" about the test should be in the text_summary and the result fields. Qualification/results.py will process the results and display them in the GUI window.

To keep the results properly formatted, follow the style example below for all result HTML.

<!-- qualification/results.py will add headers and a style sheet automatically -->
<!-- HTML output of any subtest in the html_result field -->
<H4>Data Stuff</H4>
<p>Add any details about data here.</p>
<H5>Data Sub-stuff</H5>
<p>Use H4 for main headers, H5 for smaller ones. Only use the following table format.</p>
<table border="1" cellpadding="2" cellspacing="0">
<tr><td><b>Column 1</b></td><td><b>Column 2</b></td></tr>
<hr size="2">
<H4>More Data Stuff>
<p>Use hr, size 2 to divide everything neatly. If you want, you can add colors for pass and fail. Div class "pass", "warn" and "error" are defined as Green, Orange and Red backgrounds respectively. <div class="pass">PASS</div>.</p>
<img src="IMG_PATH/my_image.png" width="640" height="480">
<p>See the next section for details of how to add images.<p>
<!-- '</body>' and '</html>' added automatically by results.py -->

Most analysis scripts automatically generate HTML for the results. It is best to set up the HTML output to have separate lines for each output to make it human readable (use '\n').

Adding Images

To add images, you must add the image stream as a PNG image to the TestResultRequest. This is easy to do in python. The following example is from simple_test/analyzer_node.py.

   1 import numpy, matplotlib
   2 import matplotlib.plot as plt
   3 from StringIO import StringIO
   5 # Making the plot in matplotlib
   6 plt.plot([1,2,3,4],[16, 9, 4, 1], 'ro')
   7 plt.xlabel("Pirates")
   8 plt.ylabel("Ninjas")
  10 # Saving it as a StringIO
  11 stream = StringIO()
  12 plt.savefig(stream, format="png")
  13 image = stream.getvalue()
  15 # Appending it to the result.plots field
  16 r = pr2_self_test_msgs.srv.TestResultRequest()
  17 p = pr2_self_test_msgs.msg.Plot()
  18 r.plots.append(p)
  19 p.image = image
  20 p.image_format = "png"
  21 p.title = "pirates_and_ninjas" # Do not put spaces in the title

Images must be added to the HTML output to be seen in the qualification window an in any result database. To do this, add:

<img src="IMG_PATH/pirates_and_ninjas.png" width="640" height="480" >

The "IMG_PATH/" prefix to the image name will allow the qual system to save the HTML in the proper settings for tar files, invent uploads, display and emails. A good size for images is around 640 by 480.

Pre/Post Subtests

Pre- and post- subtests can be used to set parameters or other tasks before a subtest. To add them, simply put a "pre" or "post" attribute in the subtest line. These pre and post subtests will spin() indefinitely, so they must exit or die gracefully on their own. Generally, they should only be used to set parameters, such as which side a test is on (param full_arm_test/side="r").

<subtest pre="right_side.launch">my_test.launch</subtest>

Wiki: qualification/Writing Subtests (last edited 2010-06-26 00:20:18 by KevinWatts)