Ejemplo n.º 1
0
 def __init__(self, mpuadd, qmcadd, bmeadd, pwmadd, pwmfrequency):
     self.mpuaddress = mpuadd
     self.qmcaddress = qmcadd
     self.bmeaddress = bmeadd
     self.pwmaddress = pwmadd
     self.qmcpollingrate = py_qmc5883l.ODR_50HZ
     self.i2cport = 1
     #connect to IC's
     #adafruit pca9685
     self.pwm = Adafruit_PCA9685.PCA9685(address=self.pwmaddress)
     self.pwm.set_pwm_freq(pwmfrequency)
     self.pwm.set_pwm(0, 0, 360)
     self.pwm.set_pwm(1, 0, 360)
     self.pwm.set_pwm(2, 0, 360)
     self.pwm.set_pwm(3, 0, 360)
     self.mpuaccelrange = mpu6050.ACCEL_RANGE_4G
     #bme280
     self.bus = smbus2.SMBus(self.i2cport)
     self.bmecalibration_params = bme280.load_calibration_params(self.bus, self.bmeaddress)
     #mpu6050
     self.mpu6050 = mpu6050(self.mpuaddress)
     #QMC5883L-TL
     self.qmc5833lcalibrationdata = [[1.0303, 0.0255, -227.7989],
                                     [0.0255, 1.0214, 1016.4415],
                                     [0.0, 0.0, 1.0]]
     self.qmc5883L = py_qmc5883l.QMC5883L(output_range=py_qmc5883l.RNG_2G, output_data_rate=self.qmcpollingrate)
     #init kalman filtered mpu
     self.kalmanfilter = AngleMeterAlpha.AngleMeterAlpha()
     self.kalmanfilter.MPU_Init()
     self.kalmanfilter.measure()
Ejemplo n.º 2
0
    def _enable_sensors(self):

        try:
            logging.info("Opening Compass")
            self.compass = py_qmc5883l.QMC5883L()
            self._calibrate_forwards()
        except Exception as e:
            raise Exception("Error opening compass, no steering: " + str(e))
        try:
            self.bus = smbus.SMBus(1)  # Rev 2 Pi uses 1
            lightreading = self._read_lightsensor()
            logging.info(f"Lightsensor reads {lightreading}")
        except Exception as e:
            raise Exception("Error opening light sensor, no pedals: " + str(e))
Ejemplo n.º 3
0
#sac baseball field homeplate
#long1 =-122.314747
#lat1 = 47.335092

#home
#long1 = -122.326768
#lat1 = 47.342301

tolerancelat = .0001
tolerancelong = .00003
#houselat = 47.342257833
#houselong = -122.326749667
gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)

sensor = py_qmc5883l.QMC5883L()
sensor.calibration = [[1.00579223e+00, -9.69727879e-03, -8.50240184e+02],
                      [-9.69727879e-03, 1.01623506e+00, -1.77743179e+03],
                      [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]
sensor.declination = 15.5

used = False

f = open("data/test-compass" + dt.isoformat() + ".dat", "w+")
g = open("data/test-coordinates" + dt.isoformat() + ".dat", "w+")


def calculate_correct_bearing(currentbearing):
    newbearing = currentbearing + 50
    if (type(currentbearing) != float):
        raise TypeError("Only floats are supported as arguments")
Ejemplo n.º 4
0
import time
import py_qmc5883l

sensor = py_qmc5883l.QMC5883L(output_data_rate=py_qmc5883l.ODR_100HZ,
                              output_range=py_qmc5883l.RNG_8G)


def getMagnetStrength():
    return sensor.get_magnet_raw()[1]


def main():
    rot = 0
    mode = 0
    TRESHOLD = 100
    while True:
        mag = getMagnetStrength()
        print(mag, rot)
        if (mode == 0):
            if (mag > TRESHOLD):
                rot += 1
                mode = 1
        else:
            if (mag < TRESHOLD):
                mode = 0


#main()
Ejemplo n.º 5
0
import py_qmc5883l
import time
import math
import smbus
sensor = py_qmc5883l.QMC5883L(output_range=py_qmc5883l.RNG_8G)
flag = False
flag2 = True
start = 0
end = 0
during = 0
i = 0
i_store = 100
small_car = 50
big_car = 80
x = [0]
y = [0]
z = [0]
while (1):
    x_temp, y_temp, z_temp = sensor.get_magnet_raw()
    x.append(x_temp)
    y.append(y_temp)
    z.append(z_temp)
    print(x[i], y[i], z[i])
    if (flag is False and i > 10):
        if (x[i] - x[i - 9] > 120
                or y[i - 9] - y[i] > 600 and z[i - 9] - z[i] > 100):
            start = time.time()
            i_store = i
            print("\033[1;35m start counting \033[0m")
            start = (round(start, 3))
            flag = True
Ejemplo n.º 6
0
 def __init__(self):
     self.sensor = py_qmc5883l.QMC5883L()
     self.sensor.set_declination(-8.87)
     self.sensor.calibration = [[1.2115, 0.11794, 1104.34691],
                                [0.11794, 1.06576, -625.31453], [0, 0, 1.0]]
Ejemplo n.º 7
0
 def __init__(self):
     self.sensor = py_qmc5883l.QMC5883L()
Ejemplo n.º 8
0
def main():
    ''' Defining a variable to name all the functions of the magnetometer '''
    sensor = py_qmc5883l.QMC5883L()
    ''' 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 = (ctypes.c_uint * 4)(0, 0)
    alGenSources(4, cast(source, POINTER(ctypes.c_uint)))

    alSourcef(source[0], AL_PITCH, 1.)
    alSourcef(source[0], AL_GAIN, 1.)
    alSource3f(source[0], AL_POSITION, curr[0], curr[1], curr[2])
    alSource3f(source[0], AL_VELOCITY, 0., 0., 0.)
    alSourcei(source[0], AL_LOOPING, AL_TRUE)

    alSourcef(source[1], AL_PITCH, 1.)
    alSourcef(source[1], AL_GAIN, 1.)
    alSource3f(source[1], AL_POSITION, curr[0], curr[1], curr[2])
    alSource3f(source[1], AL_VELOCITY, 0., 0., 0.)
    alSourcei(source[1], AL_LOOPING, AL_TRUE)

    alSourcef(source[2], AL_PITCH, 1.)
    alSourcef(source[2], AL_GAIN, 1.)
    alSource3f(source[2], AL_POSITION, curr[0], curr[1], curr[2])
    alSource3f(source[2], AL_VELOCITY, 0., 0., 0.)
    alSourcei(source[2], AL_LOOPING, AL_TRUE)

    alSourcef(source[3], AL_PITCH, 1.)
    alSourcef(source[3], AL_GAIN, 1.)
    alSource3f(source[3], AL_POSITION, curr[0], curr[1], curr[2])
    alSource3f(source[3], AL_VELOCITY, 0., 0., 0.)
    alSourcei(source[3], AL_LOOPING, AL_TRUE)
    ''' allocate an OpenAL buffer and fill it with monaural sample data '''
    buffer = (ctypes.c_uint * 4)(0, 0)
    alGenBuffers(4, cast(buffer, POINTER(ctypes.c_uint)))

    data = load('nord.raw')
    data2 = load('sud.raw')
    data3 = load('est.raw')
    data4 = load('oest.raw')

    dataSize = ctypes.c_int(len(data))
    dataSize2 = ctypes.c_int(len(data2))
    dataSize3 = ctypes.c_int(len(data3))
    dataSize4 = ctypes.c_int(len(data4))

    # for simplicity, assume raw file is signed-16b at 44.1kHz
    alBufferData(buffer[0], AL_FORMAT_MONO16, data, dataSize, 44100)
    gc.collect()

    alBufferData(buffer[1], AL_FORMAT_MONO16, data2, dataSize2, 44100)
    gc.collect()

    alBufferData(buffer[2], AL_FORMAT_MONO16, data3, dataSize3, 44100)
    gc.collect()

    alBufferData(buffer[3], AL_FORMAT_MONO16, data4, dataSize4, 44100)
    gc.collect()

    alSourcei(source[0], AL_BUFFER, buffer[0])
    alSourcei(source[1], AL_BUFFER, buffer[1])
    alSourcei(source[2], AL_BUFFER, buffer[2])
    alSourcei(source[3], AL_BUFFER, buffer[3])
    ''' state initializations for the upcoming loop '''
    random.seed()
    dt = 1. / 60.
    vel = 0.8 * dt
    ''' BEGIN! '''
    alSourcePlay(source[0])
    time.sleep(2)
    alSourcePlay(source[1])
    time.sleep(2)
    alSourcePlay(source[2])
    time.sleep(2)
    alSourcePlay(source[3])
    time.sleep(2)
    ''' 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 '''

        rho = round(sensor.get_bearing2(), 4)

        print(rho)

        target_polar[1] = 180 + rho  #Coordenada NORD
        target_polar[1] = 90 + rho  #Coordenada EST
        target_polar[1] = rho  #Coordenada SUD
        target_polar[1] = -90 + rho  #Coordenada OEST

        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
        #    print(target_polar[1])

        targ = rect(target_polar)

        #    print(targ)

        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))

        alSource3f(source[1], AL_POSITION, targ[0], targ[1], targ[2])
        alSource3f(source[1], 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
Ejemplo n.º 9
0
def readCompass():
    """Returns compass bearing."""
    sensor = py_qmc5883l.QMC5883L()
    return sensor.get_bearing() - 90
Ejemplo n.º 10
0
import math
import Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1115()
GAIN = 1  #This sets the voltage range to 4.096V per 2**15
#from mpu6050 import mpu6050
#sensor = mpu6050(0x68)
HOST = ''
PORT = 52849
BUFSIZE = 1024
ADDR = (HOST, PORT)
tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
print('Waiting for connection')
print('...connected from:', ADDR)
sensor = qmc.QMC5883L()
sensor.calibration = [[1.03194204e+00, -5.83440263e-02, -6.59472052e+03],
                      [-5.83440263e-02, 1.10656882e+00, 4.03742821e+02],
                      [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]

while True:

    tcpDataSock, addr = tcpSerSock.accept()
    #print("accepted")
    try:
        m = sensor.get_bearing()

    except:
        m = "none"
    try:
        #print(m)
 def __init__(self):
     sensor = py_qmc5883l.QMC5883L(output_range = py_qmc5883l.RNG_8G)
     sensor.declination = declination_value
Ejemplo n.º 12
0
def GY85():
    sensor = py_qmc5883l.QMC5883L()
    sensor.calibration = [[1.030, 0.026, -227.799], [0.0255, 1.021, 1016.442],
                          [0.0, 0.0, 1.0]]
    sensor.get_bearing()
    return sensor.get_bearing_raw()
Ejemplo n.º 13
0
gps.cfg_rate(200)  # установка частоты опроса

ser.flush()  # очистка буфера

# начало времени GPST (Jan 6 1980 00:00:00.00)
gps_epoch = datetime.datetime(1980, 1, 6).timestamp()

# считывание параметров с файла param
with open('/home/pi/Documents/scripts/param', 'r') as prs:
    freq = int(prs.readline())  # частота работы магнитометра
    decl = float(prs.readline())  # склонение магн.поля в районе работ (dd.mm)
    prs.close()

# COMPASS
# инициализация компаса
mag = py_qmc5883l.QMC5883L(i2c_bus=1, address=0x0d)
mag.set_declination(decl)

# при записи показаний магнитометра время считывается с RP.
# Поэтому исполнение скрипта продолжится после нахождения GPS достаточного
# количества спутников. При нажатии кнопки до нахождения спутников,
# программа закончит свою работу, и компьютер выключится.
while True:
    if GPIO.event_detected(button):
        time.sleep(1)
        os.system('sudo shutdown now')
    try:
        s = ser.readline()
        if b'$GPRMC' in s:
            data = parse_GPS_message(s)
            if (len(data[1]) > 6) and (len(data[9]) > 5) and \