While the Euro RPy-Rover explores new worlds the Command Centre must keep track of its whereabouts. To do this we fitted the rover with a GPS module, that outputs the rover’s coordinates whenever queried.
- Raspberry Pi B+
- 66-Channel Locosys LS20031 GPS Receiver Module (MT3339 Chipset)
The LS20031 has an integrated ceramic antenna that enables it to acquire a fix from a cold start in 32 seconds. It saves satellite information, so it can acquire a hot-start fix in less than 1 second.
The LS20031 GPS has surface contacts, which are trickier to solder than pins. Of the five contacts on the device we only require three: Vcc, Tx and the Gnd immediatly next to it.
|GPS Vcc||RPi 1||Vcc 3.3V|
|GPS Rx||Not connected||UART RX
Not needed, as we will only listen to the GPS
|GPS Tx||RPi 10||UART GPS Tx / RPi Rx|
|GPS Gnd (1)||RPi 6||Ground|
|GPS Gnd (2)||Not connected||(do not connect)|
The GPS used is capable of outputting different NMEA strings. These strings contain different GPS data, such as lattitude, longitude, groundspeed, altitude, etc. According to its manual “The LS20031 GPS receiver module’s firmware is initially set to a 5Hz update rate, a 57600bps serial communication rate, and is set to output GGA, GLL, GSV, GSA, RMC, and VTG NMEA sentences.”
For our project we only needed latitude and longitude, which is present in multiple NMEA strings, including the RMC that is outputted five times per second in the default configuration. By using this string we avoided the need to change the configuration of the device.
To read the GPS device and select RMC strings we used the following code:
def getrmc(): serial = wp.serialOpen("/dev/ttyAMA0",57600) # open serial port wp.serialFlush(serial) print(serial) while True: # repeat until we get a RMC NMEA string gpsstring = "" while True: # repeat until we have a complete string if (wp.serialDataAvail(serial) > 0): letter = wp.serialGetchar(serial) if letter == 10: break else: gpsstring += str(chr(letter)) if (gpsstring[3:6]=="RMC"): break wp.serialClose(serial) return(gpsstring)
According to the data sheet of the manufacturer, the RMC string has the following format:
NMEA RMC string example:
The data we want is between the third and seventh comma. We created the following function to parse the string received by the function above and return a string composed of the signed floating values for latitude and longitude, sepparated by a comma.
def cmd_read_GPS(): reading=getrmc() # determine the position of the value separating commas commas = [0,1,2,3,4,5,6,7,8,9,10,11] comnum = 0 for i in range (0,len(reading)): if reading[i] == ",": commas[comnum] = i # save the position of the comma comnum += 1 # Extract latitude if (reading[commas + 1:commas]) == "N": sign = 1 else: sign = -1 degrees = float(reading[commas+1:commas+3]) minutes = float(reading[commas + 3:commas])/60 latitude = sign*(degrees + minutes) # Extract Longitude if (reading[commas + 1:commas]) == "E": sign = 1 else: sign = -1 degrees = float(reading[commas+1:commas+3]) minutes = float(reading[commas + 3:commas])/60 longitude = sign*(degrees + minutes) return(str(latitude),",",str(longitude))
You can download all the Euro RPy-Rover’s code at the project’s GitHub Python repository.
Previous tutorial: Avoiding rover collisions
First tutorial: Controlling the RPy-Rover’s motors