counterbalance_training.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2010, Willow Garage, Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Willow Garage nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 ##\author Eric Berger, Kevin Watts
36 ##\brief Determines counterbalance adjustments based on CB data
37 
38 PKG = 'pr2_counterbalance_check'
39 from pr2_counterbalance_check import *
40 
41 
42 from joint_qualification_controllers.msg import CounterbalanceTestData
43 
44 from optparse import OptionParser
45 
46 import sys, os
47 
48 from ros import rosrecord
49 
50 import numpy
51 
52 CB_MSG_TYPE = 'joint_qualification_controllers/CounterbalanceTestData'
53 
54 def get_data(bag):
55  for topic, msg, t in rosrecord.logplayer(bag):
56  return CounterbalanceAnalysisData(msg)
57 
58 def print_usage(code = 0):
59  print "./counterbalance_training cb_bag1 cb_bag2 cb_bag3 ..."
60  print "Determines counterbalance adjustments necessary to tune CB"
61  print "Bags must have one message of type %s" % CB_MSG_TYPE
62  sys.exit(code)
63 
64 if __name__ == '__main__':
65  if len(sys.argv) < 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
66  print_usage(1)
67 
68  bags = sys.argv[1:]
69 
70  adjustments = {}
71  efforts = {}
72  print 'Enter CB adjustments from "zero" in turns CW for each bag'
73  for b in bags:
74  if not os.path.exists(b):
75  print >> sys.stderr, "Bag %s does not exist. Check filename and retry" % b
76  print_usage(1)
77 
78  #Ask for adjustments when this bag was taken
79  try:
80  adj_secondary = float(raw_input("Please enter secondary adjustment (turns CW) for bag %s: "%b))
81  adj_cb_bar = float(raw_input("Please enter CB bar adjustment (turns CW) for bag %s: "%b))
82  adjustments[b] = (adj_secondary, adj_cb_bar, 1)
83  except:
84  print "Invalid input for adjustment. Floating point values expected."
85  sys.exit(1)
86 
87  data = get_data(b)
88  efforts[b] = get_efforts(data, True) + get_efforts(data, False)
89 
90  B = numpy.array([efforts[b] for b in bags])
91  A = numpy.array([adjustments[b] for b in bags])
92  X = numpy.linalg.lstsq(A, B)
93  model = X[0]
94  model.dump('counterbalance_model.dat')
95  print '\"counterbalance_model.dat\" contains CB adjustment values'
def get_efforts(data, lift_calc)
Get average efforts for CB test as a list.


pr2_counterbalance_check
Author(s): Kevin Watts
autogenerated on Wed Jan 6 2021 03:39:25