AHRS attitude algorithm described (acceleration + + magnetometer gyroscope raw data analysis and Principle)

Reprinted link: http://www.51hei.com/bbs/dpj-92911-1.html
AHRS Attitude Heading Reference System commonly known, AHRS consists of an accelerometer, magnetometer, gyroscope, real AHRS reference comes from the Earth's gravity Earth's magnetic field and the field ~ he static final accuracy depends on the measurement accuracy and the measurement accuracy of the magnetic field of gravity, and the gyro decision his dynamic performance.
  This is the AHRS ~ in this context. Description AHRS left ~~ Earth's gravity and magnetic field environment of this time is not working properly
this chapter is to explain the following
1. acceleration
2. gyroscope
3. magnetometer
calculation principle always wanted to write articles about the attitude solution , as far as possible using the common statement shows how the accelerometer and gyroscope data from the attitude angle obtained fusion vector. Helpless limited their level, it has been shelved. Indifferent to Ming, Calm Heart. People always want to force myself to do something, just a nice peace of mind. Then get some time to integrate this aspect of information about it. Most of the content of this article is not my original, thanks to the selfless dedication of people on the network.
In this experiment tell us about the attitude of the board, a new generation of mini AHRS, using STM32F103 microcontroller attitude solution, integrated with the board
1. MPU6050, triaxial accelerometer and gyroscope
2.HMC5883 triaxial magnetometer
3.BMP180 barometer precision
of these sensors are connected to the main controller via the I2C interface STM32. no additional ADC circuit, can be directly through the digital interface reading sensor output current.

Mini AHRS hardware block diagram
0.png

1 accelerometer
accelerometer name suggests, is to measure acceleration. So how do we know this acceleration? In this case the shape of a cube with a model to do, understanding the acceleration, as follows, the image in the box.
0.png
If we put a cube-shaped box no place gravitational field, the ball will remain in the middle of the box. As you can imagine, the box is in outer space, away from any celestial body, it is difficult to find such a place, imagine the spacecraft orbit around Earth fly, everything is in a state of weightlessness. So six wall feel the pressure is 0.
If we suddenly cube (we accelerate accelerated, 1G = 9.8 Mi / S ^ 2) moves to the left, the ball hit the wall X-. Then, we measured the pressure applied to the ball and the wall -1g output values of the X-axis. Below
0.png
Note that the acceleration vector is reacted with the accelerometer current direction opposite to the force. As shown above, the force leftward direction, but the direction of the acceleration vector to the right.
If we put this small box brought on Earth, then the ball will fall on the Z- wall, and will exert a force of 1G bottom wall, as shown in the following picture:
0.png
in this case, the frame does not move, but we can still get the Z axis reading -1G. Ball pressure on the walls caused by the gravitational field.
So far, we have analyzed the output of a single-axis accelerometer, which is you will get a single-axis accelerometer. Triaxial accelerometer true value, that is, they can detect all the inertia force three axes simultaneously. Let's go back to our box model, and let rotated 45 degrees in the right box. Balls will touch two walls: Z X- and the picture shown in the following:
0.png
X-axis being 0.71 and z is not arbitrary value which is actually an approximation SQRT (1/2) to know when the cartridge by gravity only?. when field, x 2 + Y 2 + with 2 = 1 g {x^2 +Y^2+z^2 =1g} This will become clearer as we introduce our next accelerometer look like.
In the previous box model, we have fixed and rotating gravitational field. In the two examples just described, we analyzed two different output frame position and the force vector remains unchanged. Which is more conducive to learn how to interact with an external accelerometer, and displays the current reading.
0.png
Take a look at the above model, which is a new model instead of just boxes cube. Imagine the new model in each axis is perpendicular to the wall surface of the box. Vector R is measured by an accelerometer (from a combination of the above examples or both, it may be a gravitational field or an inertial force) force vector. Upon receipt, Ry, RZ X and on, Y, R Z-axis vector projection. Please note the following relationship:
R ^ 2 = ^ 2 + RX RY RZ ^ 2 ^ 2 + (Equation 1)
Remember, I told you earlier, SQRT (1/2) value is not random ~0.71. If you the above formula, we review the gravitational field is 1 g, we can verify that:
. 1 ^ 2 = (- SQRT (1/2)) ^ 2 + 2 ^ 0 + (- SQRT (1/2)) ^ 2
when simply by substituting R = 1, when receiving = SQRT (1/2), Ry =in equation
theory through the above analysis, we are getting closer to real life Accelerometer. Value RX, RY, RZ is actually a linear relationship between the x-axis corresponds to the true reality of the y-axis accelerometer z-axis.
In this present a problem, accelerometer how that information tell us? Currently the market scored accelerometer output region from two types of digital, analog and the other is
to use the MPU6050 .miniAHRS three-axis accelerometer, the sensor is a digital I2C interface may be configured by specific commands acceleration range, and the internal ADC conversion result read out.
Now, we have our reading of the accelerometer, in LSB's, it's still not g (9.8 m / s ^ 2), require the final conversion, we need to know accelerometer sensitivity, usually expressed in LSB / g. When we say 2g of the selected range, corresponding to the sensitivity = 16384 LSB / G. In order to obtain the final force values, in units of g, we use the following formula:
the RX = ADCRx / sensitivity
. That is the x-axis when the count when ADCRx, then the corresponding value is the acceleration (ADCRx / 16384) g acceleration Back vector model, the angle on the associated symbol completion, as shown below
0.png

方向余弦
我们感兴趣的是向量R 和 X、Y、Z轴之间的角度,将它们定义为 Axr Ayr Azr. 可以看到
由R 和Rx 组成的直角三角形:
COS(Axr)= RX / R 依此类推:
COS(Ayr)= RY / R
COS(Azr)= RZ / R
可以得到 R = SQRT(RX ^ 2 + RY ^ 2 + RZ ^ 2) 我们发现 当使用 arccos() 反余弦 :
Axr = arccos(RX / R)
Ayr = arccos(RY / R)
Azr = arccos(RZ / R)
已以通过很多公式解释加速度计模型。我们也会很快解释陀螺仪 以及如何用加速度计和陀 螺仪的数据进行整合,以得到更精确的角度估计。
在这之前 我们先来看看更有用的公式: cosX = cos(Axr) = Rx / R
cosY = cos(Ayr) = Ry / R
cosZ = cos(Azr) = Rz / R
这三个公式通常被称为方向余弦。你可以轻松地验证: SQRT(cosX ^ 2 + COSY ^ 2 + cosZ ^ 2)= 1
这个属性可以避免监视R矢量的模(长度)。很多时候,我们只对惯性矢量方向感兴趣,对 矢量进行规范化对简化程序运算很有意义。

重力向量
我们暂且从理论分析回到现实的传感器输出中,当水平放置MPU6050,只有Z轴感受到重力向量,它将输出1g。对应的ADC值就是16384 (2g的量程)。此时,R就是重力向量,Rx=0. Ry=0. Rz = R =1g.满足 R ^ 2 = RX ^ 2 + RY ^ 2 + RZ ^ 2 得到重力向量与各个轴的夹角
Axr = arccos(RX / R) = 90度
Ayr = arccos(RY / R) = 90度
Azr = arccos(RZ / R) = 0 度

加速度计的标定
当MPU6050水平放置时,理论上Z轴感受到重力 将读出16384。同时X 轴和Y轴的读数将是0.可实际并不是这样的。这是由于每个芯片在制作时都不一样,数据手册上的都是理论的值,真正的芯片在水平时Z轴可能并不是16384.我们需要找到当各个轴在0g重力时的计数,
1g时的读数,以及-1g时的读数,得到一个补偿值,在每次读取ADC结果后都进行补偿。这个过程我们称之为标定。用数学公式表示为:
ADCx = K*Gx + Offset
ADCx 传感器输出
Gx 真实的加速值
Offset 加速度为0g时传感器的输出
K 标度因数

陀螺仪
陀螺仪是测试角速度的传感器,也有人把角速度说成角速率,说的是一样的物理量。拿电机做例子,当我们说一个电机10转每秒。一转是360度,那么它的主轴在一秒内转过3600度。也就是说这个电机在转动时的角速度是3600dps.dps 就是dergee per second 度每秒(或者写成 deg/s).
MPU6050 集成了三轴的陀螺仪.角速度全格感测范围为±250、±500、±1000与±2000°/sec (dps).当选择量程为±250dps的时候,将会得到分辩率为131LSB/(º/s).也就是当载体在X+轴转动1dps时,ADC将输出131.
0.png
回到加速度向量模型,将相关角度符号补上,如下图
0.png

陀螺仪测量什么?
MPU6050带有三个陀螺仪,每个陀螺仪各自负责检测相应轴的转动速度,也就是检测围绕各个轴转动的速度。像三轴的陀螺仪将同时检测 X Y Z轴的旋转。 由上面这个模型图,首先我们定义: Rxz - 是R向量在XZ平面上的投影 Ryz - 是R向量在XY平面上的投影 Rxz和Rz所形成的直角三角形,利用勾股定理,我们得到: Rxz ^ 2 = RX ^ 2 + RZ ^ 2,和同样: Ryz ^ 2 = RY ^ 2 + RZ ^ 2
还要注意的是:
R ^ 2 = RXZ ^ 2 + Ry^ 2,这可以来自从公式1和上面的等式,或它可以是来自于由R和Ryz
R ^ 2 = Ryz ^ 2 + Rx^ 2 形成的直角三角我们不会在本文中使用这些公式,只是让读者认识到所有值之间的关系。 同时我们将定义Z轴和Rxz 、RyZ之间的夹角。 Axz - Rxz和Z轴间的夹角 Ayz - Ryz和Z轴间的夹角 现在看看,从这个模型中,陀螺仪测量什么?
上述的说明,已经知道陀螺仪测量角度的变化率.为了解释这一点,让我们假设,我们已经 测量围绕Y轴的旋转角(这将是Axz角)在时刻t0,我们将其定义为Axz0,接下来,我们测 量这个角度是在稍后的时间t1是Axz1。变化率将被计算如下:
RateAxz =(Axz1 - Axz0)/(t1 - t0)
如果Axz单位是度,并以秒为时间单位,那么RateAxz将以deg / s表示。
MPU6050并不会以 deg / s 单位输出,我们需要在读完后进行转换。先来看看各个量程对 应的灵敏度。
0.png

从ADC值到 dps
通过I2C接口读出来的转换结果ADC值,并不是以度每秒为单位。一般按以下公式进行转换:
Anglerate = ADCrate /灵敏度
以量程为±1000º/s为例,说明如何转换。假设读取x轴的ADC值为200,从上表中得知在±1000º/s下的灵敏度为32.8LSB/(º/s) 。根据上面的公式:
Anglerate = 200/32.8 = 6.09756º/s
这就是说,MPU6050检测到模块正在以约6度每秒的速度绕X轴(或者叫在YZ平面上)旋转.
ADC值并不都是正的,请注意,当出现负数时,意味着该设备从现有的正方向相反的方向旋转.

磁力计
通过上面的介绍,读者对加速度和陀螺仪已经有一个认识了。
1.陀螺仪的强项在于测量设备自身的旋转运动。对设备自身运动更擅长。但不能确定设备的方位。
2.加速计的强项在于测量设备的受力情况。对设备相对外部参考物(比如,地面)的运动更擅长。
那么 为什么所有的AHRS模块都带有一个三轴的磁力计呢?磁力计是做什么用的?
首先,AHRS 全称为姿态航向参考系统,加速度和陀螺只能提供姿态参考,并不能解算出正确的航向。而磁力计是用于感受地磁向量以解算出模块与北的夹角。磁力计的这个功能类似 于指南针,所以也叫电子指南针,或者称为电子磁罗盘。 为了认识这个传感器,重新认识一下指南针。
0.png

从指南针开始
指南针是用以测定方向基准的仪器。其主要组成部分是一根装在轴上可以自由转动的磁 针。指南针之所以能够指示方向,是因为地球本身存在磁场,磁针在地磁场作用下能保持在 磁子午线的切线方向上。磁针的N极指向地磁的南极,利用这一性能可以辨别方向。常用于 航海、大地测量、旅行及军事等方面。 指南针是用以测定方向基准的仪器。其主要组成部分是一根装在轴上可以自由转动的磁 针。指南针之所以能够指示方向,是因为地球本身存在磁场,磁针在地磁场作用下能保持在 磁子午线的切线方向上。磁针的N极指向地磁的南极,利用这一性能可以辨别方向。常用于 航海、大地测量、旅行及军事等方面。
0.png

霍尔传感器
霍尔传感器是根据霍尔效应制作的一种磁场传感器。霍尔效应是磁电效应的一种,这一现 象是霍尔(A.H.Hall,1855—1938)于1879年在研究金属的导电机构时发现的.
在半导体薄片两端通以控制电流I,并在薄片的垂直方向施加磁感应强度为B的匀强磁场,则在垂直于电流和磁场的方向上,将产生电势差为VH的霍尔电压.
霍尔效应的典型应用就是霍尔开关,它由稳压器、霍尔元件、差分放大器,斯密特触发器和输出级组成,它输出数字量。常常用于检测发动机转速和产生点火信号,等等 在这里说霍尔效应 是证明磁场是存在的,也是可以被检测到的.
磁力计与霍尔传感器是有差别的,前者是用于检测微量的磁场,大地磁场约在0.3-0.6高斯,如此微弱的磁力,我们需要借助惠斯通电桥来检测,
0.png

磁力计的惠斯通电桥
如上图所示。R1/R2/R3/R4是初始状态相同的AMR电阻,但是R1/R2和R3/R4具有相反的磁化特性。当检测到外界正交偏置磁场的时候,R1/R2阻值增加∆R而R3/R4减少∆R。这样在没有外界正交偏置磁场的情况下,电桥的输出为零;而在有外界磁场时电桥的输出为一个微小的电压∆V。磁力计就是利用惠斯通电桥检测AMR阻值的变化,来感觉外部的磁力.当然这里的∆V很小,需要进入放大电路处理。
在些解释一下电桥的关键部件AMR电阻,也叫各向异性磁电阻效应,简称磁控电阻.当外部的 磁力线垂直于电阻时与外部磁力线平行于电阻时呈现不一样的电阻率.
HMC5883是三轴的磁力计,当然它内部有三个电桥.将三维磁阻传感器按照载体三维坐标系安装,通过测量载体空间磁场的三维磁感应强度,按照一定的算法就可以计算出载体在空间 的姿态信息。 这就是电子指南针.

磁干扰
这个世界上不是只有地球才能产生磁场,我们身边很多的物体都是可以产生磁场的,比如磁 铁,电机,钢筋构建的楼房,通电流的直导线也会产生磁场.
我们可以做这样的实验,找个指南针,当用磁铁靠近指南针时,它指示的方向会发生变化,此 时它再不能用做指南针给我们导航.因为它受到外界磁力干扰,指示的方向已经不能保证正确 了.这样的现象,我们称之为磁干扰.
电子指南针主要是通过感知地球磁场的存在来计算磁北极的方向。然而由于地球磁场在一 般情况下只有微弱的0.5高斯左右,而一个普通的手机喇叭当相距2厘米时仍会有大约4高斯 的磁场,一个手机马达在相距2厘米时会有大约6高斯的磁场,这一特点使得针对电子设备表 面地球磁场的测量很容易受到电子设备本身的干扰。 磁场干扰是指由于具有磁性物质或者可以影响局部磁场强度的物质存在,使得磁传感器所 放置位置上的地球磁场发生了偏差。 磁干扰又分成两种,一种是硬磁干扰,另一个是软磁干扰.
硬铁磁场由磁力计平台(可认为是载体)上的永久性磁铁和被磁化的钢铁物质组成,其特点 是当载体位于某一固定位置时,其强度为一定值,不随航向的变化而变化.软铁磁场可认为 由地球磁场与磁力计周围的磁化物质相互作用而产生。与硬铁磁场不同的是,软铁磁场强度 的大小与方向与磁力计的方位有关.

Magnetic calibration
by environmental factors and electronic magnetic compass itself factors, often there is a large electronic magnetic compass heading angle error, and therefore often need to calibrate before use. General Procedure magnetic compass calibration vectors is to make magnetic compass mounted particular motion, or to a specific carrier rotation angle, the magnetic field strength measurements obtained at different magnetic compass attitude. By analyzing the measured values, the magnetic compass calibration
plane calibration method for calibrating the XY axes, equipped with a magnetic sensor device, respectively, the rotation in the XY plane, the Earth's magnetic field vector corresponding to the point around through O (γx, γy) XY plane perpendicular to the normal rotation, and the red circles represent the magnetic field vector during rotation in the XY plane projected trajectory. This can be found in the center position ((Xmax + Xmin) / 2 , (Ymax + Ymin) / 2).

Guess you like

Origin blog.csdn.net/qq_27251141/article/details/90166733