极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 114619|回复: 58

MPU9250,MPU6050芯片3D姿态PC上位机及Arduino下位机程序库

  [复制链接]
发表于 2015-2-18 23:35:10 | 显示全部楼层 |阅读模式
本帖最后由 seekyong 于 2015-3-4 21:01 编辑

RTIMULib-Arduino now supports the InvenSense MPU-9250 9-dof IMU


这个是Arduino库文件,输出的就是算好的姿态!



此乃老夫的上位机,之前看过Mission Planner,看过MK-TOOL,本来想省事找接口用他们那上位机的姿态部分,太费脑筋。后来不如自己编一个,也不难,还入门了LABview。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-3-20 08:54:47 | 显示全部楼层
本帖最后由 mc.six 于 2015-3-20 13:27 编辑

奇怪怎么会这样-----好了可能是线插得不好

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 3 反对 0

使用道具 举报

发表于 2015-2-28 15:33:41 | 显示全部楼层
请问能否实现多个mpu9250之间连接传输数据呢?我看到手册里写的有这种接口,想问一下,不知道有人成功过吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-28 17:34:46 | 显示全部楼层
单个的我试成功了,数据稳定,现在在搞姿态软件,直接显示三维姿态在电脑上
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-1 15:31:35 | 显示全部楼层


输出为姿态融合算法:偏航角Yaw、俯仰角Pitch和滚动角Roll

由四元数求出的最终姿态角,其中Yaw为航向角,表示机头偏离正北方多少度,范围-180到+180
Pitch为俯仰角,表示机头正方向与水平线的夹角,范围-90到+90
Roll为翻滚角,表示机翼与水平线的夹角,范围:-180到+180

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 00:29:50 | 显示全部楼层
本帖最后由 seekyong 于 2015-3-4 20:59 编辑

注意:将压缩包中此文件seekyong.stl放入D盘根目录即可
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 00:40:43 | 显示全部楼层
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of RTIMULib-Arduino
  4. //
  5. //  Copyright (c) 2014, richards-tech
  6. //
  7. //  Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. //  this software and associated documentation files (the "Software"), to deal in
  9. //  the Software without restriction, including without limitation the rights to use,
  10. //  copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
  11. //  Software, and to permit persons to whom the Software is furnished to do so,
  12. //  subject to the following conditions:
  13. //
  14. //  The above copyright notice and this permission notice shall be included in all
  15. //  copies or substantial portions of the Software.
  16. //
  17. //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  18. //  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  19. //  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. //  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. //  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. //  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  23. #include <Wire.h>
  24. #include "I2Cdev.h"
  25. #include "RTIMUSettings.h"
  26. #include "RTIMU.h"
  27. #include "RTFusionRTQF.h"
  28. #include "CalLib.h"
  29. #include <EEPROM.h>

  30. RTIMU *imu;                                           // the IMU object
  31. RTFusionRTQF fusion;                                  // the fusion object
  32. RTIMUSettings settings;                               // the settings object

  33. //  DISPLAY_INTERVAL sets the rate at which results are displayed

  34. #define DISPLAY_INTERVAL  300                         // interval between pose displays

  35. //  SERIAL_PORT_SPEED defines the speed to use for the debug serial port

  36. #define  SERIAL_PORT_SPEED  115200

  37. unsigned long lastDisplay;
  38. unsigned long lastRate;
  39. int sampleCount;

  40. void setup()
  41. {
  42.     int errcode;
  43.   
  44.     Serial.begin(SERIAL_PORT_SPEED);
  45.     Wire.begin();
  46.     imu = RTIMU::createIMU(&settings);                        // create the imu object
  47.   
  48.     Serial.print("ArduinoIMU starting using device "); Serial.println(imu->IMUName());
  49.     if ((errcode = imu->IMUInit()) < 0) {
  50.         Serial.print("Failed to init IMU: "); Serial.println(errcode);
  51.     }
  52.   
  53.     if (imu->getCalibrationValid())
  54.         Serial.println("Using compass calibration");
  55.     else
  56.         Serial.println("No valid compass calibration data");

  57.     lastDisplay = lastRate = millis();
  58.     sampleCount = 0;
  59.    
  60.     // use of sensors in the fusion algorithm can be controlled here
  61.     // change any of these to false to disable that sensor
  62.    
  63.     fusion.setGyroEnable(true);
  64.     fusion.setAccelEnable(true);
  65.     fusion.setCompassEnable(true);
  66. }

  67. void loop()
  68. {  
  69.     unsigned long now = millis();
  70.     unsigned long delta;
  71.   
  72.     if (imu->IMURead()) {                                // get the latest data if ready yet
  73.         fusion.newIMUData(imu->getGyro(), imu->getAccel(), imu->getCompass(), imu->getTimestamp());
  74.         sampleCount++;
  75.         if ((delta = now - lastRate) >= 1000) {
  76.             Serial.print("Sample rate: "); Serial.print(sampleCount);
  77.             if (imu->IMUGyroBiasValid())
  78.                 Serial.println(", gyro bias valid");
  79.             else
  80.                 Serial.println(", calculating gyro bias");
  81.         
  82.             sampleCount = 0;
  83.             lastRate = now;
  84.         }
  85.         if ((now - lastDisplay) >= DISPLAY_INTERVAL) {
  86.             lastDisplay = now;
  87.             RTMath::display("Gyro:", (RTVector3&)imu->getGyro());                // gyro data 陀螺仪(角加速度,单位°/S)
  88.             RTMath::display("Accel:", (RTVector3&)imu->getAccel());              // accel data 加速度(直线加速度,单位g)
  89.             RTMath::display("Mag:", (RTVector3&)imu->getCompass());              // compass data 磁力计(轴磁场强度,单位uT)
  90.             //RTMath::displayRollPitchYaw("Pose:", (RTVector3&)fusion.getFusionPose()); // fused output 融合姿态输出
  91.            Serial.println();
  92.         }
  93.     }
  94. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 00:42:39 | 显示全部楼层
#define DISPLAY_INTERVAL  300 改小一点100,不然可能会卡,不流畅
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 21:05:13 | 显示全部楼层
上位机使用前磁力最好校准一次

不然可能不太准

具体使用时,Z轴朝下,测试单轴转动时,最好把方位角调到0,这样板子上的坐标系才能和世界坐标系重合。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 21:51:26 | 显示全部楼层
后面我再研究一下用MPU9250代替工业机器箱体测振系统的可能性

能搞定的话,精度足够的话在线监测系统低成本小型化将有望实现
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 22:04:46 | 显示全部楼层


预先资料准备,大家可以看看

《用加速度传感器测量振动位移的方法》请参考之

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-4 22:18:57 | 显示全部楼层


将直线加速度值放大100倍,测量范围-2,2g

看起来可以稳定在0.01g

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2015-3-16 11:13:41 | 显示全部楼层
支持下啊
很厉害
回复 支持 反对

使用道具 举报

发表于 2015-3-31 15:00:07 | 显示全部楼层
seekyong 发表于 2015-3-4 21:05
上位机使用前磁力最好校准一次

不然可能不太准

使用MPU9150发现得到的Yaw会有严重的漂移,请问9250做的时候各数据的稳定性怎样?
回复 支持 反对

使用道具 举报

发表于 2015-4-4 12:46:30 | 显示全部楼层
顶!顶!顶!
向大神求助:我现在也只是labview入门不长时间,现在正在折腾怎么用labview读取STL文件,显示,再进一步取它的边线参数
突然就发现你的贴子了,哈哈。
请问方便不方便分享一下你的labview工程,来学习一下呢?非常感谢!
我的Q 13531382
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 22:13 , Processed in 0.051959 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表