def gpsLoop(inParams): #log path savePath, printLive = inParams #setup gps device #wait for gps attach? gps = GPS() gps.openPhidget() gps.waitForAttach(10000) print "GPS attached" #set up logging: gpsLog = open(savePath+'/Gps.log','w') #change handler def gpsChangeHandler1(e): gps_time = gps.getTime().toString() gps_lat = gps.getLatitude() gps_lon = gps.getLongitude() gps_alt = gps.getAltitude() gps_heading = gps.getHeading() gps_vel = gps.getVelocity() time1 = str(datetime.datetime.now()) dataElems = [time1, gps_time, gps_lat, gps_lon,gps_alt,gps_heading,gps_vel] dataElems = [str(x) for x in dataElems] return ','.join(dataElems)+'\n', (gps_lat, gps_lon, gps_alt) #(','.join(dataElems)+'\n') #gpsLog.flush() #gps.setOnPositionChangeHandler(gpsChangeHandler1) data, xyzPos = gpsChangeHandler1(1) gpsLog.write(data) while True: time.sleep(0.1) newData, newXyz = gpsChangeHandler1(1) if xyzPos == newXyz: pass else: #log new data print "position changed", newXyz xyzPos = newXyz gpsLog.write(newData) gpsLog.flush()
def gpsLoop(inParams): #log path savePath, printLive = inParams #setup gps device #wait for gps attach? gps = GPS() gps.openPhidget() gps.waitForAttach(10000) print "GPS attached" #set up logging: gpsLog = open(savePath+'/Gps.log','w') #change handler def gpsChangeHandler1(e): gps_time = gps.getTime().toString() gps_date = gps.getDate().toString() gps_lat = gps.getLatitude() gps_lon = gps.getLongitude() gps_alt = gps.getAltitude() gps_heading = gps.getHeading() gps_vel = gps.getVelocity() time1 = str(datetime.datetime.now()) dataElems = [time1, gps_time, gps_date, gps_lat, gps_lon,gps_alt,gps_heading,gps_vel] dataElems = [str(x) for x in dataElems] return ','.join(dataElems)+'\n', (gps_lat, gps_lon, gps_alt) #(','.join(dataElems)+'\n') #gpsLog.flush() #gps.setOnPositionChangeHandler(gpsChangeHandler1) data, xyzPos = gpsChangeHandler1(1) gpsLog.write("sysTime, gpsTime, gpsDate, Lat, Lon, Alt, Heading, Velocity\n") gpsLog.write(data) logCounter = 0 while True: logCounter = logCounter+1 #tune sleep timer to image capture rate... time.sleep(0.18) data, xyzPos = gpsChangeHandler1(1) gpsLog.write(data) if logCounter%10==0: gpsLog.flush()
def activate(self): """Phidget GPS Must be attached via USB cable and powered before calling, sets is_ready() to True when done""" try: self.phidget = GPS() self.phidget.openPhidget() except RuntimeError as e: print("Runtime Exception: %s" % e.details) try: self.phidget.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: self.phidget.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) self.ready = True
""" __author__ = "Adam Stelmack" __version__ = "2.1.8" __date__ = "14-Jan-2011 3:01:06 PM" #Basic imports import sys #Phidget specific imports from Phidgets.PhidgetException import PhidgetException from Phidgets.Devices.GPS import GPS from Phidgets.Phidget import PhidgetLogLevel #Create an accelerometer object try: gps = GPS() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) #Information Display Function def displayDeviceInfo(): print( "|------------|----------------------------------|--------------|------------|" ) print( "|- Attached -|- Type -|- Serial No. -|- Version -|" ) print(
print("Closing...") try: gps.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Done.") exit(0) atexit.register(clean_up) gps = None try: gps = GPS() gps.openPhidget() gps.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) print("Date,Time,Lat,Long,Altitude,Velocity,Heading") while True: try: print("{0},{1},{2},{3},{4},{5},{6}".format( gps.getDate().toString(), gps.getTime().toString(), gps.getLatitude(), gps.getLongitude(),
from numpy import mean, median from upoints import point from drivers.servo import MaestroServoController from drivers.cmps03_compass import CMPS03 from Phidgets.PhidgetException import PhidgetException from Phidgets.Devices.GPS import GPS WAYPOINTS = [ (39.720382,-104.706065), ] curr_waypoint = 0 #### GPS SETUP gps = None try: gps = GPS() gps.openPhidget() gps.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) ### SERVO SETUP servo = MaestroServoController(port="COM3") servo.reset_all() THROTTLE_MAX = 1600 THROTTLE_MIN = 1585 STEERING_FULL_RIGHT = 1654 STEERING_FULL_LEFT = 1454 STEERING_CENTER = 1554 STEERING_GAIN = 1.04
def AttachGPS(databasepath, serialNumber): def onAttachHandler(event): logString = "GPS Attached " + str(event.device.getSerialNum()) #print(logString) DisplayAttachedDeviceInfo(event.device) def onDetachHandler(event): logString = "GPS Detached " + str(event.device.getSerialNum()) #print(logString) DisplayDetachedDeviceInfo(event.device) event.device.closePhidget() def onErrorHandler(event): logString = "GPS Error " + str(event.device.getSerialNum()) + ", Error: " + event.description print(logString) DisplayErrorDeviceInfo(event.device) def onServerConnectHandler(event): logString = "GPS Server Connect " + str(event.device.getSerialNum()) #print(logString) def onServerDisconnectHandler(event): logString = "GPS Server Disconnect " + str(event.device.getSerialNum()) #print(logString) def positionChangeHandler(event): logString = "GPS Position Changed" #print(logString) try: conn = sqlite3.connect(databasepath) conn.execute("INSERT INTO GPS_POSITIONCHANGE VALUES(NULL, DateTime('now'), ?, ?, ?)", (event.device.getSerialNum(), event.index, event.position)) conn.commit() conn.close() except sqlite3.Error as e: print "An error occurred:", e.args[0] def positionFixStatusChangeHandler(event): logString = "GPS Position Fix Status Changed" #print(logString) try: conn = sqlite3.connect(databasepath) conn.execute("INSERT INTO GPS_POSITIONFIXSTATUSCHANGE VALUES(NULL, DateTime('now'), ?, ?, ?)", (event.device.getSerialNum(), event.index, event.position)) conn.commit() conn.close() except sqlite3.Error as e: print "An error occurred:", e.args[0] try: p = GPS() p.setOnAttachHandler(onAttachHandler) p.setOnDetachHandler(onDetachHandler) p.setOnErrorhandler(onErrorHandler) p.setOnServerConnectHandler(onServerConnectHandler) p.setOnServerDisconnectHandler(onServerDisconnectHandler) p.setOnPositionChangeHandler(positionChangeHandler) p.setOnPositionFixStatusChangeHandler(positionFixStatusChangeHandler) p.openPhidget(serialNumber) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting...") exit(1)
""" __author__ = "Adam Stelmack" __version__ = "2.1.8" __date__ = "14-Jan-2011 3:01:06 PM" # Basic imports import sys # Phidget specific imports from Phidgets.PhidgetException import PhidgetException from Phidgets.Devices.GPS import GPS # Create an accelerometer object try: gps = GPS() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) # Information Display Function def displayDeviceInfo(): print("|------------|----------------------------------|--------------|------------|") print("|- Attached -|- Type -|- Serial No. -|- Version -|") print("|------------|----------------------------------|--------------|------------|") print( "|- %8s -|- %30s -|- %10d -|- %8d -|" % (gps.isAttached(), gps.getDeviceName(), gps.getSerialNum(), gps.getDeviceVersion()) ) print("|------------|----------------------------------|--------------|------------|")
#Basic imports from ctypes import * import sys import random from datetime import datetime #Phidget specific imports from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, OutputChangeEventArgs, SensorChangeEventArgs from Phidgets.Devices.InterfaceKit import InterfaceKit from Phidgets.Devices.GPS import GPS #Create an interfacekit object try: interfaceKit = InterfaceKit() gps = GPS() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) #Information Display Function def displayDeviceInfo(): print("|------------|----------------------------------|--------------|------------|") print("|- Attached -|- Type -|- Serial No. -|- Version -|") print("|------------|----------------------------------|--------------|------------|") print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (interfaceKit.isAttached(), interfaceKit.getDeviceName(), interfaceKit.getSerialNum(), interfaceKit.getDeviceVersion())) print("|------------|----------------------------------|--------------|------------|") print("Number of Digital Inputs: %i" % (interfaceKit.getInputCount())) print("Number of Digital Outputs: %i" % (interfaceKit.getOutputCount())) print("Number of Sensor Inputs: %i" % (interfaceKit.getSensorCount()))
"""Prints one pull of GPS Data""" from geopy import distance from numpy import mean, median from upoints import point from Phidgets.PhidgetException import PhidgetException from Phidgets.Devices.GPS import GPS #### GPS SETUP gps = None try: gps = GPS() gps.openPhidget() gps.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) while 1: try: latitude = float(gps.getLatitude()) longitude = float(gps.getLongitude()) heading = float(gps.getHeading()) fix = gps.getPositionFixStatus() print ('lat:{0} long:{1} heading:{2} fix:{3}'.format(latitude, longitude, heading, fix)) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details))
import cv, time, datetime, sys from Phidgets.Devices.GPS import GPS saveDir = '/data/tmpImg' logFile = open('/data/tmpImg/runLog.txt', 'w') gps = GPS() gps.openPhidget() gps.waitForAttach(10000) gps_time = gps.getTime().toString() capture = cv.CaptureFromCAM(0) cv.SetCaptureProperty(capture, 3, 1280) cv.SetCaptureProperty(capture, 4, 720) header = 'imgName,curTime,elpTime,gps_time,gps_vel, gps_heading, gps_lon,gps_lat,gps_alt\n' logFile.write(header) for i in range(2000): #print 1 curTime = str(datetime.datetime.now()) imgName = 'testImg' + str(i).zfill(5) + '.jpg' img = cv.QueryFrame(capture) #print 2 #cv.ShowImage("camera", img) cv.SaveImage(saveDir + '/' + imgName, img) #print 3 #gps stuff... gps_time = gps.getTime().toString() gps_lat = gps.getLatitude()
def AttachGPS(databasepath, serialNumber): def onAttachHandler(event): logString = "GPS Attached " + str(event.device.getSerialNum()) #print(logString) DisplayAttachedDeviceInfo(event.device) def onDetachHandler(event): logString = "GPS Detached " + str(event.device.getSerialNum()) #print(logString) DisplayDetachedDeviceInfo(event.device) event.device.closePhidget() def onErrorHandler(event): logString = "GPS Error " + str( event.device.getSerialNum()) + ", Error: " + event.description print(logString) DisplayErrorDeviceInfo(event.device) def onServerConnectHandler(event): logString = "GPS Server Connect " + str(event.device.getSerialNum()) #print(logString) def onServerDisconnectHandler(event): logString = "GPS Server Disconnect " + str(event.device.getSerialNum()) #print(logString) def positionChangeHandler(event): logString = "GPS Position Changed" #print(logString) try: conn = sqlite3.connect(databasepath) conn.execute( "INSERT INTO GPS_POSITIONCHANGE VALUES(NULL, DateTime('now'), ?, ?, ?)", (event.device.getSerialNum(), event.index, event.position)) conn.commit() conn.close() except sqlite3.Error as e: print "An error occurred:", e.args[0] def positionFixStatusChangeHandler(event): logString = "GPS Position Fix Status Changed" #print(logString) try: conn = sqlite3.connect(databasepath) conn.execute( "INSERT INTO GPS_POSITIONFIXSTATUSCHANGE VALUES(NULL, DateTime('now'), ?, ?, ?)", (event.device.getSerialNum(), event.index, event.position)) conn.commit() conn.close() except sqlite3.Error as e: print "An error occurred:", e.args[0] try: p = GPS() p.setOnAttachHandler(onAttachHandler) p.setOnDetachHandler(onDetachHandler) p.setOnErrorhandler(onErrorHandler) p.setOnServerConnectHandler(onServerConnectHandler) p.setOnServerDisconnectHandler(onServerDisconnectHandler) p.setOnPositionChangeHandler(positionChangeHandler) p.setOnPositionFixStatusChangeHandler(positionFixStatusChangeHandler) p.openPhidget(serialNumber) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting...") exit(1)
""" simple gps test """ print "starting up!" from Phidgets.Devices.GPS import GPS import datetime, sys gps = GPS() gps.openPhidget() print "waiting for attach" gps.waitForAttach(10000) print "attached!" gps_time = gps.getTime().toString() def gpsChangeHandler1(e): gps_time = gps.getTime().toString() gps_lat = gps.getLatitude() gps_lon = gps.getLongitude() gps_alt = gps.getAltitude() gps_heading = gps.getHeading() gps_vel = gps.getVelocity() time1 = str(datetime.datetime.now()) dataElems = [time1, gps_time, gps_lat, gps_lon] dataElems = [str(x) for x in dataElems] print ','.join(dataElems) print "testing function" gpsChangeHandler1(1)
#find last log entry, start numbering with most recent, else start over try: inLog = open(outLogPath,'r').readlines() #image name first in list lastFrame = inLog[-1].split(',')[0] print "last frame captured:", lastFrame lastFrameCount = int(lastFrame[7:-4]) curFrame = lastFrameCount+1 except: curFrame = 1 #raise('oops') logFile = open(outLogPath,'w') gps = GPS() gps.openPhidget() gps.waitForAttach(10000) gps_time = gps.getTime().toString() #eventually add logic for gps fix here... captureA = cv.CaptureFromCAM(0) cv.SetCaptureProperty(captureA, 3, 1280) cv.SetCaptureProperty(captureA, 4, 720) captureB = cv.CaptureFromCAM(1) cv.SetCaptureProperty(captureB, 3, 1280) cv.SetCaptureProperty(captureB, 4, 720)
class GPSPhidgets(GPSDevice): """ This class implements the GPS facade for the Phidgets GPS. """ phidget = None # Holds reference to Phidget device, populated from activate def get_current_latitude(self): try: self.latitude = self.phidget.getLatitude() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.latitude def get_current_longitude(self): try: self.longitude = self.phidget.getLongitude() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.longitude def get_current_velocity(self): """Returns the current GPS-derived speed in miles per hour""" try: self.velocity = self.phidget.getVelocity() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.velocity def get_current_altitude(self): """Returns the current altitude in decimal feet""" try: self.altitude = self.phidget.getAltitude() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.altitude def get_current_heading(self): """Returns the current GPS-derived heading in degrees""" try: self.heading = self.phidget.getHeading() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.heading def get_time(self): """Returns a datetime.time object with the current time from the GPS""" try: phidget_time = self.phidget.getTime() self.time = datetime.time(phidget_time.tm_hour, phidget_time.tm_min, phidget_time.tm_sec, phidget_time.tm_ms) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.time def get_date(self): """Returns a datetime.date object with the current date from the GPS""" try: phidget_date = self.phidget.getDate() self.date = datetime.date(phidget_date.tm_year, phidget_date.tm_mon, phidget_date.tm_mday) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.date def get_datetime(self): """Returns a datetime.datetime object with the current date and time from the GPS""" try: self.date_time = datetime.datetime.combine(self.get_date(), self.get_time()) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) return self.date_time def is_ready(self): """Returns True if the GPS is ready to return data (on, booted, sat lock, etc.)""" fix_status = self.phidget.getPositionFixStatus() if not fix_status: self.ready = False return self.ready def activate(self): """Phidget GPS Must be attached via USB cable and powered before calling, sets is_ready() to True when done""" try: self.phidget = GPS() self.phidget.openPhidget() except RuntimeError as e: print("Runtime Exception: %s" % e.details) try: self.phidget.waitForAttach(10000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) try: self.phidget.closePhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) self.ready = True def deactivate(self): """Tells the GPS to shut down, sets is_ready() to False when done""" self.phidget.closePhidget() self.ready = False
from Phidgets.Phidget import Phidget from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException from Phidgets.Events.Events import SpatialDataEventArgs, AttachEventArgs, DetachEventArgs, ErrorEventArgs from Phidgets.Devices.Spatial import Spatial, SpatialEventData, TimeSpan from Phidgets.Devices.GPS import GPS import urllib, httplib2 springxd_url = 'http://phidgets.mikepwright.dyndns.ws:8080' h = httplib2.Http(".cache") # WAT? h.add_credentials("user", "******", "http://192.168.0.108:9020") #Create an accelerometer object try: spatial = Spatial() gps = GPS() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) #Information Display Function def DisplayDeviceInfo(): print( "|------------|----------------------------------|--------------|------------|" ) print( "|- Attached -|- Type -|- Serial No. -|- Version -|" ) print(