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