def getGyro(): gyro = mpu9250.read_gyro_data() # returns 3 axes gyro data (deg/s) gyro = np.round(gyro, 2) return(gyro)
if rcpy.get_state() == rcpy.RUNNING: temp = mpu9250.read_imu_temp() data = mpu9250.read_accel_data() save.append(data[1]) avg = avg + data[1] i = i + 1 avg = avg / 100 print('doing') time.sleep(0.01) print('done') for i in range(0, len(save)): sigma = sigma + ((save[i] - avg)**2) stdv = math.sqrt(sigma / 100) cov = stdv**2 cov = [[cov, 0, 0], [0, cov, 0], [0, 0, cov]] print('done1') if rcpy.get_state() == rcpy.RUNNING: print('hi') temp = mpu9250.read_imu_temp() data = mpu9250.read_accel_data() data_gyro = mpu9250.read_gyro_data() g = Kalman(data, data_gyro, cov) print(g) time.sleep(1) # sleep some except KeyboardInterrupt: # Catch Ctrl-C pass finally: print("\nBye BeagleBone!")
def test1(): N = 1 try: # no magnetometer mpu9250.initialize(enable_magnetometer = False) conf = mpu9250.get() assert conf == {'orientation': 136, 'accel_dlpf': 2, 'gyro_dlpf': 2, 'compass_time_constant': 5.0, 'enable_fusion': False, 'enable_dmp': False, 'enable_magnetometer': False, 'accel_fsr': 1, 'dmp_sample_rate': 100, 'show_warnings': False, 'gyro_fsr': 2, 'dmp_interrupt_priority': 98} print('\n Accel XYZ(m/s^2) | Gyro XYZ (rad/s) | Temp (C)') for i in range(N): (ax,ay,az) = mpu9250.read_accel_data() (gx,gy,gz) = mpu9250.read_gyro_data() temp = mpu9250.read_imu_temp() print(('\r{:6.2f} {:6.2f} {:6.2f} |' + '{:6.1f} {:6.1f} {:6.1f} | {:6.1f}') .format(ax, ay, az, gx, gy, gz, temp), end='') time.sleep(1) with pytest.raises(mpu9250.error): mpu9250.read_mag_data() # consolidated read function for i in range(N): data = mpu9250.read() print(('\r{0[0]:6.2f} {0[1]:6.2f} {0[2]:6.2f} |' '{1[0]:6.1f} {1[1]:6.1f} {1[2]:6.1f} |') .format(data['accel'], data['gyro']), end='') time.sleep(1) # with magnetometer mpu9250.initialize(enable_magnetometer = True) conf = mpu9250.get() assert conf == {'orientation': 136, 'accel_dlpf': 2, 'gyro_dlpf': 2, 'compass_time_constant': 5.0, 'enable_fusion': False, 'enable_dmp': False, 'enable_magnetometer': True, 'accel_fsr': 1, 'dmp_sample_rate': 100, 'show_warnings': False, 'gyro_fsr': 2, 'dmp_interrupt_priority': 98} print('\n Accel XYZ(m/s^2) | Gyro XYZ (rad/s) | Mag Field XYZ(uT) | Temp (C)') for i in range(N): (ax,ay,az) = mpu9250.read_accel_data() (gx,gy,gz) = mpu9250.read_gyro_data() (mx,my,mz) = mpu9250.read_mag_data() temp = mpu9250.read_imu_temp() print(('\r{:6.2f} {:6.2f} {:6.2f} |' + '{:6.1f} {:6.1f} {:6.1f} |' '{:6.1f} {:6.1f} {:6.1f} | {:6.1f}') .format(ax, ay, az, gx, gy, gz, mx, my, mz, temp), end='') time.sleep(1) # consolidated read function for i in range(N): data = mpu9250.read() print(('\r{0[0]:6.2f} {0[1]:6.2f} {0[2]:6.2f} |' '{1[0]:6.1f} {1[1]:6.1f} {1[2]:6.1f} |' '{2[0]:6.1f} {2[1]:6.1f} {2[2]:6.1f} |') .format(data['accel'], data['gyro'], data['mag']), end='') time.sleep(1) except (KeyboardInterrupt, SystemExit): pass finally: mpu9250.power_off()