def imu(self): imu = IMU() # To select a specific I2C port, use IMU(n). Default is 1. imu.initialize() # Enable accelerometer, magnetometer, gyroscope imu.enable_accel() imu.enable_mag() imu.enable_gyro() print imu.read_accel() print imu.ax, imu.ay, imu.az return imu
def sensor_reader (): jaylen_data = IMU() jaylen_data.initialize() #enable sensors here jaylen_data.enable_accel() jaylen_data.enable_gyro() #declaring the range of the accelerometer jaylen_data.accel_range("8G") jaylen_data.read_accel() jaylen_data.read_gyro() ax = jaylen_data.ax ay = jaylen_data.ay az = jaylen_data.az gx = jaylen_data.gx gy = jaylen_data.gy gz = jaylen_data.gz return ax, ay, az
return False # this is for non-blocking input old_settings = termios.tcgetattr(sys.stdin) try: tty.setcbreak(sys.stdin.fileno()) imu.read_mag() mag = (imu.mx, imu.my, imu.mz) calibrate(mag) print fuse.magbias while (1): imu.read_accel() imu.read_mag() imu.read_gyro() imu.readTemp() #gather the accel results for the fusion algorithm accel = (float(imu.ax), float(imu.ay), float(imu.az)) gyro = (float(imu.gx), float(imu.gy), float(imu.gz)) mag = (float(imu.mx), float(imu.my), float(imu.mz)) # Print the results print "Accel: " + str(imu.ax) + ", " + str(imu.ay) + ", " + str(imu.az) print "Mag: " + str(imu.mx) + ", " + str(imu.my) + ", " + str(imu.mz) print "Gyro: " + str(imu.gx) + ", " + str(imu.gy) + ", " + str(imu.gz) print "Temperature: " + str(imu.temp) outFile_accel.write(
imu.enable_mag() imu.enable_gyro() imu.enable_temp() # Set range on accel, mag, and gyro # Specify Options: "2G", "4G", "6G", "8G", "16G" imu.accel_range("2G") # leave blank for default of "2G" # Specify Options: "2GAUSS", "4GAUSS", "8GAUSS", "12GAUSS" imu.mag_range("2GAUSS") # leave blank for default of "2GAUSS" # Specify Options: "245DPS", "500DPS", "2000DPS" imu.gyro_range("245DPS") # leave blank for default of "245DPS" # Loop and read accel, mag, and gyro while(1): imu.read_accel() imu.read_mag() imu.read_gyro() imu.readTemp() # Print the results print "Accel: " + str(imu.ax) + ", " + str(imu.ay) + ", " + str(imu.az) print "Mag: " + str(imu.mx) + ", " + str(imu.my) + ", " + str(imu.mz) print "Gyro: " + str(imu.gx) + ", " + str(imu.gy) + ", " + str(imu.gz) print "Temperature: " + str(imu.temp) # Sleep for 1/10th of a second time.sleep(0.1)