Example #1
0
def readGyroAngles():
    # Read the gyroscope    
    imu=IMU()    # Default IC2 port 1
    imu.gyro_range("245DPS")    
    imu.read_gyro()
    angles = qM.getEuler()
    return Angles
Example #2
0
from SF_9DOF import IMU
import time
import numpy as np

# Create IMU object
imu = IMU() # To select a specific I2C port, use IMU(n). Default is 1. 

# 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):
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 #4
0
WAITSECS = 0.02
NUMDATAPOINTS = 100
DIRECTORY = "gesture_data"

# Create Directory for file if does not exist
if not os.path.exists(DIRECTORY):
    os.makedirs(DIRECTORY)

# Print Program Header
print("\
=======================================\n\
STARTING GESTURE RECORDING TOOL\n\
=======================================")

# Create IMU object
imu = IMU()  # To select a specific I2C port, use IMU(n). Default is 1.

# 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"
Example #5
0
def initialize():
    imu = IMU()
    imu.initialize()
    imu.enable_gyro()
    imu.gyro_range("2000DPS")
    return imu
Example #6
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 #7
0
from SF_9DOF import IMU 
import requests
import json 
#create IMU object 
imu = IMU()

#Initialize IMU
imu.initialize()

imu.enable_accel()

imu.read_accel()
accel_data = imu.ax
print str(accel_data)
print "accel data"
payload  = {'firstName':'Kehlin',
                'lastName':'Sizzaaane',
                'accelData':str(accel_data)}

r=requests.post('https://contact-list-kehlin.herokuapp.com/contacts',json=payload)

Example #8
0
import socket
import uuid
import dbus
import dbus.service
import dbus.mainloop.glib
try:
    from gi.repository import GObject
except ImportError:
    import gobject as GObject

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()
Example #9
0
from SF_9DOF import IMU
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
#This class will handles any incoming request from
#the browser
import mraa
import sys
import time
#i2c = mraa.I2c(1)
#i2c.address(0x15)
imu = IMU()
imu.initialize()
imu.enable_accel()
imu.accel_range("2G")
PORT_NUMBER = 8000


class myHandler(BaseHTTPRequestHandler):

    #Handler for the GET requests
    def do_GET(self):

        if self.path == '/val':
            self.do_val()
        else:
            self.do_index()
        return

    def do_index(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
Example #10
0
END_THROW_THRESHOLD = 20
FREQ_THRESHOLD = 0.5

gyroThrowReadings = []
curGyroReadingIndex = 0

oldIsThrowing = False
isThrowing = False
isThrowingCounter = 0

curTimeStamp = time.time()

allThrows = []

# Gyro stuff
imu = IMU()

# Network stuff


class Throw:
    def __init__(self, gyroReadings, timestamp):
        self.gyroReadings = list(gyroReadings)  # Gyro readings are in Hz
        self.timestamp = timestamp
        self.dt = SYS_TICK_TIME


def initGyro():
    imu.initialize()
    imu.enable_gyro()
    imu.gyro_range('245DPS')
Example #11
0
      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
Example #12
0
import dbus
import dbus.service
import dbus.mainloop.glib
try:
  from gi.repository import GObject
except ImportError:
  import gobject as GObject


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
Example #13
0
import time
import requests
import sys
import select
from SF_9DOF import IMU
#create IMU object
imu = IMU()

#Initialize IMU
imu.initialize()

imu.enable_accel()

imu.read_accel()

imu.accel_range("16G")
accel_x = []
accel_y = []
accel_z = []

#t_end = time.time() + 1
#while(imu.ax.size < 700):
accel_x.append(imu.ax)
accel_y.append(imu.ay)
accel_z.append(imu.az)


def start_checker():
    if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
        c = sys.stdin.read(1)
        return c
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
Example #15
0
from servolib import PWMDriver
from servoDriverConfig import ServoDriver
import welby_balance as wB
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}