Skip to content
Snippets Groups Projects
Commit 954fea9a authored by Daalen, Tim van's avatar Daalen, Tim van
Browse files

gps moving test

parent fda87b6b
Branches
No related tags found
No related merge requests found
...@@ -38,14 +38,16 @@ class TCPReceiver(socketserver.StreamRequestHandler): ...@@ -38,14 +38,16 @@ class TCPReceiver(socketserver.StreamRequestHandler):
#start TCP server which receives the messages from the RUTX11 #start TCP server which receives the messages from the RUTX11
def start_GPSthread(CONFIG): def start_GPSthread(CONFIG):
global TCPServerInstance, GPS_Ringbuffer global TCPServerInstance, GPS_Ringbuffer
GPS_ringbuf.set_min_frame_movement(CONFIG['min-movement-frame']) GPS_ringbuf.set_min_frame_movement(CONFIG['min-movement-pulse'])
GPS_poort = 8500 #port to which the TCP nmea string is send GPS_poort = 8500 #port to which the TCP nmea string is send
for _ in range(0,5): for _ in range(0,5):
ip_address = get_ip_address() ip_address = get_ip_address()
if ip_address != None: break if ip_address != None:
break
sleep(1)
if ip_address == None: if ip_address == None:
raise Exception("Router not connected, shutting down!") raise Exception("Router not connected, shutting down!")
sleep(1)
ServerAddress = (ip_address, GPS_poort) ServerAddress = (ip_address, GPS_poort)
TCPServerInstance = socketserver.ThreadingTCPServer(ServerAddress, TCPReceiver) TCPServerInstance = socketserver.ThreadingTCPServer(ServerAddress, TCPReceiver)
threading.Thread(target=TCPServerInstance.serve_forever).start() threading.Thread(target=TCPServerInstance.serve_forever).start()
......
...@@ -5,6 +5,7 @@ from threading import Thread ...@@ -5,6 +5,7 @@ from threading import Thread
from pypylon import pylon #camera from pypylon import pylon #camera
from itertools import cycle from itertools import cycle
from glob import glob from glob import glob
from sys import maxsize
from global_vars import * from global_vars import *
from usb_Filestorage import * from usb_Filestorage import *
...@@ -50,7 +51,7 @@ class take_img(Thread): ...@@ -50,7 +51,7 @@ class take_img(Thread):
#only process images when we are moving & the GPS buffer is filled #only process images when we are moving & the GPS buffer is filled
if (self.GPS_check == False) or (is_moving == True): if (self.GPS_check == False) or (is_moving == True):
if (self.GPS_check == False) or ((data_obj.lat >= 0) and (data_obj.lng >= 0)): if (self.GPS_check == False) or ((data_obj.lat < maxsize) and (data_obj.lng < maxsize)):
#send image to neural network #send image to neural network
to_process_deque.append({'file_name': filename, 'img': img,'data': data_obj}) to_process_deque.append({'file_name': filename, 'img': img,'data': data_obj})
if self.save_IMGS == True: if self.save_IMGS == True:
......
...@@ -18,7 +18,7 @@ AGENSO: True ...@@ -18,7 +18,7 @@ AGENSO: True
save-GPS: True save-GPS: True
save-IMGS: True save-IMGS: True
save-every-x: 10 #dont save all imgs & GPS coordinates, its simply to much save-every-x: 10 #dont save all imgs & GPS coordinates, its simply to much
min-movement-frame: 0.1 #M between GPS pulses (1 puls/2min) min-movement-pulse: 0.6 #M between GPS pulses (1 puls/2 seconds, 0.6 = 0.3 m/s and 1 km/h)
GPS-checks: True #enable/disable GPS moving checks to facilitate desk debugging GPS-checks: True #enable/disable GPS moving checks to facilitate desk debugging
#AGENSO #AGENSO
......
import json import json
from datetime import datetime from datetime import datetime
from types import SimpleNamespace as Namespace from types import SimpleNamespace as Namespace
from sys import maxsize
#https://medium.com/@yzhong.cs/serialize-and-deserialize-complex-json-in-python-205ecc636caa #https://medium.com/@yzhong.cs/serialize-and-deserialize-complex-json-in-python-205ecc636caa
...@@ -19,8 +19,8 @@ class data_class():#lat, lng, hdop, satnum, gps_quality, timestamp ...@@ -19,8 +19,8 @@ class data_class():#lat, lng, hdop, satnum, gps_quality, timestamp
def __init__(self): def __init__(self):
self.timestamp = "0-0-0T0:0:0" self.timestamp = "0-0-0T0:0:0"
self.gps_quality = "Not valid" #values: Not valid, Fixed, Diff fix, RTK, RTK F self.gps_quality = "Not valid" #values: Not valid, Fixed, Diff fix, RTK, RTK F
self.lat = -1 self.lat = maxsize
self.lng = -1 self.lng = maxsize
self.hdop = 0 self.hdop = 0
self.satnum = 0 self.satnum = 0
self.diseases = [] self.diseases = []
...@@ -99,8 +99,8 @@ class GPS_Ringbuffer: ...@@ -99,8 +99,8 @@ class GPS_Ringbuffer:
self.min_movement = 0 #minimal movement over the entire buffer. self.min_movement = 0 #minimal movement over the entire buffer.
self.decdegr_to_m = 0.00001 #very rough conversion from DD to M self.decdegr_to_m = 0.00001 #very rough conversion from DD to M
self.size = size self.size = size
self.prevlat = 0 self.prevlat = maxsize
self.prevlng = 0 self.prevlng = maxsize
self.prevtimestamp = datetime.utcnow()#.strftime("%y-%m-%dT%H:%M:%S.%f") self.prevtimestamp = datetime.utcnow()#.strftime("%y-%m-%dT%H:%M:%S.%f")
self.data = [] self.data = []
self.f_pnt = 0 #inital poisition self.f_pnt = 0 #inital poisition
...@@ -113,9 +113,9 @@ class GPS_Ringbuffer: ...@@ -113,9 +113,9 @@ class GPS_Ringbuffer:
def update_pointer(self, pointer): def update_pointer(self, pointer):
return (pointer + 1) % self.size return (pointer + 1) % self.size
def set_min_frame_movement(self, min_movement_frame): def set_min_frame_movement(self, min_movement_pulse):
self.min_movement = min_movement_frame * self.decdegr_to_m * self.size self.min_movement = min_movement_pulse * self.decdegr_to_m * self.size
self.min_movement_frame = min_movement_frame * self.decdegr_to_m self.min_movement_frame = min_movement_pulse * self.decdegr_to_m
#put new value in the rinngbuffer en update the values #put new value in the rinngbuffer en update the values
def put(self, nmea_GGA_msg, timestamp): def put(self, nmea_GGA_msg, timestamp):
...@@ -136,7 +136,7 @@ class GPS_Ringbuffer: ...@@ -136,7 +136,7 @@ class GPS_Ringbuffer:
self.data[self.f_pnt].gpsquality = nmea_GGA_msg.gps_qual self.data[self.f_pnt].gpsquality = nmea_GGA_msg.gps_qual
self.data[self.f_pnt].gpstime = nmea_GGA_msg.timestamp.strftime("%y-%m-%dT%H:%M:%S.%f") self.data[self.f_pnt].gpstime = nmea_GGA_msg.timestamp.strftime("%y-%m-%dT%H:%M:%S.%f")
self.data[self.f_pnt].rectime = timestamp.strftime("%y-%m-%dT%H:%M:%S.%f") self.data[self.f_pnt].rectime = timestamp.strftime("%y-%m-%dT%H:%M:%S.%f")
self.data[self.f_pnt].moving = self.determine_hasmoved() self.data[self.f_pnt].moving = self.determine_hasmoved_fast()
#print('prev_lat: %f, lat: %f, diff: %f' %(self.prevlat, lat, self.data[self.f_pnt].latdif)) #print('prev_lat: %f, lat: %f, diff: %f' %(self.prevlat, lat, self.data[self.f_pnt].latdif))
#print('prev_lng: %f, lng: %f, diff: %f' %(self.prevlng, lng, self.data[self.f_pnt].lngdif)) #print('prev_lng: %f, lng: %f, diff: %f' %(self.prevlng, lng, self.data[self.f_pnt].lngdif))
self.prevtimestamp = timestamp self.prevtimestamp = timestamp
...@@ -174,7 +174,7 @@ class GPS_Ringbuffer: ...@@ -174,7 +174,7 @@ class GPS_Ringbuffer:
for pos in self.data: for pos in self.data:
total_latdiff += pos.latdif total_latdiff += pos.latdif
total_lngdiff += pos.lngdif total_lngdiff += pos.lngdif
total_movement = total_latdiff + total_lngdiff total_movement = abs(total_latdiff + total_lngdiff)
if (total_movement > self.min_movement): if (total_movement > self.min_movement):
return True return True
else: else:
...@@ -187,7 +187,7 @@ class GPS_Ringbuffer: ...@@ -187,7 +187,7 @@ class GPS_Ringbuffer:
lat_movement = abs(itemone.lat - itemtwo.lat) lat_movement = abs(itemone.lat - itemtwo.lat)
lng_movement = abs(itemone.lng - itemtwo.lng) lng_movement = abs(itemone.lng - itemtwo.lng)
total_movement = lat_movement + lng_movement total_movement = abs(lat_movement + lng_movement)
if (total_movement > self.min_movement): if (total_movement > self.min_movement):
return True return True
else: else:
...@@ -220,9 +220,25 @@ class GPS_Ringbuffer: ...@@ -220,9 +220,25 @@ class GPS_Ringbuffer:
#fake nmea class, used to initialise the RING buffer #fake nmea class, used to initialise the RING buffer
class fake_nmea_class: class fake_nmea_class:
def __init__(self,prevtimestamp): def __init__(self,prevtimestamp):
self.latitude = -1 self.latitude = maxsize
self.longitude = -1 self.longitude = maxsize
self.horizontal_dil = 0 self.horizontal_dil = 0
self.num_sats = 0 self.num_sats = 0
self.gps_qual = 0 self.gps_qual = 0
self.timestamp = prevtimestamp self.timestamp = prevtimestamp
\ No newline at end of file
if __name__ == '__main__':
fnc = fake_nmea_class(datetime.now())
gps_test = GPS_Ringbuffer(5)
gps_test.set_min_frame_movement(0.1)
lat_init = 52.64538985
lon_init = 5.667874878
for i in range(6):
fnc.latitude = lat_init + (i * 1e-6)
fnc.longitude = lon_init + (i * 1e-6)
gps_test.put(fnc, datetime.now())
(obj, is_moving) = gps_test.get_dataobject(datetime.now())
print(is_moving)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment