extracting full location info using SBP python for piksi Multi

114 views
Skip to first unread message

Kirk Martinez

unread,
Aug 14, 2018, 10:59:58 AM8/14/18
to swiftnav-discuss
I have finally needed to decode SBP (rather than my usual NMEA).
The python library is rather tricky to get started with - as the example prints some data but its not clear how to get lat lon height etc
I know this is a bit lazyweb - but I'm sure others would need such a simple example too ;-)

Cheers!
Kirk
Message has been deleted

Matthias Füller

unread,
Sep 28, 2018, 3:54:52 AM9/28/18
to swiftnav-discuss

with PySerialDriver(args.port[0], baud=1000000) as driver:
   
with Handler(Framer(driver.read, None, verbose=True)) as source:
   
try:
       
for msg, metadata in source.filter(SBP_MSG_BASELINE_NED):
           
print "%.4f,%.4f,%.4f" % (msg.n * 1e-3, msg.e * 1e-3, msg.d * 1e-3)

   
except KeyboardInterrupt:
 
         
pass


just change the filter to None and you will receive any msg type:
...
       for msg, metadata in source.filter():            
           
if(isinstance(msg, sbp.navigation.MsgUtcTime)):
                 
....
           
if(isinstance(msg, sbp.navigation.MsgBaselineNED)):
             
....
           
if(isinstance(msg, sbp.navigation.MsgPosLLH)):
                 
print(msg.lat, msg.lon, msg.height, msg.h_accuracy)
             
....

you'll find the attributes of each msg in the protocol specs:


Regads,
Matthias

Pheoemph

unread,
Jul 10, 2019, 1:10:25 AM7/10/19
to swiftnav-discuss



Try this.....

 setup a serial connection and then after this works for you change the msg type to whatever type you like, read from the specification and decode as you wish.  MSG types are little endian so when searching the specification for 0x020C, use \x0C\x02 in python. and vise versa

Regards

data = b''
BIG_MSG = 45 #a size bigger than the longest msg we care to decode
PREAMBLE = 6 #this is the length of the preamble 0x55 plus the length and the message type bytes.
GPSTimeOfWeek = 0
while True:
            data += serialPort.read(100)
            
            while True:
                index = data.find(b"\x55") #the location of the first preamble byte
                #this line checks to see if there is enough data that it makes sense to even attempt to process the message.
if len(data) < index + BIG_MSG or index == -1:
                    continue
                
                length = data[index+5] #the length of the actual message

                output = ''
                msgType = data[index+1:index+3] #you can get these magic numbers from the SBP message specification
                
                #print("time: %s length: %s index: %s" % (struct.unpack('<i',data[index+6:index+10])[0], len(data), index))
                    
                if msgType == b"\x0c\x02":     #Rover NED's
                    output = {
                        'GPS_TimeOfWeek' : (struct.unpack('<i',data[index+6:index+10])[0]),#in milliseconds
                        'north' : struct.unpack('<i',data[index+10:index+14])[0]*0.001,
                        'east' : struct.unpack('<i',data[index+14:index+18])[0]*0.001,
                        #FIXFLAG is an enumeration for readability in the log... you can just put the number if you wish.
'fixmode' : FIXFLAG(data[index+27]).name
                    }
data = data[index+length+PREAMBLE:] #chop the data chunk we've already used.
Reply all
Reply to author
Forward
0 new messages