hmc5883l校准的测量车位怎样提高精度

21ic官方微信
后使用快捷导航没有帐号?
查看: 1532|回复: 4
我用stm32(硬件IIC)读取MPU6050的从机HMC5883L的数据为什么不发生变化呢
&&未结帖(20)
主题帖子积分
实习生, 积分 9, 距离下一级还需 41 积分
实习生, 积分 9, 距离下一级还需 41 积分
主题帖子积分
专家等级:结帖率:0%
主题帖子积分
实习生, 积分 9, 距离下一级还需 41 积分
实习生, 积分 9, 距离下一级还需 41 积分
我设置了HMC5993L的连续测量模式,然后通过mpu6050上的EXT_SENS_DATA来得到传感器的六个数据,然后用串口把数据发回电脑查看,但是数据只有一组,转动芯片也不会发生变化,掉电重新连接之后才会看到另外的一组数据,请问这是为什么呢?谢谢!
主题帖子积分
---------------------
主题帖子积分
---------------------
专家等级:结帖率:100%打赏:0.00受赏:40.00
主题帖子积分
---------------------
可能是 I2C 的问题, 也可能是你的串口把数据发回电脑查看的程序的问题.
欢迎进入 !
主题帖子积分
实习生, 积分 9, 距离下一级还需 41 积分
实习生, 积分 9, 距离下一级还需 41 积分
主题帖子积分
专家等级:结帖率:0%
主题帖子积分
实习生, 积分 9, 距离下一级还需 41 积分
实习生, 积分 9, 距离下一级还需 41 积分
可能是 I2C 的问题, 也可能是你的串口把数据发回电脑查看的程序的问题.
应该不会,我还读取了其他六轴的数据,都是正常的,只有这个不对头
主题帖子积分
实习生, 积分 9, 距离下一级还需 41 积分
实习生, 积分 9, 距离下一级还需 41 积分
主题帖子积分
专家等级:结帖率:0%
主题帖子积分
实习生, 积分 9, 距离下一级还需 41 积分
实习生, 积分 9, 距离下一级还需 41 积分
应该不会,我还读取了其他六轴的数据,都是正常的,只有这个不对头
问一下&&HMC5883L的DRDY引脚是用来干嘛的,需要用吗
主题帖子积分
助理工程师, 积分 1627, 距离下一级还需 373 积分
助理工程师, 积分 1627, 距离下一级还需 373 积分
主题帖子积分
专家等级:结帖率:100%
主题帖子积分
助理工程师, 积分 1627, 距离下一级还需 373 积分
助理工程师, 积分 1627, 距离下一级还需 373 积分
可以用虚拟示波器看看有波形吗
荣誉元老奖章
等级类勋章
坚毅之洋流
发帖类勋章
时间类勋章
技术领袖奖章
人才类勋章查看: 63405|回复: 111
注册时间最后登录阅读权限150积分3105精华26帖子
Arduino连接HMC5883L三轴电子罗盘传感器
用途:测量地磁方向,测量物体静止时候的方向,测量传感器周围磁力线的方向。注意,测量地磁时候容易受到周围磁场影响,
主芯片HMC5883三轴磁阻传感器特点(抄自网上):
1,数字量输出:I2C数字量输出接口,设计使用非常方便。
2,尺寸小: 3x3x0.9mm LCC封装,适合大规模量产使用。
3,精度高:1-2度,内置12位A/D,OFFSET, SET/RESET 电路,不会出现磁饱和现象,不会有累加误差。
4,支持自动校准程序,简化使用步骤,终端产品使用非常方便。
5,内置自测试电路,方便量产测试,无需增加额外昂贵的测试设备。
6,功耗低:供电电压1.8V, 功耗睡眠模式-2.5uA 测量模式-0.6mA
20:55 上传
连接方法:
只要连接VCC,GND,SDA,SCL四条线。Arduino GND -& HMC5883L GNDArduino 3.3V -& HMC5883L VCCArduino A4 (SDA) -& HMC5883L SDAArduino A5 (SCL) -& HMC5883L SCL
(注意,接线是A4,A5,不是D4,D5)
程序编写:下载HMC5883L库文件。下载地址:解压HMC5883L库文件到arduino文件夹:arduino-0022\libraries下面。编写以下程序,下载下面测试程序到arduino:
#include &Wire.h&
#include &HMC5883L.h&
void setup()
&&Serial.begin(9600);
&&Wire.begin();
&&compass = HMC5883L();
&&compass.SetScale(1.3);
&&compass.SetMeasurementMode(Measurement_Continuous);
void loop()
&&MagnetometerRaw raw = compass.ReadRawAxis();
&&MagnetometerScaled scaled = compass.ReadScaledAxis();
&&float xHeading = atan2(scaled.YAxis, scaled.XAxis);
&&float yHeading = atan2(scaled.ZAxis, scaled.XAxis);
&&float zHeading = atan2(scaled.ZAxis, scaled.YAxis);
&&if(xHeading & 0) xHeading += 2*PI;
&&if(xHeading & 2*PI) xHeading -= 2*PI;
&&if(yHeading & 0) yHeading += 2*PI;
&&if(yHeading & 2*PI) yHeading -= 2*PI;
&&if(zHeading & 0) zHeading += 2*PI;
&&if(zHeading & 2*PI) zHeading -= 2*PI;
&&float xDegrees = xHeading * 180/M_PI;
&&float yDegrees = yHeading * 180/M_PI;
&&float zDegrees = zHeading * 180/M_PI;
&&Serial.print(xDegrees);
&&Serial.print(&,&);
&&Serial.print(yDegrees);
&&Serial.print(&,&);
&&Serial.print(zDegrees);
&&Serial.println(&;&);
&&delay(100);
打开Arduino串口监视器即可看到结果(X平面角度,Y平面角度,Z平面角度):
21:06 上传
(5.55 KB, 下载次数: 2383)
20:30 上传
点击文件名下载附件
总评分:&金币 + 3&
注册时间最后登录阅读权限10积分26精华0帖子
新手上路, 积分 26, 距离下一级还需 24 积分
LZ好啊,我想问问如果我用的是HMC5843 ,应该还是一样的吧,就稍微改改就好了。。。
还有就是& &if(xHeading & 0) xHeading += 2*PI;
&&if(xHeading & 2*PI) xHeading -= 2*PI;
&&if(yHeading & 0) yHeading += 2*PI;
&&if(yHeading & 2*PI) yHeading -= 2*PI;
&&if(zHeading & 0) zHeading += 2*PI;
&&if(zHeading & 2*PI) zHeading -= 2*PI;
这一段是不是把,x,y,z局限于一定的范围呢。。。。新人,求指教。。。多些LZ了
&楼上正解&
&是的,其实就是将负数和超过360度的,转换回0~360°而已&
注册时间最后登录阅读权限10积分26精华0帖子
新手上路, 积分 26, 距离下一级还需 24 积分
本帖最后由 ck59505 于
15:43 编辑
ck59505 发表于
LZ好啊,我想问问如果我用的是HMC5843 ,应该还是一样的吧,就稍微改改就好了。。。
还有就是& &if(xHea ...
哦,谢谢啦,还有我弱弱的问问。。。PI表示的是Arduino从传感器的来的数据吗,随着物体的移动,传来的PI值就不相同
额。。还是说是 π。。。
注册时间最后登录阅读权限50积分858精华5帖子
RedDot Winner
高级会员, 积分 858, 距离下一级还需 142 积分
ck59505 发表于
哦,谢谢啦,还有我弱弱的问问。。。PI表示的是Arduino从传感器的来的数据吗,随着物体的移动,传来的P ...
PI是圆周率,其实这个库文件已经把能做的都做了,直接读就行,这一大坨代码无非是变变数据的格式
用足迹 丈量天涯
注册时间最后登录阅读权限90积分4717精华11帖子
论坛元老, 积分 4717, 距离下一级还需 9995282 积分
好东西,但是不知道这些数字是怎么分析的呢?
注册时间最后登录阅读权限50积分521精华1帖子
高级会员, 积分 521, 距离下一级还需 479 积分
16:14 上传
试问一下上面的模块和你使用的模块有什么区别吗?因为上面只有4个接口,而且没有针脚,要自己焊接挺麻烦的。
注册时间最后登录阅读权限150积分9685精华10帖子
树·水·风 发表于
试问一下上面的模块和你使用的模块有什么区别吗?因为上面只有4个接口,而且没有针脚,要自己焊接挺麻烦的 ...
这种模块,只能3.3V供电,没有上拉电阻,所以连接arduino板子,上拉电阻需要手工接。其他没区别
注册时间最后登录阅读权限50积分521精华1帖子
高级会员, 积分 521, 距离下一级还需 479 积分
弘毅 发表于
这种模块,只能3.3V供电,没有上拉电阻,所以连接arduino板子,上拉电阻需要手工接。其他没区别
哦,谢谢。我在淘宝上搜,有引脚的要贵很多,自己又没有焊接的经验,有点囧啊
注册时间最后登录阅读权限90积分4717精华11帖子
论坛元老, 积分 4717, 距离下一级还需 9995282 积分
本帖最后由 Randy 于
11:49 编辑
最近在玩这个东西,刚刚测试了一下。我也来提供一下测出地磁场角度的程序!/*
HMC5883L_Example.pde - Example sketch for integration with an HMC5883L triple axis magnetomerwe.
Copyright (C) 2011 Love Electronics (loveelectronics.co.uk)
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&&See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.&&If not, see &http://www.gnu.org/licenses/&.
// Reference the I2C Library
#include &Wire.h&
// Reference the HMC5883L Compass Library
#include &HMC5883L.h&
// Store our compass as a variable.
HMC5883L
// Record any errors that may occur in the compass.
int error = 0;
// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
&&// Initialize the serial port.
&&Serial.begin(9600);
&&Serial.println(&Starting the I2C interface.&);
&&Wire.begin(); // Start the I2C interface.
&&Serial.println(&Constructing new HMC5883L&);
&&compass = HMC5883L(); // Construct a new HMC5883 compass.
& &
&&Serial.println(&Setting scale to +/- 1.3 Ga&);
&&error = compass.SetScale(1.3); // Set the scale of the compass.
&&if(error != 0) // If there is an error, print it out.
& & Serial.println(compass.GetErrorText(error));
&&
&&Serial.println(&Setting measurement mode to continous.&);
&&error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
&&if(error != 0) // If there is an error, print it out.
& & Serial.println(compass.GetErrorText(error));
}
// Our main program loop.
void loop()
{
&&// Retrive the raw values from the compass (not scaled).
&&MagnetometerRaw raw = compass.ReadRawAxis();
&&// Retrived the scaled values from the compass (scaled to the configured scale).
&&MagnetometerScaled scaled = compass.ReadScaledAxis();
&&
&&// Values are accessed like so:
&&int MilliGauss_OnThe_XAxis = scaled.XA// (or YAxis, or ZAxis)
&&// Calculate heading when the magnetometer is level, then correct for signs of axis.
&&float heading = atan2(scaled.YAxis, scaled.XAxis);
&&
&&// Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
&&// Find yours here: http://www./
&&// Mine is: 2� 37' W, which is 2.617 Degrees, or (which we need) 0. radians, I will use 0.0457
&&// If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
&&float declinationAngle = 0.0457;
&&heading += declinationA
&&
&&// Correct for when signs are reversed.
&&if(heading & 0)
& & heading += 2*PI;
& &
&&// Check for wrap due to addition of declination.
&&if(heading & 2*PI)
& & heading -= 2*PI;
& &
&&// Convert radians to degrees for readability.
&&float headingDegrees = heading * 180/M_PI;
&&// Output the data via the serial port.
&&Output(raw, scaled, heading, headingDegrees);
&&// Normally we would delay the application by 66ms to allow the loop
&&// to run at 15Hz (default bandwidth for the HMC5883L).
&&// However since we have a long serial out (104ms at 9600) we will let
&&// it run at its natural speed.
&&// delay(66);
}
// Output the data down the serial port.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
{
& &Serial.print(&Raw:\t&);
& &Serial.print(raw.XAxis);
& &Serial.print(&& &&);& &
& &Serial.print(raw.YAxis);
& &Serial.print(&& &&);& &
& &Serial.print(raw.ZAxis);
& &Serial.print(&& &\tScaled:\t&);
& &
& &Serial.print(scaled.XAxis);
& &Serial.print(&& &&);& &
& &Serial.print(scaled.YAxis);
& &Serial.print(&& &&);& &
& &Serial.print(scaled.ZAxis);
& &Serial.print(&& &\tHeading:\t&);
& &Serial.print(heading);
& &Serial.print(& Radians& &\t&);
& &Serial.print(headingDegrees);
& &Serial.println(& Degrees& &\t&);
}复制代码结果是这样的,问了HEAVEN的意思!
11:36 上传
下面我又测了另外一个的结果,感觉奇怪,楼主懂什么原因?
11:49 上传
&这个做法太简单了,没有考虑磁场传感器的零偏,以及姿态的影响。只能说,能指示出东南西北,要说指向精度就谈不上了。&
解释不错,哈哈
总评分:&威望 + 30&
深圳市博励教育,专注于高速PCB设计培训,需要请联系:QQ:
注册时间最后登录阅读权限90积分4717精华11帖子
论坛元老, 积分 4717, 距离下一级还需 9995282 积分
树·水·风 发表于
哦,谢谢。我在淘宝上搜,有引脚的要贵很多,自己又没有焊接的经验,有点囧啊
焊接这几个针非常的简单,慢慢来!
Powered by&&&&HMC5883L模块资料
HMC5883L模块资料
3轴数字罗盘IC Honeywell
霍尼韦尔 HMC5883L 是一种表面贴装的高集成模块,并带有数字接口的弱磁
传感器芯片,应用于低成本罗盘和磁场检测领域。HMC5883L 包括最先进的高
分辨率HMC118X 系列磁阻传感器,并附带霍尼韦尔专利的集成电路包括放大
器、自动消磁驱动器、偏差校准、能使罗盘精度控制在1°~2°的12 位模数
转换器.简易的I2C 系列总线接口。HMC5883L 是采用无铅表面封装技术,带
有16 引脚,尺寸为3.0X3.0X0.9mm。HMC5883L 的所应用领域有手机、笔记本
电脑、消费类电子、汽车导航系统和个人导航系统。
HMC5883L 采用霍尼韦尔各向异性磁阻(AMR)技术,该技术的优点是其他磁传感器技术所无法企及。这些各向
异性传感器具有在轴向高灵敏度和线性高精度的特点.传感器带有的对于正交轴低敏感行的固相结构能用于
测量地球磁场的方向和大小,其测量范围从毫高斯到 8 高斯(gauss)。 霍尼韦尔的磁传感器在低磁场传感
器行业中是灵敏度最高和可靠性最好的传感器。
? 三轴磁阻传感器和ASIC 都被封装在
3.0×3.0×0.9mm LCC 表面装配中
? 12-bit ADC 与低干扰AMR 传感器,能在
±8 高斯的磁场中实现5 毫高斯分辨率
? 内置自检功能
? 低 电压工作(2.16-3.6V) 和超低功耗
? 内置驱动电路
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
开发技术下载排行HMC5883L 电子指南针用树莓派进行磁场干扰过滤 校准
本文适合所有的电子指南针校准,不仅限于 HMC5883L.
硬件的连接和树莓派的搭建以后再写。
本文仅限于固定强度和方向磁场干扰的过滤,例如机器人自身其它设备产生的磁场。但对于环境如扩音器喇叭等磁场干扰无效.
首先进行X Y 方向的校准,将芯片平放固定到一个水平面,这时大地磁场是近似平行XY平面的,绕Z轴慢速的转动XY平面,电子指南针HMC5883L会测量出圆周内大地磁场的强度+固定干扰磁场。而固定磁场的强度就是所有测量值的平均值。
#!/usr/bin/python
import smbus
import time
import math
bus = smbus.SMBus(0)
address = 0x1e
def read_byte(adr):
return bus.read_byte_data(address, adr)
def read_word(adr):
high = bus.read_byte_data(address, adr)
low = bus.read_byte_data(address, adr+1)
val = (high <= 0x8000):
return -((65535 - val) + 1)
return val
def write_byte(adr, value):
bus.write_byte_data(address, adr, value)
write_byte(0, 0b) # Set to 8 samples @ 15Hz
write_byte(1, 0b) # 1.3 gain LSb / Gauss 1090 (default)
write_byte(2, 0b) # Continuous sampling
scale = 0.92
for i in range(0,500):
&#160;&#160;&#160; x_out = read_word_2c(3)
&#160;&#160;&#160; y_out = read_word_2c(7)
&#160;&#160;&#160; z_out = read_word_2c(5)
&#160;&#160;&#160;
&#160;&#160;&#160; bearing&#160; = math.atan2(y_out, x_out)
&#160;&#160;&#160; if (bearing < 0):
&#160;&#160;&#160;&#160;&#160;&#160;&#160; bearing += 2 * math.pi
&#160;&#160;&#160;
&#160;&#160;&#160; print x_out, y_out, (x_out * scale), (y_out * scale)
&#160;&#160;&#160; time.sleep(0.1)
运行上面的程序,在50秒内不停地旋转装有芯片的水平面,360度的缓慢旋转,一定要保证水平面稳定,否则会得到很多奇怪的干扰数据。
sudo ./compass-test.py > compass-plot.dat
将输出结果导入到compas-plot.dat文件里面。接下来我们用GNUPlot来看一下数据结果,以每对儿X Y为坐标的图形效果。
set terminal wxt persist size 800,800 background&#39;#;
set style line99 linecolor rgb "#ffffff" linetype 0 linewidth 2
set key topright textcolor linestyle 99
set gridlinestyle 99
set borderlinestyle 99
plot filenameusing 1:2 title "Raw compass values" linecolor rgb "green"
将上面命令文本保存到 gnuplot-compass.plg
并执行下面的命令,可以看到图形:
gnuplot -e "filename=&#39;compass-plot.dat&#39;"gnuplot-compass.plg
这时我们可以看到图形的圆心不是在 0,0 点vcD4KPHAgYWxpZ249"left">把上面程序的for循环内容更换成下面的代码,运行50秒不停地手动旋转水平面,
for i in range(0,500):
x_out = read_word_2c(3)
y_out = read_word_2c(7)
z_out = read_word_2c(5)
if x_out < minx:
minx=x_out
maxx=x_out
if y_out > maxy:
maxy=y_out
#print x_out, y_out, (x_out * scale), (y_out * scale)
time.sleep(0.1)
print "minx: ", minx
print "miny: ", miny
print "maxx: ", maxx
print "maxy: ", maxy
print "x offset: ", (maxx + minx) / 2
print "y offset: ", (maxy + miny) / 2
这一次会输出下面的&#20540;:
把输出的偏移加到程序当中,第一段程序的读取&#20540;的代码换成下面:
x_offset = -10
y_offset = 10
x_out = (read_word_2c(3) - x_offset) * scale
y_out = (read_word_2c(7) - y_offset) * scale
z_out = (read_word_2c(5)) * scale
Z 方向的校准同上面的方法,只是要把XZ平面固定到水平面上做同样的事情而已。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'&#xe621; 上传我的文档
&#xe602; 下载
&#xe60c; 收藏
该文档贡献者很忙,什么也没留下。
&#xe602; 下载此文档
正在努力加载中...
基于HMC5883L的停车位ZigBee数据采集系统
下载积分:797
内容提示:基于HMC5883L的停车位ZigBee数据采集系统
文档格式:PDF|
浏览次数:9|
上传日期: 13:09:09|
文档星级:&#xe60b;&#xe612;&#xe612;&#xe612;&#xe612;
该用户还上传了这些文档
基于HMC5883L的停车位ZigBee数据采集系统
官方公共微信

我要回帖

更多关于 hmc5883l磁力计校准 的文章

 

随机推荐