Skip to content

Commit

Permalink
Added GPS firmware integration 📡
Browse files Browse the repository at this point in the history
  • Loading branch information
saoron committed Apr 11, 2017
1 parent 4d93aa8 commit 9e8b0c1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 21 deletions.
Binary file modified assets/images/watermark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 78 additions & 17 deletions classes/gps.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
from config import *
import json
import time
import serial

port = "/dev/ttyS0" # Raspberry Pi 3

class GPS(object):

@classmethod
def getPos(self):

file = open(PARENT_DIR + "/modules/gps/gps.json", 'r')
position = {}

ser = serial.Serial(port, baudrate = 9600, timeout = 1)
latLon = [-1, -1];
speed = 0;

for row in range(0, 10):
data = ser.readline()
latLon = self.parseGPS(data) if self.parseGPS(data) != [-1, -1] else latLon
speed = self.parseSpeed(data) if self.parseSpeed(data)!= -1 else speed

position["latitude"] = latLon[0]
position["longitude"] = latLon[1]
position["speed"] = speed
# TODO
position["heading"] = '-1'

return json.dumps(position)


# Fast method to return current speed
@classmethod
def getSpeed(self):

ser = serial.Serial(port, baudrate = 9600, timeout = 1)
speed = 0;

while True:
data = ser.readline()
speed = self.parseSpeed(data)

if speed > -1:
return self.parseSpeed(data)

return 0

return file.read()

@classmethod
def createNewGPSrecordFile(self, filename):
Expand Down Expand Up @@ -61,19 +97,44 @@ def getPositionObjectByTime(self, time, filename):
except KeyError:
return None

# res = None
# for (i, element) in enumerate(frames):
# # print str(int(element) - int(filename) + int(time)) + ' ' + element
# # print int(element)
# # print int(filename) + int(time)
# # print int(element) < int(int(filename) + int(time))
# # print
# if int(element) < int(filename) + int(time):
# res = (frames[element])
# else:
# print res
# return res

#
# print
# print
@classmethod
def parseGPS(self, data):
lat = lon = -1
if data[0:6] == "$GPGGA":
s = data.split(",")
if s[7] == '0':
print "no satellite data available"
return
lat = self.decode(s[2], s[3])
lon = self.decode(s[4], s[5])

return [lat, lon]

@classmethod
def parseSpeed(self, data):
# print "raw:", data
speed = -1
if data[0:6] == "$GPRMC":
speedParse = data.split(",")
speed = speedParse[7]

return speed

@classmethod
def dms2dd(self, degrees, minutes, seconds, direction):
dd = float(degrees) + float(minutes)/60 + float(seconds)/(60*60);
if direction == 'E' or direction == 'N':
dd *= -1
return dd;

@classmethod
def decode(self, coord, direction):
# DDDMM.MMMMM -> DD deg MM.MMMMM min
v = coord.split(".")
head = v[0]
tail = v[1]
deg = head[0:-2]
min = head[-2:]
return self.dms2dd(deg, min, "0." + tail, direction)

8 changes: 4 additions & 4 deletions mainPi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def run_program():
cap.captureFrame(frame)


# get GPS data
position = json.loads(GPS.getPos())
# get speed from GPS
speed = GPS.getSpeed()

if config['in_calibration'] or (position and position['speed'] < config['activation_speed']):
if (config['calibration']['adas'] and speed > config['activation_speed']) or config['in_calibration']:
# Start ADAS process
frameAnalyzer.analyze_frame(frame, True, True, True)

Expand All @@ -56,4 +56,4 @@ def run_program():


if __name__ == '__main__':
run_program()
run_program()

0 comments on commit 9e8b0c1

Please sign in to comment.