import smbus #import SMBus module of I2C import math from time import sleep #import import os import time import datetime from datetime import datetime, timedelta from neo6 import GpsNeo6 gps=GpsNeo6(port="/dev/ttyUSB0",debit=9600,diff=2) #diff is difference between utc time en local time from hmc5883l import hmc5883l compass = hmc5883l(gauss = 4.7, declination = (-2,5)) #some MPU6050 Registers and their Address PWR_MGMT_1 = 0x6B SMPLRT_DIV = 0x19 CONFIG = 0x1A GYRO_CONFIG = 0x1B INT_ENABLE = 0x38 ACCEL_XOUT_H = 0x3B ACCEL_YOUT_H = 0x3D ACCEL_ZOUT_H = 0x3F GYRO_XOUT_H = 0x43 GYRO_YOUT_H = 0x45 GYRO_ZOUT_H = 0x47 def MPU_Init(): #write to sample rate register bus.write_byte_data(Device_Address, SMPLRT_DIV, 7) #Write to power management register bus.write_byte_data(Device_Address, PWR_MGMT_1, 1)
def main(): ''' Defining a variable to name all the functions of the gps ''' gps = GpsNeo6(port="/dev/ttyAMA0", debit=9600, diff=2) #diff is difference betw$ lat_FGC = 41.56344849685262 long_FGC = 2.0190451151906927 ''' current position and where to walk to... start just 1m ahead ''' target_polar = [5.0, 0.0] curr = targ = rect(target_polar) ''' initialize OpenAL context, asking for 44.1kHz to match HRIR data ''' contextAttr = [ALC_FREQUENCY, 44100, 0] device = alcOpenDevice(None) context = alcCreateContext(device, (ctypes.c_int * len(contextAttr))(*contextAttr)) alcMakeContextCurrent(context) ''' listener at origin, facing down -z (ears at 1.5m height) ''' alListener3f(AL_POSITION, 0., 1.5, 0.) alListener3f(AL_VELOCITY, 0., 0., 0.) orient = [0.0, 0.0, -1.0, 0.0, 1.0, 0.0] alListenerfv(AL_ORIENTATION, (ctypes.c_float * len(orient))(*orient)) ''' this will be the source of ghostly footsteps... ''' source = c_uint(0) alGenSources(1, source) alSourcef(source, AL_PITCH, 1.) alSourcef(source, AL_GAIN, 1.) alSource3f(source, AL_POSITION, curr[0], curr[1], curr[2]) alSource3f(source, AL_VELOCITY, 0., 0., 0.) alSourcei(source, AL_LOOPING, AL_TRUE) ''' allocate an OpenAL buffer and fill it with monaural sample data ''' buffer = ctypes.c_uint(0) alGenBuffers(1, ctypes.pointer(buffer)) data = load('nord.raw') dataSize = ctypes.c_int(len(data)) # for simplicity, assume raw file is signed-16b at 44.1kHz alBufferData(buffer, AL_FORMAT_MONO16, data, dataSize, 44100) gc.collect() alSourcei(source, AL_BUFFER, buffer.value) ''' state initializations for the upcoming loop ''' random.seed() dt = 1. / 60. vel = 0.8 * dt ''' BEGIN! ''' alSourcePlay(source) ''' loop forever... walking to random, adjacent, integer coordinates ''' while (True): ''' Initial position of the x,y,z coordinates of the sound relating to the current positions 'curr' and the target 'targ' one ''' gps.traite() print(gps.time, gps.latitude, gps.longitude, gps.satellite) lat_orig = gps.latitude long_orig = gps.longitude target_polar[1] = lat_orig - lat_FGC #Diferencia Latitud target_polar[1] = long_orig - long_FGC #Diferencia Longitud if target_polar[1] > 360.0: target_polar[1] = target_polar[1] - 360.0 if target_polar[1] < 0.0: target_polar[1] = target_polar[1] + 360.0 target_polar[1] = target_polar[1] * math.pi / 180.0 targ = rect(target_polar) alSource3f(source[0], AL_POSITION, targ[0], targ[1], targ[2]) alSource3f(source[0], AL_VELOCITY, 0.0, 0.0, 0.0) #print(curr, targ) time.sleep((int)(1 * dt)) ''' cleanup that should be done when you have a proper exit... ;) ''' alDeleteSources(1, ctypes.pointer(source)) alDeleteBuffers(1, ctypes.pointer(buffer)) alcDestroyContext(context) alcCloseDevice(device) return
def getGPS(): gps=GpsNeo6(port="/dev/ttyAMA0",debit=9600,diff=2) #diff is difference between utc time en local time gps.traite() return gps.latitude, gps.longitude, gps.speed
from neo6 import GpsNeo6 gps = GpsNeo6(port="/dev/ttyAMA0", debit=9600, diff=2) while True: gps.traite() print(gps) # print all info latstr = str(gps.latitude) lonstr = str(gps.longitude) print(gps.latitude, gps.longitude) print(latstr, lonstr)