MPU9250,MPU6050芯片3D姿态PC上位机及Arduino下位机程序库
本帖最后由 seekyong 于 2015-3-4 21:01 编辑RTIMULib-Arduino now supports the InvenSense MPU-9250 9-dof IMU
这个是Arduino库文件,输出的就是算好的姿态!
此乃老夫的上位机,之前看过Mission Planner,看过MK-TOOL,本来想省事找接口用他们那上位机的姿态部分,太费脑筋。后来不如自己编一个,也不难,还入门了LABview。
本帖最后由 mc.six 于 2015-3-20 13:27 编辑
奇怪怎么会这样-----好了可能是线插得不好
请问能否实现多个mpu9250之间连接传输数据呢?我看到手册里写的有这种接口,想问一下,不知道有人成功过吗? 单个的我试成功了,数据稳定,现在在搞姿态软件,直接显示三维姿态在电脑上
输出为姿态融合算法:偏航角Yaw、俯仰角Pitch和滚动角Roll
由四元数求出的最终姿态角,其中Yaw为航向角,表示机头偏离正北方多少度,范围-180到+180
Pitch为俯仰角,表示机头正方向与水平线的夹角,范围-90到+90
Roll为翻滚角,表示机翼与水平线的夹角,范围:-180到+180 本帖最后由 seekyong 于 2015-3-4 20:59 编辑
注意:将压缩包中此文件seekyong.stl放入D盘根目录即可 ////////////////////////////////////////////////////////////////////////////
//
//This file is part of RTIMULib-Arduino
//
//Copyright (c) 2014, richards-tech
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of
//this software and associated documentation files (the "Software"), to deal in
//the Software without restriction, including without limitation the rights to use,
//copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
//Software, and to permit persons to whom the Software is furnished to do so,
//subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
//INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
//PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
//OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
//SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <Wire.h>
#include "I2Cdev.h"
#include "RTIMUSettings.h"
#include "RTIMU.h"
#include "RTFusionRTQF.h"
#include "CalLib.h"
#include <EEPROM.h>
RTIMU *imu; // the IMU object
RTFusionRTQF fusion; // the fusion object
RTIMUSettings settings; // the settings object
//DISPLAY_INTERVAL sets the rate at which results are displayed
#define DISPLAY_INTERVAL300 // interval between pose displays
//SERIAL_PORT_SPEED defines the speed to use for the debug serial port
#defineSERIAL_PORT_SPEED115200
unsigned long lastDisplay;
unsigned long lastRate;
int sampleCount;
void setup()
{
int errcode;
Serial.begin(SERIAL_PORT_SPEED);
Wire.begin();
imu = RTIMU::createIMU(&settings); // create the imu object
Serial.print("ArduinoIMU starting using device "); Serial.println(imu->IMUName());
if ((errcode = imu->IMUInit()) < 0) {
Serial.print("Failed to init IMU: "); Serial.println(errcode);
}
if (imu->getCalibrationValid())
Serial.println("Using compass calibration");
else
Serial.println("No valid compass calibration data");
lastDisplay = lastRate = millis();
sampleCount = 0;
// use of sensors in the fusion algorithm can be controlled here
// change any of these to false to disable that sensor
fusion.setGyroEnable(true);
fusion.setAccelEnable(true);
fusion.setCompassEnable(true);
}
void loop()
{
unsigned long now = millis();
unsigned long delta;
if (imu->IMURead()) { // get the latest data if ready yet
fusion.newIMUData(imu->getGyro(), imu->getAccel(), imu->getCompass(), imu->getTimestamp());
sampleCount++;
if ((delta = now - lastRate) >= 1000) {
Serial.print("Sample rate: "); Serial.print(sampleCount);
if (imu->IMUGyroBiasValid())
Serial.println(", gyro bias valid");
else
Serial.println(", calculating gyro bias");
sampleCount = 0;
lastRate = now;
}
if ((now - lastDisplay) >= DISPLAY_INTERVAL) {
lastDisplay = now;
RTMath::display("Gyro:", (RTVector3&)imu->getGyro()); // gyro data 陀螺仪(角加速度,单位°/S)
RTMath::display("Accel:", (RTVector3&)imu->getAccel()); // accel data 加速度(直线加速度,单位g)
RTMath::display("Mag:", (RTVector3&)imu->getCompass()); // compass data 磁力计(轴磁场强度,单位uT)
//RTMath::displayRollPitchYaw("Pose:", (RTVector3&)fusion.getFusionPose()); // fused output 融合姿态输出
Serial.println();
}
}
}
#define DISPLAY_INTERVAL300 改小一点100,不然可能会卡,不流畅 上位机使用前磁力最好校准一次
不然可能不太准
具体使用时,Z轴朝下,测试单轴转动时,最好把方位角调到0,这样板子上的坐标系才能和世界坐标系重合。 后面我再研究一下用MPU9250代替工业机器箱体测振系统的可能性
能搞定的话,精度足够的话在线监测系统低成本小型化将有望实现:lol:lol:lol:lol:lol:P:P:P
预先资料准备,大家可以看看
《用加速度传感器测量振动位移的方法》请参考之
将直线加速度值放大100倍,测量范围-2,2g
看起来可以稳定在0.01g 支持下啊
很厉害 seekyong 发表于 2015-3-4 21:05 static/image/common/back.gif
上位机使用前磁力最好校准一次
不然可能不太准
使用MPU9150发现得到的Yaw会有严重的漂移,请问9250做的时候各数据的稳定性怎样? 顶!顶!顶!
向大神求助:我现在也只是labview入门不长时间,现在正在折腾怎么用labview读取STL文件,显示,再进一步取它的边线参数
突然就发现你的贴子了,哈哈。
请问方便不方便分享一下你的labview工程,来学习一下呢?非常感谢!
我的Q 13531382