def initialize(): """Creates and initializes the IMU object Returns an IMU object """ # Create IMU object 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() # Change IMU buffer mode to Bypass # TODO: Try other modes as well imu.accel_mode(0b001) imu.gyro_mode(0b001) # Specify ranges for accelerometer, magnetometer and gyroscope # Accelerometer Options: "2G", "4G", "6G", "8G", "16G" # Magnetometer Options: "2GAUSS", "4GAUSS", "8GAUSS", "12GAUSS" # Gyroscope Options: "245DPS", "500DPS", "2000DPS" imu.accel_range("16G") imu.mag_range("2GAUSS") imu.gyro_range("2000DPS") return imu
def readGyroAngles(): # Read the gyroscope imu=IMU() # Default IC2 port 1 imu.gyro_range("245DPS") imu.read_gyro() angles = qM.getEuler() return Angles
# Enable accel, mag, gyro, and temperature imu.enable_accel() 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 class Offset_Gyro: def __init__(self): imu.read_gyro() self.gx = imu.gx self.gy = imu.gy self.gz = imu.gz #gyro_offset = Offset_Gyro() def gyro_offset_calc(): print "Calculating Gyroscope Offsets..." for i in range(2, 102):
# Enable accel, mag, gyro, and temperature imu.enable_accel() 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" def recordData(x): tstamp = strftime("_%Y-%m-%d_%H%M%S", gmtime()) file = DIRECTORY + '/' + str(x) + tstamp + ".txt" fd = open(file, 'w') # Loop and read accel, mag, and gyro for i in range(NUMDATAPOINTS): imu.read_accel() imu.read_gyro() # Print the results fd.write( "Accel-X: %.8f\tY: %.8f\tZ: %.8f\t| Gyro-X: %.8f\tY: %.8f\tZ: %.8f\n\
def initialize(): imu = IMU() imu.initialize() imu.enable_gyro() imu.gyro_range("2000DPS") return imu
from SF_9DOF import IMU import time import json import numpy as np imu = IMU() imu.initialize() imu.enable_accel() imu.enable_mag() imu.enable_gyro() imu.enable_temp() imu.accel_range("2G") imu.mag_range("2GAUSS") imu.gyro_range("245DPS") class Offset_Gyro: def __init__(self): imu.read_gyro() self.gx = imu.gx self.gy = imu.gy self.gz = imu.gz gyro_offset = Offset_Gyro() def gyro_offset_calc(): print("Calculating Gyroscope Offset...")
import time import json import numpy as np import math imu = IMU() imu.initialize() imu.enable_accel() imu.enable_mag() imu.enable_gyro() imu.enable_temp() imu.accel_range("2G") imu.mag_range("2GAUSS") imu.gyro_range("245DPS") class Accel_Readings: def __init__(self): imu.read_accel() self.ax = imu.ax self.ay = imu.ay self.az = imu.az self.R = math.sqrt(math.pow(self.ax, 2) + math.pow(self.ay, 2) + math.pow(self.az, 2)) class Accel_Readings_Norm: def __init__(self, accel): self.axn = accel.ax/accel.R self.ayn = accel.ay/accel.R self.azn = accel.az/accel.R
from SF_9DOF import IMU from config import GYRO from config import XM import numpy as np import quatMath as qM import time import pandas as pd G = GYRO() G.CTRL_REG1_G = 240 G.CTRL_REG2_G = 40 imu = IMU() imu.initialize() imu.enable_gyro() imu.gyro_range("2000DPS") iterations = 10 period = 5 exes = [0] * period * iterations wyes = [0] * period * iterations zees = [0] * period * iterations its = { 'avg exes': [0] * iterations, 'avg wyes': [0] * iterations, 'avg zees': [0] * iterations, } angles = {'exes': exes, 'wyes': wyes, 'zees': zees} df = pd.DataFrame(angles) averages = pd.DataFrame(its)