Ejemplo n.º 1
0
import time
import board
from adafruit_lsm6ds import LSM6DSOX as LSM6DS

# To use LSM6DS33, comment out the LSM6DSOX import line
# and uncomment the next line
# from adafruit_lsm6ds import LSM6DS33 as LSM6DS

# To use ISM330DHCX, comment out the LSM6DSOX import line
# and uncomment the next line
# from adafruit_lsm6ds import ISM330DHCX as LSM6DS

from adafruit_lis3mdl import LIS3MDL

accel_gyro = LSM6DS(board.I2C())
mag = LIS3MDL(board.I2C())

while True:
    acceleration = accel_gyro.acceleration
    gyro = accel_gyro.gyro
    magnetic = mag.magnetic
    print("Acceleration: X:{0:7.2f}, Y:{1:7.2f}, Z:{2:7.2f} m/s^2".format(
        *acceleration))
    print(
        "Gyro          X:{0:7.2f}, Y:{1:7.2f}, Z:{2:7.2f} rad/s".format(*gyro))
    print("Magnetic      X:{0:7.2f}, Y:{1:7.2f}, Z:{2:7.2f} uT".format(
        *magnetic))
    print("")
    time.sleep(0.5)
Ejemplo n.º 2
0
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" Test Each Data Rate """

# pylint: disable=no-member
import time
import board
import busio
from adafruit_lis3mdl import LIS3MDL, Rate, PerformanceMode

i2c = busio.I2C(board.SCL, board.SDA)
sensor = LIS3MDL(i2c)

current_rate = Rate.RATE_155_HZ
sensor.data_rate = current_rate
start_time = time.monotonic()
print("data_rate is", Rate.string[sensor.data_rate], "HZ")
print("performance_mode is", PerformanceMode.string[sensor.performance_mode])
while True:
    mag_x, mag_y, mag_z = sensor.magnetic

    print("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(
        mag_x, mag_y, mag_z))

    # sleep for enough time so that we'll read the value twice per measurement
    sleep_time = 1 / (Rate.string[current_rate] * 2)
    time.sleep(sleep_time)

    # exit loop after a second to prevent hard to stop loops with short delays
    if (time.monotonic() - start_time) > 1:
        break
import time
import board
from adafruit_lsm6ds.lsm6dsox import LSM6DSOX as LSM6DS

# To use LSM6DS33, comment out the LSM6DSOX import line
# and uncomment the next line
# from adafruit_lsm6ds.lsm6ds33 import LSM6DS33 as LSM6DS

# To use ISM330DHCX, comment out the LSM6DSOX import line
# and uncomment the next line
# from adafruit_lsm6ds.lsm330dhcx import ISM330DHCX as LSM6DS

from adafruit_lis3mdl import LIS3MDL

i2c = board.I2C()  # uses board.SCL and board.SDA
accel_gyro = LSM6DS(i2c)
mag = LIS3MDL(i2c)

while True:
    acceleration = accel_gyro.acceleration
    gyro = accel_gyro.gyro
    magnetic = mag.magnetic
    print(
        "Acceleration: X:{0:7.2f}, Y:{1:7.2f}, Z:{2:7.2f} m/s^2".format(*acceleration)
    )
    print("Gyro          X:{0:7.2f}, Y:{1:7.2f}, Z:{2:7.2f} rad/s".format(*gyro))
    print("Magnetic      X:{0:7.2f}, Y:{1:7.2f}, Z:{2:7.2f} uT".format(*magnetic))
    print("")
    time.sleep(0.5)
from adafruit_lsm6ds.lsm6dsox import LSM6DSOX as LSM6DS
from adafruit_lis3mdl import LIS3MDL
from scipy.spatial.transform import Rotation as R
import board
import numpy as np
import time
import math

accel_gyro = LSM6DS(board.I2C())
magnetic = LIS3MDL(board.I2C())

GRAVITY = 9.802 # The gravity acceleration in New York City

# Calibration outcomes
   
GYRO_X_OFFSET =  0.01465514
GYRO_Y_OFFSET =  0.00873888
GYRO_Z_OFFSET = -0.01110159
      
ACCEL_X_OFFSET = 0.11090005
ACCEL_Y_OFFSET = -0.11273523
ACCEL_Z_OFFSET = 9.89793281

magn_ellipsoid_center = np.array([-0.71882994, -1.47720803, 2.13276772])
magn_ellipsoid_transform = np.array([[ 0.99220953, -0.01757624, -0.03020328],
 [-0.01757624,  0.81745802, -0.02563071],
 [-0.03020328, -0.02563071,  0.8702554]])

time_former = 0

q = [1, 0, 0, 0]
Ejemplo n.º 5
0
def main():
    # pylint: disable=too-many-locals, too-many-statements
    i2c = busio.I2C(board.SCL, board.SDA)

    gyro_accel = LSM6DSOX(i2c)
    magnetometer = LIS3MDL(i2c)
    key_listener = KeyListener()
    key_listener.start()

    ############################
    # Magnetometer Calibration #
    ############################

    print("Magnetometer Calibration")
    print("Start moving the board in all directions")
    print("When the magnetic Hard Offset values stop")
    print("changing, press ENTER to go to the next step")
    print("Press ENTER to continue...")
    while not key_listener.pressed:
        pass

    mag_x, mag_y, mag_z = magnetometer.magnetic
    min_x = max_x = mag_x
    min_y = max_y = mag_y
    min_z = max_z = mag_z

    while not key_listener.pressed:
        mag_x, mag_y, mag_z = magnetometer.magnetic

        print("Magnetometer: X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} uT".format(
            mag_x, mag_y, mag_z))

        min_x = min(min_x, mag_x)
        min_y = min(min_y, mag_y)
        min_z = min(min_z, mag_z)

        max_x = max(max_x, mag_x)
        max_y = max(max_y, mag_y)
        max_z = max(max_z, mag_z)

        offset_x = (max_x + min_x) / 2
        offset_y = (max_y + min_y) / 2
        offset_z = (max_z + min_z) / 2

        field_x = (max_x - min_x) / 2
        field_y = (max_y - min_y) / 2
        field_z = (max_z - min_z) / 2

        print("Hard Offset:  X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} uT".format(
            offset_x, offset_y, offset_z))
        print("Field:        X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} uT".format(
            field_x, field_y, field_z))
        print("")
        time.sleep(0.01)

    mag_calibration = (offset_x, offset_y, offset_z)
    print(
        "Final Magnetometer Calibration: X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} uT"
        .format(offset_x, offset_y, offset_z))

    #########################
    # Gyroscope Calibration #
    #########################

    gyro_x, gyro_y, gyro_z = gyro_accel.gyro
    min_x = max_x = gyro_x
    min_y = max_y = gyro_y
    min_z = max_z = gyro_z

    print("")
    print("")
    print("Gyro Calibration")
    print("Place your gyro on a FLAT stable surface.")
    print("Press ENTER to continue...")
    while not key_listener.pressed:
        pass

    for _ in range(SAMPLE_SIZE):
        gyro_x, gyro_y, gyro_z = gyro_accel.gyro

        print("Gyroscope: X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} rad/s".format(
            gyro_x, gyro_y, gyro_z))

        min_x = min(min_x, gyro_x)
        min_y = min(min_y, gyro_y)
        min_z = min(min_z, gyro_z)

        max_x = max(max_x, gyro_x)
        max_y = max(max_y, gyro_y)
        max_z = max(max_z, gyro_z)

        offset_x = (max_x + min_x) / 2
        offset_y = (max_y + min_y) / 2
        offset_z = (max_z + min_z) / 2

        noise_x = max_x - min_x
        noise_y = max_y - min_y
        noise_z = max_z - min_z

        print("Zero Rate Offset:  X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} rad/s".
              format(offset_x, offset_y, offset_z))
        print("Rad/s Noise:       X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} rad/s".
              format(noise_x, noise_y, noise_z))
        print("")

    gyro_calibration = (offset_x, offset_y, offset_z)
    print("Final Zero Rate Offset: X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} rad/s".
          format(offset_x, offset_y, offset_z))
    print("")
    print(
        "------------------------------------------------------------------------"
    )
    print("Final Magnetometer Calibration Values: ", mag_calibration)
    print("Final Gyro Calibration Values: ", gyro_calibration)
Ejemplo n.º 6
0
import time
import subprocess
import board
import busio
from adafruit_lis3mdl import LIS3MDL
from adafruit_lsm6ds.lsm6ds33 import LSM6DS33


i2c = busio.I2C(board.SCL, board.SDA)
senseMag = LIS3MDL(i2c)
senseGyro = LSM6DS33(i2c)

cmd = "hostname -I | cut -d' ' -f1"
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")

while True:
    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" %
          (senseGyro.acceleration))
    print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (senseGyro.gyro))
    print("")
    #mag_x, mag_y, mag_z = senseMag.magnetic
    print("Magnetic X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT" % (
        senseMag.magnetic))
    time.sleep(0.5)