如何用Navio2的MPU9250(python2)中的陀螺仪计算音高值

时间:2017-05-22 23:57:07

标签: python raspberry-pi sensor gyroscope robotics

我可以获得陀螺仪传感器的原始值。

但是,我不知道如何使用这些值来计算音高值。

我想让音高值介于-180和+180之间。

这是因为我想使用互补滤波器获得精确的音高值,该互补滤波器具有用加速度计获得的音高值和用陀螺仪获得的音高值。

请帮帮我。

我的代码(获取陀螺仪传感器的原始值)

import spidev
import time
import argparse
import sys
import navio.mpu9250
import navio.util

navio.util.check_apm()

imu = navio.mpu9250.MPU9250()
imu.initialize()

m9a, m9g, m9m = acc.imu.getMotion9()

#These are raw values of gyroscope
gyro_x = m9g[0]
gyro_y = m9g[1]
gyro_z = m9g[2]

详细(设定)

gyro_scale = 2000DPS

gyro_divider = 16.4

'陀螺仪传感器的原始值' =(PI / 180)* data / gyro_divider

enter image description here

Reference code.

...

def getMotion9(self):
    self.read_all()
    m9a = self.accelerometer_data
    m9g = self.gyroscope_data
    m9m = self.magnetometer_data

    return m9a, m9g, m9m

...

def read_all(self):
    # Send I2C command at first
    # Set the I2C slave addres of AK8963 and set for read.
    self.WriteReg(self.__MPUREG_I2C_SLV0_ADDR, self.__AK8963_I2C_ADDR | self.__READ_FLAG)
    # I2C slave 0 register address from where ; //Read 7 bytes from the magnetometerto begin data transfer
    self.WriteReg(self.__MPUREG_I2C_SLV0_REG, self.__AK8963_HXL)
    # Read 7 bytes from the magnetometer
    self.WriteReg(self.__MPUREG_I2C_SLV0_CTRL, 0x87)
    # must start your read from AK8963A register 0x03 and read seven bytes so that upon read of ST2 register 0x09 the AK8963A will unlatch the data registers for the next measurement.

    # time.sleep(0.001)
    response = self.ReadRegs(self.__MPUREG_ACCEL_XOUT_H, 21);

    # Get Accelerometer values
    for i in range(0, 3):
        data = self.byte_to_float(response[i*2:i*2+2])
        self.accelerometer_data[i] = self.G_SI*data/self.acc_divider

    # Get temperature
    i = 3
    temp = self.byte_to_float(response[i*2:i*2+2])
    self.temperature = (temp/340.0)+36.53

    # Get gyroscope values
    for i in range(4, 7):
        data = self.byte_to_float(response[i*2:i*2+2])
        self.gyroscope_data[i-4] =(self.PI/180)*data/self.gyro_divider

    # Get magnetometer values
    for i in range(7, 10):
        data = self.byte_to_float_le(response[i*2:i*2+2])
        self.magnetometer_data[i-7] = data * self.magnetometer_ASA[i-7]

0 个答案:

没有答案