HMC5883L校准
HMC5883L 磁力计校准
(2015-02-14 11:48:21)
标签:
hmc5883磁力计校准 |
分类: 电子技术 |
这里针对 HMC5883L 磁力计 的校准,做一个简单讲解。欢迎交流,新浪长沙@WalkAnt。
先看看这篇文章:http://blog.sina.com.cn/s/blog_8240cbef0101i7gn.html
如果磁力计在含有附加的局部磁场的环境中进行操作,磁力计的输出做附加的修正将是必要的。 在没有任何本地磁场的影响下,下图1可以通过旋转设备360°产生的平面 ,图2为引入本地磁场。
关于为什么设置偏置,请参考以下文章:
ST集成传感器方案实现电子罗盘功能:http://www.dzsc.com/data/html/2010-11-29/87454.html
HMC5883L常见问题解答:http://blog.sina.com.cn/s/blog_402c071e0102v8gj.html
这里我采用了上方的简单方法,来计算一个 offsetX, offsetY, offsetZ,然后减去这个偏移量,得到了正确的结果。下方是代码。下方我做了一个处理(诸如:mag.x*0.2 + magRange[0]*0.8)。是因为偶尔mag.x mag.y mag.z 会出现一个异常的值,使得计算的offsetX offsetY offsetZ不准,所以加了这个滤波处理。
static float magRange[6] = {1.0,-1.0,1.0,-1.0,1.0,-1.0};// magRange[0] 对应X最小,magRange[1] 对应X最大
// Magnetometer not yet used more then for logging.
// 磁力计尚未使用到,仅仅只是 log 记录下来。
imu9Read(&gyro, &acc, &mag);
if(magRange[0] > mag.x) magRange[0] = mag.x*0.2 + magRange[0]*0.8; // x min
if(magRange[1] < mag.x) magRange[1] = mag.x*0.2 + magRange[1]*0.8; // x max
if(magRange[2] > mag.y) magRange[2] = mag.y*0.2 + magRange[2]*0.8;
if(magRange[3] < mag.y) magRange[3] = mag.y*0.2 + magRange[3]*0.8;
if(magRange[4] > mag.z) magRange[4] = mag.z*0.2 + magRange[4]*0.8; // z min
if(magRange[5] < mag.z) magRange[5] = mag.z*0.2 + magRange[5]*0.8; // z max
magOffset[0] = (magRange[0]+magRange[1])/2.0;
magOffset[1] = (magRange[2]+magRange[3])/2.0;
magOffset[2] = (magRange[4]+magRange[5])/2.0;
mag.x -= magOffset[0];
mag.y -= magOffset[1];
mag.z -= magOffset[2];
自我检测也比较重要。通过HMC5883l芯片提供的自我检测功能,进行自我检测,然后找到一个比例因子。将传感器的检测值乘以这个比例因子,就可以修正磁场。我在代码中没有使用。相关的详细资料请看如下英文。
相关源代码,可以参考 Crazyflie firmware中的 bool hmc5883lSelfTest() 函数。
自我检测
SELF TEST OPERATION
To check the HMC5883L for proper operation, a self test feature in incorporated in which the sensor offset straps are excited to create a nominal field strength (bias field) to be measured. To implement self test, the least significant bits (MS1 and MS0) of configuration register A are changed from 00 to 01 (positive bias) or 10 (negetive bias), e.g. 0x11 or 0x12.
Then, by placing the mode register into single-measurement mode (0x01), two data acquisition cycles will be made on each magnetic vector. The first acquisition will be a set pulse followed shortly by measurement data of the external field. The second acquisition will have the offset strap excited (about 10 mA) in the positive bias mode for X, Y, and Z axes to create about a ±1.1 gauss self test field plus the external field. The first acquisition values will be subtracted from the second acquisition, and the net measurement will be placed into the data output registers.
Since self test adds ~1.1 Gauss additional field to the existing field strength, using a reduced gain setting prevents sensor from being saturated and data registers overflowed. For example, if the configuration register B is set to 0x60 (Gain=3), values around +766 LSB (1.16 Ga * 660 LSB/Ga) will be placed in the X and Y data output registers and around +713 (1.08 Ga * 660 LSB/Ga) will be placed in Z data output register. To leave the self test mode, change MS1 and MS0 bit of the configuration register A back to 00 (Normal Measurement Mode), e.g. 0x10.
比例因子校准
SCALE FACTOR CALIBRATION
Using the self test method described above, the user can scale sensors’ sensitivity to match each other. Since placing device in positive bias mode (or alternatively negative bias mode) applies a known artificial field on all three axes, the resulting ADC measurements in data output registers can be used to scale the sensors. For example, if the expected self test value for X-axis is 766 and the actual value is 750 then a scale factor of (766/750) should be multiplied to all future readings of X-axis. Doing so for all three axes will ensure their sensitivity are well matched.
The built-in self test can also be used to periodically compensate the scaling errors due to temperature variations. A compensation factor can be found by comparing the self test outputs with the ones obtained at a known temperature. For example, if the self test output is 750 at room temperature and 700 at the current temperature then a compensation factor of (750/700) should be applied to all current magnetic readings. A temperature sensor is not required using this method.
Crazyflie firmware中的 bool hmc5883lSelfTest() 函数代码如下,仅供参考:(函数中的各种定义这里未给出)
bool hmc5883lSelfTest()
{
bool testStatus = TRUE;
int16_t mxp, myp, mzp; // positive magnetometer measurements
int16_t mxn, myn, mzn; // negative magnetometer measurements
struct
{
uint8_t configA;
uint8_t configB;
uint8_t mode;
} regSave;
// Save register values
if (i2cdevRead(I2Cx, devAddr, HMC5883L_RA_CONFIG_A, sizeof(regSave), (uint8_t *)®Save) == FALSE)
{
// TODO: error handling
return FALSE;
}
// Set gain (sensitivity)
hmc5883lSetGain(HMC5883L_ST_GAIN);
// Write CONFIG_A register and do positive test
i2cdevWriteByte(I2Cx, devAddr, HMC5883L_RA_CONFIG_A,
(HMC5883L_AVERAGING_1 << (HMC5883L_CRA_AVERAGE_BIT - HMC5883L_CRA_AVERAGE_LENGTH + 1)) |
(HMC5883L_RATE_15 << (HMC5883L_CRA_RATE_BIT - HMC5883L_CRA_RATE_LENGTH + 1)) |
(HMC5883L_BIAS_POSITIVE << (HMC5883L_CRA_BIAS_BIT - HMC5883L_CRA_BIAS_LENGTH + 1)));
hmc5883lSetMode(HMC5883L_MODE_SINGLE);
vTaskDelay(M2T(HMC5883L_ST_DELAY_MS));
hmc5883lGetHeading(&mxp, &myp, &mzp);
// Write CONFIG_A register and do negative test
i2cdevWriteByte(I2Cx, devAddr, HMC5883L_RA_CONFIG_A,
(HMC5883L_AVERAGING_1 << (HMC5883L_CRA_AVERAGE_BIT - HMC5883L_CRA_AVERAGE_LENGTH + 1)) |
(HMC5883L_RATE_15 << (HMC5883L_CRA_RATE_BIT - HMC5883L_CRA_RATE_LENGTH + 1)) |
(HMC5883L_BIAS_NEGATIVE << (HMC5883L_CRA_BIAS_BIT - HMC5883L_CRA_BIAS_LENGTH + 1)));
hmc5883lSetMode(HMC5883L_MODE_SINGLE);
vTaskDelay(M2T(HMC5883L_ST_DELAY_MS));
hmc5883lGetHeading(&mxn, &myn, &mzn);
if (hmc5883lEvaluateSelfTest(HMC5883L_ST_X_MIN, HMC5883L_ST_X_MAX, mxp, "pos X") &&
hmc5883lEvaluateSelfTest(HMC5883L_ST_Y_MIN, HMC5883L_ST_Y_MAX, myp, "pos Y") &&
hmc5883lEvaluateSelfTest(HMC5883L_ST_Z_MIN, HMC5883L_ST_Z_MAX, mzp, "pos Z") &&
hmc5883lEvaluateSelfTest(-HMC5883L_ST_X_MAX, -HMC5883L_ST_X_MIN, mxn, "neg X") &&
hmc5883lEvaluateSelfTest(-HMC5883L_ST_Y_MAX, -HMC5883L_ST_Y_MIN, myn, "neg Y") &&
hmc5883lEvaluateSelfTest(-HMC5883L_ST_Z_MAX, -HMC5883L_ST_Z_MIN, mzn, "neg Z"))
{
DEBUG_PRINT("Self test [OK].\n");
}
else
{
testStatus = FALSE;
}
// Restore registers
if (i2cdevWrite(I2Cx, devAddr, HMC5883L_RA_CONFIG_A, sizeof(regSave), (uint8_t *)®Save) == FALSE)
{
// TODO: error handling
return FALSE;
}
return testStatus;
}
HMC5883L校准相关推荐
- HMC5883L常见问题解答
HMC5883L常见问题解答:本文来源于百度文库: http://wenku.baidu.com/link?url=eDNpt5pwY5nzmez2HfAgFNg7il5rZKVKpywKcF8F9f ...
- HMC5883L磁力计常见问题解答
原文地址:http://blog.sina.com.cn/s/blog_402c071e0102v8gj.html 本文提供了 HMC5883L 磁力计 的 常见问题的解答,本文来自百度文库,欢迎交流 ...
- 【51单片机快速入门指南】4.4:I2C 读取HMC5883L / QMC5883L 磁力计
目录 硬知识 简介 操作模式 HMC5883L 连续测量模式 单次测量模式 闲置模式 QMC5883L 连续测量模式 待命模式 主要差异 寄存器 寄存器列表 HMC5883L QMC5883L 配置寄 ...
- HMC5883L 电子指南针
电子指南针也称为电子罗盘,是一种重要的导航工具,能实时提供移动物体的航向和姿态.随着半导体工艺的进步和手机操作系统的发展,集成了越来越多传感器的智能手机变得功能强大,很多手机上都实现了电子罗盘的功能. ...
- HMC5883L地磁传感器驱动
霍尼韦尔 HMC5883L 是一种表面贴装的高集成模块,并带有数字接口的弱磁传感器芯片,应用于低成本罗盘和磁场检测领域.HMC5883L 包括最先进的高分辨率 HMC118X 系列磁阻传感器,并附带霍 ...
- 3轴数字罗盘IC HMC5883L介绍
3轴数字罗盘IC HMC5883L简介 霍尼韦尔 HMC5883L 是一种表面贴装的高集成模块,并带有数字接口的弱磁传感器芯片,应用于低成本罗盘和磁场检测领域.HMC5883L 包括最先进的高分辨率H ...
- HMC5883Lnbsp;磁力计校准
原文地址:HMC5883L 磁力计校准作者:WalkAnt 这里针对 HMC5883L 磁力计 的校准,做一个简单讲解.欢迎交流,新浪长沙@WalkAnt. 先看看这篇文章:http://blog.s ...
- MPU6050 6轴陀螺仪的使用与校准
1 MPU6050初始化 ①初始化IIC接口. ②初始化MPU6050.由电源管理寄存器1(0X6B)控制. ③设置角速度传感器和加速度传感器的满量程范围.由陀螺仪配置寄存器(0X1B)和加速度传感器 ...
- HMC5883L读取数据代码分享
文章目录 前言 一.硬件.软件准备 二.代码内容 1.寄存器地址的宏定义 2.IIC功能实现函数 3.寄存器A,B与模式寄存器配置(初始化) 4.读取xyz寄存器中的数据 三.总结 前言 最近初入门学 ...
- LabVIEW机器视觉系统图像畸变、校准和矫正(基础篇—3)
目录 1.图像畸变 1.1.图像畸变的原因 1.2.图像畸变类型 1.2.1.透视畸变 1.2.2.径向畸变 1.2.3.切向畸变 1.2.4.灰度不均 2.图像校准 2.1.简易系统校准法和透视校准 ...
最新文章
- linux执行命令段错误,Linux运行fortran程序 出现段错误(segmentation fault)
- 编程成长日记——有意思的编程题(二)
- CTFshow 反序列化 web263
- how you can do to make girls more close to you?
- 【Sikuli】Sikuli 文档
- Springboot2 Quartz实现JAVA定时任务的动态配置
- 使用mprotect系统调用来调试内存问题:memalign,aligned_alloc
- 基于Open vSwitch搭建虚拟路由器
- 怎样用MATLAB画二次函数曲线,matlab画二次函数图像
- 【HBase 进阶】-- Region 过多的影响 合理分区数量
- Spark MLlib矩阵分解源码分析
- 【一级讲解】不可思议唤来不可思议β——数学排列组合
- MATLAB实现图像灰度直方图
- java验证11位手机号_JAVA怎样用数组实现输入手机号码为11位
- Anlin-chat多功能聊天室php源码下载,极速安装
- Java面试锦囊(五)
- Linux学习笔记2(root密码忘记重置,Linux系统更新yum源,YUM安装卸载,常见故障排除,vim,用户/组)
- JAVA后端开发面试经典
- iOS 第三方登录(QQ 微信 新浪微博)
- JS数组定义,遍历,判断是否是数组
热门文章
- php创建对象出问题,activex部件不能创建对象
- mysql codesmith_CodeSmith MySql
- 基于ASP.NET的网络购物系统设计与实现
- MyEclipse10破解,亲测实用
- 中职计算机组装与维护实训教案,《计算机组装与维护》——计算机组装与维修的基础知识教学教案(中职教育)...
- 密码编码学与网络安全笔记(第7版)
- sqlserver2016转sqlserver2008
- MDIO总线简单介绍
- 3t硬盘 xp_华硕Disk Unlocker
- 3d3s9.0硬件复制狗