コード例 #1
0
ファイル: orient.py プロジェクト: GuyCarver/raspi
  def __init__( self ):
    '''  '''
    self._mpu = MPU9250(
        address_ak=AK8963_ADDRESS,
        address_mpu_master=MPU9050_ADDRESS_68, # In 0x68 Address
        address_mpu_slave=None,
        bus=1,
        gfs=GFS_1000,
        afs=AFS_8G,
        mfs=AK8963_BIT_16,
        mode=AK8963_MODE_C100HZ)

    # self._mpu.calibrate()
    self._mpu.configure() # Apply the settings to the registers.

    a = self._mpu.readAccelerometerMaster()
    g = self._mpu.readGyroscopeMaster()
    m = self._mpu.readMagnetometerMaster()

    self._ypr = mwick.updateypr(g[0], g[1], g[2], a[0], a[1], a[2], m[0], m[1], m[2], 0.1)

    self._prevtime = perf_counter()

    self._minext = 0.0
    self._maxext = 0.0
コード例 #2
0
    def __init__(self):
        super().__init__()
        self.sumGyroZ = 0
        self.mpuComVal = 0.0004
        self.mpu = MPU9250(
            address_ak=AK8963_ADDRESS,
            address_mpu_master=MPU9050_ADDRESS_68,  # In 0x68 Address
            address_mpu_slave=None,
            bus=1,
            gfs=GFS_1000,
            afs=AFS_8G,
            mfs=AK8963_BIT_16,
            mode=AK8963_MODE_C100HZ)

        self.mpu.configure()  # Apply the settings to the registers.
        # 		#enter accBiases:
        #print("accBiases", self.calibrateAccOffset(2000))
        self.accBiases = [
            0.4439825439453125, 0.352824462890625, -1.9188690185546875
        ]
        #gyroCalibration
        calibrationData = self.calibrateGyro(2000)
        self.gyroBiases = calibrationData[0:3]
        self.sumGyroX, self.sumGyroY = calibrationData[3]
        #print(self.sumGyroX,self.sumGyroY)
        #set Mpu Frequency
        self.freq = 100
コード例 #3
0
    def __init__(self):
        self._mpu = MPU9250(
            address_ak=AK8963_ADDRESS,
            address_mpu_master=MPU9050_ADDRESS_68,  # In 0x68 Address
            address_mpu_slave=None,
            bus=1,
            gfs=GFS_1000,
            afs=AFS_8G,
            mfs=AK8963_BIT_16,
            mode=AK8963_MODE_C8HZ)

        self._mpu.configure()

        self._mpu.abias = [
            -0.14861613948170732, 0.04269483612804878, 0.0027867759146340543
        ]
        self._mpu.gbias = [
            -1.9508920064786586, -0.5945345250571646, -0.7832224776105182
        ]
        self._mpu.magbias = [
            0.7719651240778002, 0.826867816091954, 2.0192982456140354
        ]
        self._mpu.mbias = [
            42.44004407051282, 19.4276365995116, -94.42522512210013
        ]
コード例 #4
0
ファイル: mpu9250.py プロジェクト: davidmpereira/Adeept_AWR
class Gyro:

    mpu = MPU9250(
        address_ak=AK8963_ADDRESS,
        address_mpu_master=MPU9050_ADDRESS_68,  # In 0x68 Address
        address_mpu_slave=None,
        bus=1,
        gfs=GFS_1000,
        afs=AFS_8G,
        mfs=AK8963_BIT_16,
        mode=AK8963_MODE_C100HZ)

    def __init__(self):
        super().__init__()

        self.mpu2 = self.mpu

    def getOrientation(self):

        self.mpu2.configure  # Apply the settings to the registers.

        result = self.mpu2.readMagnetometerMaster()

        degree = atan2(result[1], result[0]) * (180 / pi)

        return (str(degree))
コード例 #5
0
ファイル: mpu.py プロジェクト: zjor/balancing-robot
    def __init__(self, calibrate=False):
        self.mpu = MPU9250(address_ak=AK8963_ADDRESS,
                           address_mpu_master=MPU9050_ADDRESS_68,
                           address_mpu_slave=None,
                           bus=1,
                           gfs=GFS_1000,
                           afs=AFS_4G,
                           mfs=AK8963_BIT_16,
                           mode=AK8963_MODE_C100HZ)

        if calibrate:
            # self.mpu.calibrate()
            self.mpu.calibrateMPU6500()
        self.mpu.configure()
        self.mpu.writeMaster(CONFIG, 0x04)
コード例 #6
0
ファイル: server.py プロジェクト: se1exin/auto-telescope
    def __init__(self):
        self.mpu9250 = MPU9250(
            address_ak=AK8963_ADDRESS,
            address_mpu_master=MPU9050_ADDRESS_68,
            address_mpu_slave=None,
            bus=1,
            gfs=GFS_1000,
            afs=AFS_8G,
            mfs=AK8963_BIT_16,
            mode=AK8963_MODE_C100HZ,
        )

        # Status Values
        self.is_updating = False
        self.has_position = False
        self.position_stable = False
        self.is_mag_calibrating = False
        self.mag_calibrated = False
        self.mpu_calibrated = False

        # Position Values
        self.roll_raw = 0.0
        self.pitch_raw = 0.0
        self.yaw_raw = 0.0
        self.roll_filtered = 0.0
        self.pitch_filtered = 0.0
        self.yaw_filtered = 0.0
        self.roll_smoothed = 0.0
        self.pitch_smoothed = 0.0
        self.yaw_smoothed = 0.0

        # How many degrees of variance can be tolerated in stability detection?
        self.stability_threshold = 0.5  # @TODO: Make configurable

        # Manual Mag Calibration
        # @TODO: Make configurable
        self.mpu9250.mbias = [
            20.7454594017094,
            10.134935897435899,
            -11.132967032967032,
        ]
コード例 #7
0
    def __init__(self,
                 addr=0x68,
                 poll_delay=0.0166,
                 sensor=SENSOR_MPU6050,
                 dlp_setting=DLP_SETTING_DISABLED):
        self.sensortype = sensor
        if self.sensortype == SENSOR_MPU6050:
            from mpu6050 import mpu6050 as MPU6050
            self.sensor = MPU6050(addr)

            if (dlp_setting > 0):
                self.sensor.bus.write_byte_data(self.sensor.address,
                                                CONFIG_REGISTER, dlp_setting)

        else:
            from mpu9250_jmdev.registers import AK8963_ADDRESS, GFS_1000, AFS_4G, AK8963_BIT_16, AK8963_MODE_C100HZ
            from mpu9250_jmdev.mpu_9250 import MPU9250

            self.sensor = MPU9250(
                address_ak=AK8963_ADDRESS,
                address_mpu_master=addr,  # In 0x68 Address
                address_mpu_slave=None,
                bus=1,
                gfs=GFS_1000,
                afs=AFS_4G,
                mfs=AK8963_BIT_16,
                mode=AK8963_MODE_C100HZ)

            if (dlp_setting > 0):
                self.sensor.writeSlave(CONFIG_REGISTER, dlp_setting)
            self.sensor.calibrateMPU6500()
            self.sensor.configure()

        self.accel = {'x': 0., 'y': 0., 'z': 0.}
        self.gyro = {'x': 0., 'y': 0., 'z': 0.}
        self.mag = {'x': 0., 'y': 0., 'z': 0.}
        self.temp = 0.
        self.poll_delay = poll_delay
        self.on = True
コード例 #8
0
 def setup(self):
     mpu = MPU9250(
         address_ak=AK8963_ADDRESS,
         address_mpu_master=MPU9050_ADDRESS_68,  # In 0x68 Address
         address_mpu_slave=None,
         bus=1,
         gfs=GFS_1000,
         afs=AFS_8G,
         mfs=AK8963_BIT_16,
         mode=AK8963_MODE_C100HZ)
     # mpu.calibrate() # Calibrate sensors
     mpu.configure()  # Apply the settings to the registers.
     mpu.calibrateMPU6500()  # Calibrate sensors
     mpu.configure(
     )  # The calibration function resets the sensors, so you need to reconfigure them
     abias = mpu.abias  # Get the master accelerometer biases
     abias_slave = mpu.abias_slave  # Get the slave accelerometer biases
     gbias = mpu.gbias  # Get the master gyroscope biases
     gbias_slave = mpu.gbias_slave  # Get the slave gyroscope biases
     mpu.abias = [0, 0, 0]  # Set the master accelerometer biases
     mpu.abias_slave = [0, 0, 0]  # Set the slave accelerometer biases
     mpu.gbias = [0, 0, 0]  # Set the master gyroscope biases
     mpu.gbias_slave = [0, 0, 0]  # Set the slave gyroscope biases
     return mpu
コード例 #9
0
ファイル: mpu_test.py プロジェクト: zjor/balancing-robot
from mpu9250_jmdev.mpu_9250 import MPU9250


def get_roll_pitch(mpu):
    x, y, z = mpu.readAccelerometerMaster()
    roll = atan2(x, z)
    pitch = atan2(y, z)
    return roll, pitch


if __name__ == "__main__":
    mpu = MPU9250(
        address_ak=AK8963_ADDRESS,
        address_mpu_master=MPU9050_ADDRESS_68,  # In 0x68 Address
        address_mpu_slave=None,
        bus=1,
        gfs=GFS_1000,
        afs=AFS_4G,
        mfs=AK8963_BIT_16,
        mode=AK8963_MODE_C100HZ)

    mpu.calibrate()
    mpu.configure()

    while True:

        print("|.....MPU9250 in 0x68 Address.....|")
        print("Accelerometer", mpu.readAccelerometerMaster())
        print("Gyroscope", mpu.readGyroscopeMaster())
        print("Magnetometer", mpu.readMagnetometerMaster())
        print("Temperature", mpu.readTemperatureMaster())
コード例 #10
0
def GY91():
    '''
    from time import *
    from colorama import init, Fore, Back, Style
    from mpu9250_jmdev.registers import *
    from mpu9250_jmdev.mpu_9250 import MPU9250
    import os
    '''
    os.system('clear')
    counter = 0
    hr = 0
    min = 0
    sec = 0

    # Script for have a time's follow up
    sec += 1
    if sec == 60:
        min += 1
        sec = 0
    if min == 60:
        hr += 1
        min = 0

    mpu = MPU9250(
        address_ak=AK8963_ADDRESS,
        address_mpu_master=MPU9050_ADDRESS_68, # In 0x68 Address
        address_mpu_slave=None,
        bus=1,
        gfs=GFS_1000,
        afs=AFS_8G,
        mfs=AK8963_BIT_16,
        mode=AK8963_MODE_C100HZ)
    mpu.configure()

    while True:
        watch = f'{hr}:{min}:{sec}'

        accelerometer = mpu.readAccelerometerMaster()
        gyroscope = mpu.readGyroscopeMaster()
        magnetometer = mpu.readMagnetometerMaster()
        temperature = mpu.readTemperatureMaster()

        #Accelerometer sorted values if [0][1][2] are X,Y,Z axis respectively
        xA = round(accelerometer[0], 6)
        yA = round(accelerometer[1], 6)
        zA = round(accelerometer[2], 6)
        outA = [xA, yA, zA]

        #Gyroscope sorted values if [0][1][2] are X,Y,Z axis respectively
        xG = round(gyroscope[0], 6)
        yG = round(gyroscope[1], 6)
        zG = round(gyroscope[2], 6)
        outG = [xG, yG, zG]

        #Magnetometer sorted values if [0][1][2] are X,Y,Z axis respectively
        xM = round(magnetometer[0], 6)
        yM = round(magnetometer[1], 6)
        zM = round(magnetometer[2], 6)
        outM = [xM, yM, zM]

        try:
            print('\t#.....MPU9250 in 0x68 Address at ' + Fore.GREEN + f'{watch}' + Style.RESET_ALL + '.....#\n')
    		print(Back.WHITE + Fore.BLACK + "Accelerometer:   " + str(outA) + Style.RESET_ALL)
    		print(Back.WHITE + Fore.BLACK + "Gyroscope:       " + str(outG) + Style.RESET_ALL)
    		print(Back.WHITE + Fore.BLACK + "Magnetometer:    " + str(outM) + Style.RESET_ALL)
    		print(Back.WHITE + Fore.BLACK + "(C) Temperature: " + str(round(temperature, 6)) + Style.RESET_ALL )
    		print('\n')
            counter += 1
    		sleep(1)
コード例 #11
0
- Giroscopio
- Magnetómetro
- Presión
- Temperatura
'''
#Configurar desde Rasp con algunos de los siguientes:
    #https://pypi.org/project/mpu9250-jmdev/
    #http://www.pibits.net/code/raspberry-pi-and-bmp280-sensor-example.php
    #https://makersportal.com/blog/2019/11/11/raspberry-pi-python-accelerometer-gyroscope-magnetometer#simple-plots
#MPU9250
import time
from mpu9250_jmdev.registers import *
from mpu9250_jmdev.mpu_9250 import MPU9250

mpu = MPU9250(
    address_ak=AK8963_ADDRESS,
    address_mpu_master=MPU9050
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# BMP280
# This code is designed to work with the BMP280_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Barometer?sku=BMP280_I2CSs#tabs-0-product_tabset-2
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# BMP280 address, 0x76(118)
# Read data back from 0x88(136), 24 bytes
b1 = bus.read_i2c_block_data(0x76, 0x88, 24)
# Convert the data
# Temp coefficents
dig_T1 = b1[1] * 256 + b1[0]
コード例 #12
0
ファイル: sampling.py プロジェクト: nvtkaszpir/MPU9250
 def __init__(self, address_ak, address_mpu_master, address_mpu_slave, bus, gfs, afs, mfs, mode):
     Thread.__init__(self)
     self.mpu = MPU9250(address_ak, address_mpu_master, address_mpu_slave, bus, gfs, afs, mfs, mode)
コード例 #13
0
ファイル: pi_pact.py プロジェクト: samuelwang23/PiPact
    def scan(self, scan_prefix='', timeout=0, revisit=1):
        """Execute BLE beacon scan.

        Args:
            scan_prefix (str): Scan output file prefix. Final output file name
                will be appended with first scan start timestamp. Defaults to
                configuration value.
            timeout (int, float): Time (s) for which to advertise beacon. If
                specified as None then advertises till user commanded stop via
                control file. Defaults to configuration value.
            revisit (int): Time interval (s) between consecutive scans.
                Defaults to 1.

        Returns:
            Filtered advertisements organized in a pandas.DataFrame by address
            first, timestamp second, and then remainder of advertisement
            payload, e.g., UUID, major, minor, etc.
        """
        #Printing Test
        bucket_start_time = datetime.now()
        print(bucket_start_time)
        # Parse inputs
        if scan_prefix == '':
            scan_prefix = self.scan_prefix
        if timeout == 0:
            timeout = self.timeout
        # Update control file and scan output file
        with open(self.__control_file, 'w') as f:
            f.write("0")
        scan_file = Path(f"{scan_prefix}_{datetime.now():%Y%m%dT%H%M%S}.csv")
        # Start advertising
        self.__logger.info(f"Starting beacon scanner with timeout {timeout}.")
        self.__control_file_handle = self.__control_file.open(mode='r+')
        run = True
        timestamps = defaultdict(list)
        scans = defaultdict(list)
        scan_count = 0

        current_bucket_id = 0
        #9250
        mpu = MPU9250(
            address_ak=AK8963_ADDRESS,
            address_mpu_master=MPU9050_ADDRESS_68,  # In 0x68 Address
            address_mpu_slave=None,
            bus=1,
            gfs=GFS_1000,
            afs=AFS_8G,
            mfs=AK8963_BIT_16,
            mode=AK8963_MODE_C100HZ)
        mpu.configure()
        mpu.calibrate()
        print("Done Calibration")
        mpu.configure()
        start_time = time.monotonic()
        while run:
            scan_count += 1
            self.__logger.debug(f"Performing scan #{scan_count} at revisit "
                                f"{self.revisit}.")
            ble_scan = self.__service.scan(self.revisit)
            diff = datetime.now() - bucket_start_time
            bucket_id = diff.seconds // TIME_INTERVAL
            if ble_scan:
                accel = mpu.readAccelerometerMaster()
                gyro = mpu.readMagnetometerMaster()
                mag = mpu.readGyroscopeMaster()
                if current_bucket_id != bucket_id:
                    print("New bucket created")
                    current_bucket_id = bucket_id
                scans[current_bucket_id].append([ble_scan, accel, gyro, mag])
                timestamps[current_bucket_id].append(datetime.now())
            # Stop advertising based on either timeout or control file
            if timeout is not None:
                if (time.monotonic() - start_time) > timeout:
                    self.__logger.debug("Beacon scanner timed out.")
                    run = False
            self.__control_file_handle.seek(0)
            control_flag = self.__control_file_handle.read()
            if control_flag != "0":
                self.__logger.debug("Beacon scanner control flag set to stop.")
                run = False
        self.__logger.info("Stopping beacon scanner.")
        # Cleanup
        self.__control_file_handle.close()
        with self.__control_file.open('w') as f:
            f.write("0")
        # Process, filter, and output received scans
        advertisements = self.process_scans(scans, timestamps)
        advertisements = self.filter_advertisements(advertisements)
        advertisements.to_csv(scan_file, index_label='SCAN')
        return advertisements