Exemplo n.º 1
0
 def __init__(self):
     super(IMU, self).__init__()
     self.lsm6ds33 = LSM6DS33()
     self.gyroAccelEnabled = False        
     self.lps25h = LPS25H()
     self.barometerEnabled = False        
     self.lis3mdl = LIS3MDL()
     self.magnetometerEnabled = False
Exemplo n.º 2
0
 def __init__(self, busId=1, sa0=SA0_HIGH):
     """ Compose other classes
         busId refers to the I2C bus to use (default 1)
         sa0 refers to the I2C Master/Slave address pin status
             SA0_HIGH (default) == pullup to vcc => Master addresses
             SA0_LOW == grounded => Slave addresses
     """
     self.imu = LSM6DS33(busId=busId, sa0=sa0)
     self.magnet = LIS3MDL(busId, sa0=sa0)
     self.baro = LPS25H(busId, sa0=sa0)
Exemplo n.º 3
0
#!/usr/bin/python

from time import sleep

from lsm6ds33 import LSM6DS33
from lis3mdl import LIS3MDL
from lps25h import LPS25H

imu = LSM6DS33()
#imu.enable()
imu.enableLSM()

magnet = LIS3MDL()
#magnet.enable()
magnet.enableLIS()

baro = LPS25H()
#baro.enable()
baro.enableLPS()

while True:
    print "Gyro:", imu.getGyroscopeRaw()
    print "Accelerometer:", imu.getAccelerometerRaw()
    print "Magnet:", magnet.getMagnetometerRaw()
    print "hPa:", baro.getBarometerMillibars()
    print "Altitude:", baro.getAltitude()
    sleep(0.2)
    #    print "Gyro Temperature:", imu.getTemperatureCelsius()
    #    print "Magnet Temperature:", magnet.getTemperatureCelsius()
    #    print "Baro Temperature:", baro.getTemperatureCelsius()
    sleep(0.1)
Exemplo n.º 4
0
def main():
    magnetometer = LIS3MDL()
    magnetometer.enableLIS()

    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

    min_x_Raw = []
    min_y_Raw = []
    min_z_Raw = []

    max_x_Raw = []
    max_y_Raw = []
    max_z_Raw = []

    mag_x, mag_y, mag_z = magnetometer.getMagnetometerRaw()
    min_x = max_x = mag_x
    min_y = max_y = mag_y
    min_z = max_z = mag_z

    for _ in range(SAMPLE_SIZE):
        mag_x, mag_y, mag_z = magnetometer.getMagnetometerRaw()

        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)

        min_x_Raw.append(min_x)
        min_y_Raw.append(min_y)
        min_z_Raw.append(min_z)

        max_x_Raw.append(max_x)
        max_y_Raw.append(max_y)
        max_z_Raw.append(max_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

        avg_rad = (field_x + field_y + field_z)
        avg_rad = avg_rad / 3

        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)

        #plt.title("XY Plane")
        #plt.plot(mag_x, mag_y, c="b",marker="o")

    x_scale = avg_rad / field_x
    y_scale = avg_rad / field_y
    z_scale = avg_rad / field_z

    #plt.show()
    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))

    print("")
    print(
        "------------------------------------------------------------------------"
    )
    print("Final Magnetometer Calibration Values: ", mag_calibration)

    print("Scale Factor: X: {0:8.2f}, Y:{1:8.2f}, Z:{2:8.2f} uT".format(
        x_scale, y_scale, z_scale))

    min_x_calib = [x - offset_x for x in min_x_Raw]
    min_y_calib = [y - offset_y for y in min_y_Raw]

    max_x_calib = [x - offset_x for x in max_x_Raw]
    max_y_calib = [y - offset_y for y in max_y_Raw]
Exemplo n.º 5
0
    A = X[5] + OSx**2 + X[3] * OSy**2 + X[4] * OSz**2
    B = A / X[3]
    C = A / X[4]

    SCx = numpy.sqrt(A)
    SCy = numpy.sqrt(B)
    SCz = numpy.sqrt(C)

    # type conversion from numpy.float64 to standard python floats
    offsets = [OSx, OSy, OSz]
    scale = [SCx, SCy, SCz]

    offsets = map(numpy.asscalar, offsets)
    scale = map(numpy.asscalar, scale)

    return (offsets, scale)


magneto = LIS3MDL()

#offsets, scale = real_time_calibration()
callibration()

#print('offsets:')
#for item in offsets:
#    print(item)

#print('scale:')
#for item in scale:
#    print(item)
Exemplo n.º 6
0
 def __init__(self):
     self.accelerometer = LIS331DLH()
     self.gyroscope = L3G4200D()
     self.magnetometer = LIS3MDL()
     self.barometer = LPS331AP()
Exemplo n.º 7
0
import pyb
from board import sys_config, board
from lsm6ds3 import LSM6DS3
from lis3mdl import LIS3MDL
from lps25h import LPS25H
from vl6180x import VL6180X

frog = board()
i2c = pyb.I2C(sys_config['lis3mdl']['i2c_bus'],
              pyb.I2C.MASTER,
              baudrate=100000)

mems = LSM6DS3(i2c, sys_config['lsm6ds3']['i2c_addr'])
print("Acceleration  (%.3e, %.3e, %.3e)" % mems.accel.xyz())
print("Rotation      (%.3e, %.3e, %.3e)" % mems.gyro.xyz())
print("Temperature   %.2f C" % mems.temperature())

mag = LIS3MDL(i2c, sys_config['lis3mdl']['i2c_addr'])
x, y, z = mag.xyz()
print("Magnetic field = (%.3e, %.3e, %.3e) %s" % (x, y, z, mag.unit()))

p = LPS25H(i2c, sys_config['lps25h']['i2c_addr'])
print("Pressure %5.3e %s, Height %.1f m, Temperature = %.1f C" %
      (p.value(), p.unit(), p.height(), p.temperature()))

dist = VL6180X(i2c, sys_config['vl6180x']['i2c_addr'])
val = dist.dev_id()
print("Distance sensor:")
print("\n".join(["  %s: %s" % (k, v) for k, v in val.items()]))
print("Distance      %.1f %s" % (dist.value(), dist.unit()))