1

I'm working on extracting gps values from a multiwii board via a python script based on this repo.

I have added this to the init function:

self.rawgps = {'fix':0,'numSat':0,'lat':0,'lon':0,'alt':0,'speed':0,'elapsed':0,'timestamp':0}

to the getData function:

elif cmd == MultiWii.RAW_GPS:
    self.rawgps['fix']=float(temp[0]/10.0)
    self.rawgps['numSat']=float(temp[1]/10.0)
    self.rawgps['lat']=float(temp[2]/10.0)
    self.rawgps['lon']=float(temp[3])
    self.rawgps['alt']=float(temp[4])
    self.rawgps['speed']=float(temp[5])
    self.rawgps['elapsed']=round(elapsed,3)
    self.rawgps['timestamp']="%0.2f" % (time.time(),) 
    return self.rawgps

and to the getDataInf function

elif cmd == MultiWii.RAW_GPS:
    self.rawgps['fix']=float(temp[0])
    self.rawgps['numSat']=float(temp[1])
    self.rawgps['lat']=float(temp[2])
    self.rawgps['lon']=float(temp[3])
    self.rawgps['alt']=float(temp[4])
    self.rawgps['speed']=float(temp[5])
    self.rawgps['elapsed']="%0.3f" % (elapsed,)
    self.rawgps['timestamp']="%0.2f" % (time.time(),)

I'm basing this on the output I'm reading at: http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol

When I call the code with

board.getData(MultiWii.RAW_GPS)
print board.rawgps 

The output looks really off. This is what I'm getting

{'alt': -12738.0, 'timestamp': '1494887366.41', 'lat': 6434.0, 'speed': 208.0, 'fix': 2561.0, 'lon': 24919.0, 'numSat': -21303.0, 'elapsed': 0.009}
{'alt': -12738.0, 'timestamp': '1494887366.41', 'lat': 6434.0, 'speed': 208.0, 'fix': 2561.0, 'lon': 24919.0, 'numSat': -21303.0, 'elapsed': 0.009}
{'alt': -12738.0, 'timestamp': '1494887366.41', 'lat': 6434.0, 'speed': 208.0, 'fix': 2561.0, 'lon': 24919.0, 'numSat': -21303.0, 'elapsed': 0.009}
{'alt': -12738.0, 'timestamp': '1494887366.41', 'lat': 6434.0, 'speed': 208.0, 'fix': 2561.0, 'lon': 24919.0, 'numSat': -21303.0, 'elapsed': 0.009}
{'alt': -12738.0, 'timestamp': '1494887366.41', 'lat': 6434.0, 'speed': 208.0, 'fix': 2561.0, 'lon': 24919.0, 'numSat': -21303.0, 'elapsed': 0.009}

The lat and lon don't look like typical lat/lon values to me. Maybe it's a different data type? The fixed, I'm expecting a 1 or 0. And numSats, while I don't see a definition, I feel like it should be the number of satellites I'm connected to, which likely won't be over 15... or negative.

Altitude also shouldn't be negative, and this was all taken while stationary, so the speed should be zero. Python isn't my normal language so maybe I'm losing some in the syntax.

halfer
  • 19,824
  • 17
  • 99
  • 186
John Sly
  • 763
  • 1
  • 10
  • 31
  • 1
    In order to help, we need to see the raw input data that's in `temp`. – martineau May 15 '17 at 23:23
  • To answer the question in the title, you could use `ctypes.c_uint32()` in a manner similar to what's in [this answer](http://stackoverflow.com/a/16452899/355230). – martineau May 15 '17 at 23:32

0 Answers0