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
00036
00037 from __future__ import division
00038
00039 PKG = 'pr2_counterbalance_check'
00040 import roslib
00041
00042 from pr2_counterbalance_check.counterbalance_analysis import *
00043
00044 import copy
00045 import os, sys
00046 import rostest, unittest
00047
00048
00049 class DummyCBAnalysisParams(object): pass
00050 class DummyCBAnalysisData(object): pass
00051 class DummyCBRunAnalysisData(object): pass
00052 class DummyCBPositionAnalysisData(object): pass
00053 class DummyJointPositionAnalysisData(object): pass
00054
00055 def get_position(minv, maxv, num_pts, i):
00056 return minv + (maxv - minv) * i / num_pts
00057
00058 def generate_data(params):
00059 data = DummyCBAnalysisData()
00060 data.lift_data = []
00061 for i in range(params.num_lifts):
00062 lift_data = DummyCBRunAnalysisData()
00063 lift_data.lift_position = get_position(params.min_lift, params.max_lift, params.num_lifts, i)
00064 lift_data.flex_data = []
00065
00066 for j in range(params.num_flexes):
00067 fd = DummyCBPositionAnalysisData()
00068 fd.flex_position = get_position(params.min_flex, params.max_flex, params.num_flexes, j)
00069
00070 fd.lift_hold = DummyJointPositionAnalysisData()
00071 fd.lift_hold.position_avg = lift_data.lift_position
00072 fd.lift_hold.position_sd = 0.0
00073 fd.lift_hold.effort_avg = j / 100.0 - params.num_flexes/200.0
00074 fd.lift_hold.effort_sd = 0.0
00075
00076 fd.flex_hold = DummyJointPositionAnalysisData()
00077 fd.flex_hold.position_avg = fd.flex_position
00078 fd.flex_hold.position_sd = 0.0
00079 fd.flex_hold.effort_avg = j / 100.0 - params.num_flexes/200.0
00080 fd.flex_hold.effort_sd = 0.0
00081
00082 lift_data.flex_data.append(fd)
00083
00084 data.lift_data.append(lift_data)
00085
00086 return data
00087
00088 class TestCounterbalanceAnalysis(unittest.TestCase):
00089 def setUp(self):
00090
00091 self.params = DummyCBAnalysisParams()
00092 self.params.lift_dither = 5.0
00093 self.params.flex_dither = 5.0
00094 self.params.lift_joint = 'lift_joint'
00095 self.params.flex_joint = 'flex_joint'
00096 self.params.timeout_hit = False
00097 self.params.flex_test = True
00098 self.params.lift_mse = 1.0
00099 self.params.lift_avg_abs = 1.0
00100 self.params.lift_avg_eff = 1.0
00101 self.params.flex_mse = 1.0
00102 self.params.flex_avg_abs = 1.0
00103 self.params.flex_avg_eff = 1.0
00104
00105 self.params.screw_tol = 2.0
00106 self.params.bar_tol = 0.8
00107
00108 self.params.num_lifts = 8
00109 self.params.min_lift = -0.2
00110 self.params.max_lift = 1.2
00111
00112 self.params.num_flexes = 9
00113 self.params.min_flex = -1.8
00114 self.params.max_flex = -0.2
00115
00116
00117 self.data = generate_data(self.params)
00118
00119
00120 self.model_file = os.path.join(roslib.packages.get_pkg_dir(PKG), 'cb_data/counterbalance_model.dat')
00121
00122
00123 def test_lift_effort(self):
00124 result = analyze_lift_efforts(self.params, self.data)
00125 self.assert_(result.result, "Lift effort result wasn't OK. %s\n%s" % (result.summary, result.html))
00126
00127 def test_flex_effort(self):
00128 result = analyze_flex_efforts(self.params, self.data)
00129 self.assert_(result.result, "Flex effort result wasn't OK. %s\n%s" % (result.summary, result.html))
00130
00131
00132
00133
00134 def test_adjustment(self):
00135 """
00136 Test that CB adjustment runs successfully
00137 """
00138 (secondary, bar) = calc_cb_adjust(self.data, self.model_file)
00139
00140 self.assert_(abs(secondary) < self.params.screw_tol and abs(bar) < self.params.bar_tol,
00141 "Calculated adjustment didn't match. Adjustment: %.2f, %.2f" % (secondary, bar))
00142
00143 adjust_result = check_cb_adjustment(self.params, self.data, self.model_file)
00144 self.assert_(adjust_result.result, "Adjustment result was unsuccessful! %s\n%s" % (adjust_result.summary, adjust_result.html))
00145
00146
00147 bad_params = copy.deepcopy(self.params)
00148 bad_params.num_lifts = 7
00149 bad_params.max_lift = 1.0
00150
00151 bad_data = generate_data(bad_params)
00152
00153 (secondary, bar) = calc_cb_adjust(bad_data, self.model_file)
00154
00155 self.assert_(abs(secondary) > 50 and abs(bar) > 50,
00156 "Calculated adjustment successful on bad data. Adjustment: %.2f, %.2f" % (secondary, bar))
00157
00158
00159 def test_plots(self):
00160 p_contout_lift = plot_effort_contour(self.params, self.data, True)
00161 p_contout_flex = plot_effort_contour(self.params, self.data, False)
00162
00163 p_eff = plot_efforts_by_lift_position(self.params, self.data)
00164
00165
00166 if __name__ == '__main__':
00167 rostest.unitrun(PKG, 'test_cb_analysis', TestCounterbalanceAnalysis)