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
Example #2
0
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
Example #3
0
# Initialize IMU
imu.initialize()

# 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()
Example #4
0
# Initialize IMU
imu.initialize()

# 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()
Example #5
0
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():
Example #6
0
from SF_9DOF import IMU
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