parameters: (logfile)
docstring: find best magnetometer offset fit to a log file
docstring_summary: find best magnetometer offset fit to a log file
docstring_tokens: find best magnetometer offset fit to a log file
function: def magfit(logfile):
      '''find best magnetometer offset fit to a log file'''
  
      print("Processing log %s" % filename)
  
      # open the log file
      flog = open(filename, mode='r')
  
      data = []
      data_no_motors = []
      mag = None
      offsets = None
      
      # now gather all the data
      for line in flog:
          if not line.startswith('COMPASS,'):
              continue
          line = line.rstrip()
          line = line.replace(' ', '')
          a = line.split(',')
          ofs = Vector3(float(a[4]), float(a[5]), float(a[6]))
          if offsets is None:
              initial_offsets = ofs
          offsets = ofs
          motor_ofs = Vector3(float(a[7]), float(a[8]), float(a[9]))
          mag = Vector3(float(a[1]), float(a[2]), float(a[3]))
          mag = mag - offsets
          data.append(mag)
          data_no_motors.append(mag - motor_ofs)
  
      print("Extracted %u data points" % len(data))
      print("Current offsets: %s" % initial_offsets)
  
      # run the fitting algorithm
      ofs = initial_offsets
      for r in range(opts.repeat):
          ofs = find_offsets(data, ofs)
          plot_corrected_field('plot.dat', data, ofs)
          plot_corrected_field('initial.dat', data, initial_offsets)
          plot_corrected_field('zero.dat', data, Vector3(0,0,0))
          plot_corrected_field('hand.dat', data, Vector3(-25,-8,-2))
          plot_corrected_field('zero-no-motors.dat', data_no_motors, Vector3(0,0,0))
          print('Loop %u offsets %s' % (r, ofs))
          sys.stdout.flush()
      print("New offsets: %s" % ofs)
function_tokens: def magfit ( logfile ) : print ( "Processing log %s" % filename ) # open the log file flog = open ( filename , mode = 'r' ) data = [ ] data_no_motors = [ ] mag = None offsets = None # now gather all the data for line in flog : if not line . startswith ( 'COMPASS,' ) : continue line = line . rstrip ( ) line = line . replace ( ' ' , '' ) a = line . split ( ',' ) ofs = Vector3 ( float ( a [ 4 ] ) , float ( a [ 5 ] ) , float ( a [ 6 ] ) ) if offsets is None : initial_offsets = ofs offsets = ofs motor_ofs = Vector3 ( float ( a [ 7 ] ) , float ( a [ 8 ] ) , float ( a [ 9 ] ) ) mag = Vector3 ( float ( a [ 1 ] ) , float ( a [ 2 ] ) , float ( a [ 3 ] ) ) mag = mag - offsets data . append ( mag ) data_no_motors . append ( mag - motor_ofs ) print ( "Extracted %u data points" % len ( data ) ) print ( "Current offsets: %s" % initial_offsets ) # run the fitting algorithm ofs = initial_offsets for r in range ( opts . repeat ) : ofs = find_offsets ( data , ofs ) plot_corrected_field ( 'plot.dat' , data , ofs ) plot_corrected_field ( 'initial.dat' , data , initial_offsets ) plot_corrected_field ( 'zero.dat' , data , Vector3 ( 0 , 0 , 0 ) ) plot_corrected_field ( 'hand.dat' , data , Vector3 ( - 25 , - 8 , - 2 ) ) plot_corrected_field ( 'zero-no-motors.dat' , data_no_motors , Vector3 ( 0 , 0 , 0 ) ) print ( 'Loop %u offsets %s' % ( r , ofs ) ) sys . stdout . flush ( ) print ( "New offsets: %s" % ofs )