Пример #1
0
 def getValue(self):
     """
     Return a 9-elements list containing all IMU reading
     """
     lib.lsm9ds1_readAccel(self.__conn)
     lib.lsm9ds1_readGyro(self.__conn)
     lib.lsm9ds1_readMag(self.__conn)
     ax = lib.lsm9ds1_getAccelX(self.__conn)
     ay = lib.lsm9ds1_getAccelY(self.__conn)
     az = lib.lsm9ds1_getAccelZ(self.__conn)
     cax = lib.lsm9ds1_calcAccel(self.__conn, ax)
     cay = lib.lsm9ds1_calcAccel(self.__conn, ay)
     caz = lib.lsm9ds1_calcAccel(self.__conn, az)
     gx = lib.lsm9ds1_getGyroX(self.__conn)
     gy = lib.lsm9ds1_getGyroY(self.__conn)
     gz = lib.lsm9ds1_getGyroZ(self.__conn)
     cgx = lib.lsm9ds1_calcGyro(self.__conn, gx)
     cgy = lib.lsm9ds1_calcGyro(self.__conn, gy)
     cgz = lib.lsm9ds1_calcGyro(self.__conn, gz)
     mx = lib.lsm9ds1_getMagX(self.__conn)
     my = lib.lsm9ds1_getMagY(self.__conn)
     mz = lib.lsm9ds1_getMagZ(self.__conn)
     cmx = lib.lsm9ds1_calcMag(self.__conn, mx)
     cmy = lib.lsm9ds1_calcMag(self.__conn, my)
     cmz = lib.lsm9ds1_calcMag(self.__conn, mz)
     return [cax, cay, caz, cgx, cgy, cgz, cmx, cmy, cmz]
Пример #2
0
def getData():
    #connect with IMU
    imu = lib.lsm9ds1_create()
    lib.lsm9ds1_begin(imu)
    if lib.lsm9ds1_begin(imu) == 0:
        print("Failed to communicate with LSM9DS1.")
        quit()
    lib.lsm9ds1_calibrate(imu)
    while True:
        #get IMU accel data
        global lasttime

        #new structure testing
        if lib.lsm9ds1_accelAvailable(imu) > 0 and ser.in_waiting > 8:
            lib.lsm9ds1_readAccel(imu)
            ax = lib.lsm9ds1_getAccelX(imu)
            ay = lib.lsm9ds1_getAccelY(imu)
            cax = lib.lsm9ds1_calcAccel(imu, ax)
            cay = lib.lsm9ds1_calcAccel(imu, ay)
            #TFmini data
            recv = ser.read(9)
            ser.reset_input_buffer()

            if recv[0] == 0x59 and recv[1] == 0x59:
                distance = recv[2] + recv[3] * 256
                ser.reset_input_buffer()
                currentTime = str(datetime.datetime.now())
                #timestamp data
                row = [
                    currentTime, distance, cax, cay
                ]  #the row being written to csv file, just x and y accel
                diff = time.time() - lasttime
                print(diff)
                lasttime = time.time()
                print(row)
def getData():
    global lasttime
    #connect with IMU
    imu = lib.lsm9ds1_create()
    lib.lsm9ds1_begin(imu)
    if lib.lsm9ds1_begin(imu) == 0:
        print("Failed to communicate with LSM9DS1.")
        quit()
    lib.lsm9ds1_calibrate(imu)

    current = time.time()
    while current - startTime < 10:
        
        current = time.time()
        if lib.lsm9ds1_accelAvailable(imu) > 0 and ser.in_waiting > 8:
            lib.lsm9ds1_readAccel(imu)
            ax = lib.lsm9ds1_getAccelX(imu)
            ay = lib.lsm9ds1_getAccelY(imu)
            az = lib.lsm9ds1_getAccelZ(imu)
            cax = lib.lsm9ds1_calcAccel(imu, ax)
            cay = lib.lsm9ds1_calcAccel(imu, ay)
            caz = lib.lsm9ds1_calcAccel(imu, az)
            gx = lib.lsm9ds1_getGyroX(imu)
            gy = lib.lsm9ds1_getGyroY(imu)
            gz = lib.lsm9ds1_getGyroZ(imu)
            cgx = lib.lsm9ds1_calcGyro(imu, gx)
            cgy = lib.lsm9ds1_calcGyro(imu, gy)
            cgz = lib.lsm9ds1_calcGyro(imu, gz)
            #TFmini data
            recv = ser.read(9)
            ser.reset_input_buffer()

            if recv[0] == 0x59 and recv[1] == 0x59:
                distance = recv[2] + recv[3] * 256
                ser.reset_input_buffer()
                currentTime = str(datetime.datetime.now()); #timestamp data
                row = [currentTime,distance,cax,cay,caz,cgx,cgy,cgz] #the row being written to csv file, just x and y accel
                rowList.append(row)
                diff = time.time() - lasttime
                timeDiffer.append(diff)
                #print(diff)
                lasttime = time.time()
                #print(row)

    print("start writing data")
    with open(datafile,"a",newline = '') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
        for i in range(len(rowList)):
            row = [rowList[i]]
            spamwriter.writerow(row)
            
    print("start writing frequency")
    with open(filename,"a",newline = '') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
        for i in range(len(timeDiffer)):
            row = [timeDiffer[i]]
            spamwriter.writerow(row)
Пример #4
0
def getIMU():
    global imu
    lib.lsm9ds1_readAccel(imu)
    ax = lib.lsm9ds1_getAccelX(imu)
    ay = lib.lsm9ds1_getAccelY(imu)
    az = lib.lsm9ds1_getAccelZ(imu)
    cax = lib.lsm9ds1_calcAccel(imu, ax)
    cay = lib.lsm9ds1_calcAccel(imu, ay)
    caz = lib.lsm9ds1_calcAccel(imu, az)
    gx = lib.lsm9ds1_getGyroX(imu)
    gy = lib.lsm9ds1_getGyroY(imu)
    gz = lib.lsm9ds1_getGyroZ(imu)
    cgx = lib.lsm9ds1_calcGyro(imu, gx)
    cgy = lib.lsm9ds1_calcGyro(imu, gy)
    cgz = lib.lsm9ds1_calcGyro(imu, gz)
    return (cax, cay, caz, cgx, cgy, cgz)
Пример #5
0
def getData():
    global lasttime
    #connect with IMU
    imu = lib.lsm9ds1_create()
    lib.lsm9ds1_begin(imu)
    if lib.lsm9ds1_begin(imu) == 0:
        print("Failed to communicate with LSM9DS1.")
        quit()
    lib.lsm9ds1_calibrate(imu)

    while True:
        #beforeIf = time.time()
        time.sleep(0.2)
        if lib.lsm9ds1_accelAvailable(imu) > 0:
            afterIf = time.time()
            lib.lsm9ds1_readAccel(imu)
            ax = lib.lsm9ds1_getAccelX(imu)
            ay = lib.lsm9ds1_getAccelY(imu)
            az = lib.lsm9ds1_getAccelZ(imu)
            cax = lib.lsm9ds1_calcAccel(imu, ax)
            cay = lib.lsm9ds1_calcAccel(imu, ay)
            caz = lib.lsm9ds1_calcAccel(imu, az)
            gx = lib.lsm9ds1_getGyroX(imu)
            gy = lib.lsm9ds1_getGyroY(imu)
            gz = lib.lsm9ds1_getGyroZ(imu)
            cgx = lib.lsm9ds1_calcGyro(imu, gx)
            cgy = lib.lsm9ds1_calcGyro(imu, gy)
            cgz = lib.lsm9ds1_calcGyro(imu, gz)

            ##            #add to list
            ##            caxl.append(cax)
            ##            cayl.append(cay)
            ##            cazl.append(caz)
            ##            cgxl.append(cgx)
            ##            cgyl.append(cgy)
            ##            cgzl.append(cgz)
            print(cax, cay, caz, cgx, cgy, cgz)
Пример #6
0
def getIMU():
    global imu
    lib.lsm9ds1_readAccel(imu)
    lib.lsm9ds1_readGyro(imu)
    lib.lsm9ds1_readMag(imu)
    ax = lib.lsm9ds1_getAccelX(imu)
    ay = lib.lsm9ds1_getAccelY(imu)
    az = lib.lsm9ds1_getAccelZ(imu)
    cax = lib.lsm9ds1_calcAccel(imu, ax)
    cay = lib.lsm9ds1_calcAccel(imu, ay)
    caz = lib.lsm9ds1_calcAccel(imu, az)
    gx = lib.lsm9ds1_getGyroX(imu)
    gy = lib.lsm9ds1_getGyroY(imu)
    gz = lib.lsm9ds1_getGyroZ(imu)
    cgx = lib.lsm9ds1_calcGyro(imu, gx)
    cgy = lib.lsm9ds1_calcGyro(imu, gy)
    cgz = lib.lsm9ds1_calcGyro(imu, gz)
    mx = lib.lsm9ds1_getMagX(imu)
    my = lib.lsm9ds1_getMagY(imu)
    mz = lib.lsm9ds1_getMagZ(imu)
    cmx = lib.lsm9ds1_calcMag(imu, mx)
    cmy = lib.lsm9ds1_calcMag(imu, my)
    cmz = lib.lsm9ds1_calcMag(imu, mz)
    return (cax, cay, caz, cgx, cgy, cgz, cmx, cmy, cmz)