예제 #1
0
def init_accelerometer(i2c, range=2):
    # default is 2G, but you can use 4G or 8G values):

    if range == 2:
        sensor = adafruit_fxos8700.FXOS8700(i2c)

    elif range == 4:
        gyroscope = adafruit_fxos8700.FXOS8700(
            i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)

    elif range == 8:
        gyroscope = adafruit_fxos8700.FXOS8700(
            i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)

    return sensor
예제 #2
0
 def __init__(self, delay):
     # Initialize I2C bus and device.
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.sensor = adafruit_fxos8700.FXOS8700(self.i2c)
 	
     self.delay = delay
     threading.Thread.__init__(self)
예제 #3
0
 def __SetupSensors(self):
     i2c = busio.I2C(board.SCL, board.SDA)
     fxos = fxoslib.FXOS8700(
         i2c,
         accel_range=fxoslib.ACCEL_RANGE_2G)  # accelerometer, magnetometer
     fxas = fxaslib.FXAS21002C(i2c)  # gyro
     return fxos, fxas
예제 #4
0
    def __init__(self, config, queue, level):
        self._log = Logger("nxp9dof", level)
        if config is None:
            raise ValueError("no configuration provided.")
        self._config = config
        self._queue = queue

        _config = self._config['ros'].get('nxp9dof')
        self._quaternion_accept = _config.get(
            'quaternion_accept')  # permit Quaternion once calibrated
        self._loop_delay_sec = _config.get('loop_delay_sec')

        # verbose will print some start-up info on the IMU sensors
        self._imu = IMU(gs=4, dps=2000, verbose=True)
        # setting a bias correction for the accel only; the mags/gyros are not getting a bias correction
        self._imu.setBias((0.0, 0.0, 0.0), None, None)
        #       self._imu.setBias((0.1,-0.02,.25), None, None)

        _i2c = busio.I2C(board.SCL, board.SDA)
        self._fxos = adafruit_fxos8700.FXOS8700(_i2c)
        self._log.info('accelerometer and magnetometer ready.')
        self._fxas = adafruit_fxas21002c.FXAS21002C(_i2c)
        self._log.info('gyroscope ready.')

        self._thread = None
        self._enabled = False
        self._closed = False
        self._heading = None
        self._pitch = None
        self._roll = None
        self._is_calibrated = False
        self._log.info('ready.')
예제 #5
0
    def run(self):
        i2c = busio.I2C(board.SCL, board.SDA)
        sensor = adafruit_fxos8700.FXOS8700(i2c)

        i2c2 = busio.I2C(board.SCL, board.SDA)
        sensor2 = adafruit_fxas21002c.FXAS21002C(i2c2)

        while True:
            if(Settings.tag_index == 0):
                accel_x, accel_y, accel_z = sensor.accelerometer
                Settings.ACC_X_text= "{0:.2f}".format(accel_x)
                Settings.ACC_Y_text= "{0:.2f}".format(accel_y)
                Settings.ACC_Z_text= "{0:.2f}".format(accel_z)

            elif(Settings.tag_index == 1):
                gyro_x, gyro_y, gyro_z = sensor2.gyroscope
                Settings.GYRO_X_text= "{0:.2f}".format(gyro_x)
                Settings.GYRO_Y_text= "{0:.2f}".format(gyro_y)
                Settings.GYRO_Z_text= "{0:.2f}".format(gyro_z)
            else:
                mag_x, mag_y, mag_z = sensor.magnetometer
                Settings.MAG_X_text= "{0:.2f}".format(mag_x)
                Settings.MAG_Y_text= "{0:.2f}".format(mag_y)
                Settings.MAG_Z_text= "{0:.2f}".format(mag_z)
            
            self.update.emit()
            sleep(0.1)
예제 #6
0
def init():
    global i2c
    global fxos
    global fxas
    global mpl

    i2c = busio.I2C(board.SCL, board.SDA)
    fxos = adafruit_fxos8700.FXOS8700(i2c)
    fxas = adafruit_fxas21002c.FXAS21002C(i2c)
예제 #7
0
    def __init__(self):
        self.Q = [1., 0., 0., 0.]
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # fxos contains data of the accelerometer and the magnetometer
        self.fxos = adafruit_fxos8700.FXOS8700(self.i2c)
        self.fxas = adafruit_fxas21002c.FXAS21002C(self.i2c)
        self.d2g = ahrs.common.DEG2RAD

        # TODO: make sure the correct frequency is set here
        self.madgwick = ahrs.filters.Madgwick(frequency=10.0)
예제 #8
0
def init():
    global i2c
    global fxos
    global fxas
    global mpl

    i2c = busio.I2C(board.SCL, board.SDA)
    fxos = adafruit_fxos8700.FXOS8700(i2c)
    fxas = adafruit_fxas21002c.FXAS21002C(i2c)
    mpl = adafruit_mpl3115a2.MPL3115A2(i2c)
    mpl.sealevel_pressure = 102250
예제 #9
0
def main():
    i2c = busio.I2C(board.SCL_1, board.SDA_1)
    print("I2C 1 ok!")

    acc_magn_sensor = adafruit_fxos8700.FXOS8700(i2c)
    print("acc magn ok!")

    gyro_sensor = adafruit_fxas21002c.FXAS21002C(i2c)
    print("gyro ok!")
    
    while True:
        imu_data(gyro_sensor, acc_magn_sensor)
        time.sleep(1.0)
예제 #10
0
def Accgyro_Init():
    #initalize I2C for fxos8700 and fxas21002c
    i2c = busio.I2C(board.SCL, board.SDA)

    fxos = adafruit_fxos8700.FXOS8700(i2c)
    fxas = adafruit_fxas21002c.FXAS21002C(i2c)
    print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
        *fxos.accelerometer))
    print('Magnetometer (uTesla): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
        *fxos.magnetometer))
    print('Gyroscope (radians/s): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
        *fxas.gyroscope))
    #     time.sleep(1)
    return (fxos, fxas)
예제 #11
0
def readSensor():
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_fxos8700.FXOS8700(i2c)

    now = dt.datetime.now()
    sec = now.second
    minute = now.minute
    hour = now.hour
    microsec = now.microsecond
    totaltime = ((hour * 3600) + (minute * 60) + (sec)) * 1000 + microsec

    accelx, accely, accelz = sensor.accelerometer
    df = pd.DataFrame.from_dict({
        'Time': [totaltime],
        'X': [accelx],
        'Y': [accely],
        'Z': [accelz]
    })

    db = sqlite3.connect("accelerationDB.db")
    cursor = db.cursor()
    cursor.execute("DROP TABLE IF EXISTS acceleration")

    df.to_sql(name='acceleration', con=db)
예제 #12
0
 def __init__(self):
     i2c = busio.I2C(board.SCL, board.SDA)
     self.fxos = adafruit_fxos8700.FXOS8700(i2c)
     self.fxas = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=GYRO_RANGE)
# Simple demo of the FXOS8700 accelerometer and magnetometer.
# Will print the acceleration and magnetometer values every second.
import time

import board
import busio

import adafruit_fxos8700

# Initialize I2C bus and device.
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_fxos8700.FXOS8700(i2c)
# Optionally create the sensor with a different accelerometer range (the
# default is 2G, but you can use 4G or 8G values):
# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)
# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)

# Main loop will read the acceleration and magnetometer values every second
# and print them out.
while True:
    # Read acceleration & magnetometer.
    accel_x, accel_y, accel_z = sensor.accelerometer
    mag_x, mag_y, mag_z = sensor.magnetometer
    # Print values.
    print("Acceleration (m/s^2): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
        accel_x, accel_y, accel_z))
    print("Magnetometer (uTesla): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
        mag_x, mag_y, mag_z))
    # Delay for a second.
    time.sleep(1.0)
예제 #14
0
# program prints turning direction
import board
import busio
import adafruit_fxos8700
import adafruit_fxas21002c
import time

# assign variables
mag_x = 0

# initialize I2C bus and devices
i2c = busio.I2C(board.SCL, board.SDA)
fxos = adafruit_fxos8700.FXOS8700(i2c)
fxas = adafruit_fxas21002c.FXAS21002C(i2c)
 
# main loop reads values and prints them out
while True:
    # read acceleration, magnetometer and gyroscope
    prev_mag_x = mag_x
    mag_x, mag_y, mag_z = fxos.magnetometer
    difference = mag_x - prev_mag_x
    # print x values
    if mag_x > prev_mag_x:
        print("Left: " + str(difference))
    elif mag_x < prev_mag_x:
        print("Right: " + str(difference))
    else:
        print("None")
    # second time delay
    time.sleep(1)
예제 #15
0
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.accelerometer = adafruit_fxos8700.FXOS8700(
         self.i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)
예제 #16
0
import board
import busio
import adafruit_fxos8700
import adafruit_fxas21002c

i2c = busio.I2C(board.SCL, board.SDA)
sensor1 = adafruit_fxos8700.FXOS8700(i2c)#accel and mag
sensor2 = adafruit_fxas21002c.FXAS21002C(i2c)#gyro

# class sensor1(object):#mock sensor data
#     accelerometer = [1,2,3]
#     magnetometer = [1,2,3]

# class sensor2(object):#mock sensor data
#     gyroscope = [1,2,3]

def AccelArray():
    return sensor1.accelerometer

def AccelX():
    return sensor1.accelerometer[0]

def AccelY():
    return sensor1.accelerometer[1]

def AccelZ():
    return sensor1.accelerometer[2]

def MagArray():
    return sensor1.magnetometer
예제 #17
0
    def __init__(self):
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.sensor_acc_mag = adafruit_fxos8700.FXOS8700(self.i2c)
        self.sensor_gyro = adafruit_fxas21002c.FXAS21002C(self.i2c)

        self.data = {'roll': 0, 'pitch': 0, 'yaw': 0}
예제 #18
0
import adafruit_fxas21002c

# The values for offset aftee this calibration were
#
# Gyroscope offset: (mean, std)
# X: 0.1323125  0.18466651785466298
# Y: 0.2090625  0.14371279766242798
# Z: 0.143375   0.1347482057541174
#
# Magnetometer offset:
# X: 25.93526 7.08914
# Y: -30.51872 12.36429
# Z: -14.57492 10.45313

i2c = busio.I2C(board.SCL, board.SDA)
sensor_acc_mag = adafruit_fxos8700.FXOS8700(i2c)
sensor_gyro = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=2000)

T, dt = 10, 0.01

gyro_x_data = []
gyro_y_data = []
gyro_z_data = []

mag_x_data = []
mag_y_data = []
mag_z_data = []

k = 0
for i in range(int(T/dt)):
  mag_x, mag_y, mag_z = sensor_acc_mag.magnetometer    # (uTesla)
예제 #19
0
# bmp = BMP085(0x77, debug=True)
bmp = BMP085(0x77)

# To specify a different operating mode, uncomment one of the following:
# bmp = BMP085(0x77, 0)  # ULTRALOWPOWER Mode
# bmp = BMP085(0x77, 1)  # STANDARD Mode
# bmp = BMP085(0x77, 2)  # HIRES Mode
# bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode

# Initialize I2C bus and device.
i2c = busio.I2C(board.SCL, board.SDA)
# sensor = adafruit_fxos8700.FXOS8700(i2c)
# Optionally create the sensor with a different accelerometer range (the
# default is 2G, but you can use 4G or 8G values):
# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)
sensor = adafruit_fxos8700.FXOS8700(
    i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)
sensor1 = adafruit_fxas21002c.FXAS21002C(
    i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS)

time_start = datetime.now()

file_name = 'rocket-data-' + str(datetime.now().hour) + '-' + str(
    datetime.now().minute) + '.csv'
with open(file_name, 'w', newline='') as datafile:
    datawriter = csv.writer(datafile, delimiter=';')

    # Main loop will read the acceleration and magnetometer values every second
    # and print them out.
    while True:
        # Read acceleration & magnetometer.
        accel_x, accel_y, accel_z = sensor.accelerometer
예제 #20
0
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

import threading
import time
import math
import board
import busio

import adafruit_fxos8700
import adafruit_fxas21002c

#Temp, Humidity, Pressure Sensor
import adafruit_bme280

i2c_nxp = board.I2C()
mag_accel_sensor = adafruit_fxos8700.FXOS8700(i2c_nxp)
gyro_sensor = adafruit_fxas21002c.FXAS21002C(i2c_nxp)

#I2C address for the temp, humidity and pressure sensor is 0x76
i2c_bme = board.I2C()
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c_bme, 0x76)
###############################################################################
# Parameters and global variables

# Parameters
update_interval = 100  # Time (ms) between polling/animation updates
max_elements = 1440  # Maximum number of elements to store in plot lists

# Declare global variables
root = None
dfont = None
rfm69Celsius = rfm69.temperature
rfm69Fahrenheit = round(rfm69Celsius * 1.8 + 32, 1)

#   Print out some RFM69 chip state:
print("RFM69 Radio Data")
print('    Temperature:         {0}°F ({1}°C)'.format(rfm69Fahrenheit, rfm69Celsius))
print('    Frequency:           {0} MHz'.format(round(rfm69.frequency_mhz, 0)))
print('    Bit rate:            {0} kbit/s'.format(rfm69.bitrate / 1000))
print('    Frequency deviation: {0} kHz'.format(rfm69.frequency_deviation / 1000))

#   Initialize the LSM303
lsmMag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
lsmAcc = adafruit_lsm303_accel.LSM303_Accel(i2c)

#   Initialize the NXP IMU
nxpAcc = adafruit_fxos8700.FXOS8700(i2c)
nxpGyro = adafruit_fxas21002c.FXAS21002C(i2c)

loopCount = 0
print()

while True:
    blinkLED(onBoardLED)
    loopCount += 1

    if DEBUG:
        print("Loop #{0:6d}".format(loopCount))
        print()

    lsm_acc_x, lsm_acc_y, lsm_acc_z = lsmAcc.acceleration
    lsm_mag_x, lsm_mag_y, lsm_mag_z = lsmMag.magnetic
예제 #22
0
import os
import sys
import time
import smbus
import busio
import board
import numpy as np

import adafruit_fxos8700
import adafruit_fxas21002c
from imusensor.filters import kalman

# Initialize I2C bus and device.
i2c = busio.I2C(board.SCL, board.SDA)
mag_accel = adafruit_fxos8700.FXOS8700(i2c)
gyro = adafruit_fxas21002c.FXAS21002C(i2c)

sensorfusion = kalman.Kalman()


def read():
    # Read acceleration & magnetometer.
    accel_x, accel_y, accel_z = mag_accel.accelerometer
    mag_x, mag_y, mag_z = mag_accel.magnetometer
    gyro_x, gyro_y, gyro_z = gyro.gyroscope

    return accel_x, accel_y, accel_z, mag_x, mag_y, mag_z, gyro_x, gyro_y, gyro_z


# accel_x, accel_y, accel_z, mag_x, mag_y, mag_z = read()
예제 #23
0
    logging.info('GPS Enabled')

# Adafruit Barometric Altimeter MPL3115A2
altimeter = None
if args.altimeter:
    altimeter = adafruit_mpl3115a2.MPL3115A2(i2c)
    altimeter.sealevel_pressure = 102520

    logging.info('Altimeter Enabled, Pressure: %d',
                 altimeter.sealevel_pressure)

# Adafruit 9-DOF Accelerometer
accelerometer = None
if args.accelerometer:
    accelerometer = adafruit_fxos8700.FXOS8700(i2c)

    logging.info('9-DOF Enabled')

######################################################################
# TRANSMIT FUNCTION
######################################################################


def transmit(aprs_info, num_transmissions):
    # write APRS message as wave audio file
    subprocess.run([
        script_path + '/afsk/aprs', '-c', CALLSIGN, '--destination', 'APCSU1',
        '-o', '/tmp/packet' + str(num_transmissions % 5) + '.wav', aprs_info
    ])
예제 #24
0
 def __init__(self):
     # Initialize I2C bus and device.
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.sensor = adafruit_fxos8700.FXOS8700(self.i2c)