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
00038 PKG = 'pr2_counterbalance_check'
00039 from pr2_counterbalance_check import *
00040
00041
00042 from joint_qualification_controllers.msg import CounterbalanceTestData
00043
00044 from optparse import OptionParser
00045
00046 import sys, os
00047
00048 from ros import rosrecord
00049
00050 import numpy
00051
00052 CB_MSG_TYPE = 'joint_qualification_controllers/CounterbalanceTestData'
00053
00054 def get_data(bag):
00055 for topic, msg, t in rosrecord.logplayer(bag):
00056 return CounterbalanceAnalysisData(msg)
00057
00058 def print_usage(code = 0):
00059 print "./counterbalance_training cb_bag1 cb_bag2 cb_bag3 ..."
00060 print "Determines counterbalance adjustments necessary to tune CB"
00061 print "Bags must have one message of type %s" % CB_MSG_TYPE
00062 sys.exit(code)
00063
00064 if __name__ == '__main__':
00065 if len(sys.argv) < 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
00066 print_usage(1)
00067
00068 bags = sys.argv[1:]
00069
00070 adjustments = {}
00071 efforts = {}
00072 print 'Enter CB adjustments from "zero" in turns CW for each bag'
00073 for b in bags:
00074 if not os.path.exists(b):
00075 print >> sys.stderr, "Bag %s does not exist. Check filename and retry" % b
00076 print_usage(1)
00077
00078
00079 try:
00080 adj_secondary = float(raw_input("Please enter secondary adjustment (turns CW) for bag %s: "%b))
00081 adj_cb_bar = float(raw_input("Please enter CB bar adjustment (turns CW) for bag %s: "%b))
00082 adjustments[b] = (adj_secondary, adj_cb_bar, 1)
00083 except:
00084 print "Invalid input for adjustment. Floating point values expected."
00085 sys.exit(1)
00086
00087 data = get_data(b)
00088 efforts[b] = get_efforts(data, True) + get_efforts(data, False)
00089
00090 B = numpy.array([efforts[b] for b in bags])
00091 A = numpy.array([adjustments[b] for b in bags])
00092 X = numpy.linalg.lstsq(A, B)
00093 model = X[0]
00094 model.dump('counterbalance_model.dat')
00095 print '\"counterbalance_model.dat\" contains CB adjustment values'