使用官方库移植的办法
使用到的两个文件是“inv_mpu.c”和“inv_mpu_dmp_motion_driver.c”
在学习的过程中,觉得比较好的学习资料已经整理出来,以方便以后学习起来更加方便。
官方资料及代码下载入口

这里使用的是某宝买MPU6050模块给的代码经过移植和修改后能够实现读取9轴数据

首先初始化MPU9250

void MPU9250_Init(void)
{int result=0;result = mpu_init();rt_thread_delay(10);if(!result)   //返回0代表初始化成功{   rt_kprintf("mpu initialization complete......\n ");//mpu_set_sensorif(!mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS))                                 //打开/关闭特定的传感器。{rt_kprintf("mpu_set_sensor complete ......\n");}else{rt_kprintf("mpu_set_sensor come across error ......\n");}//mpu_configure_fifoif(!mpu_configure_fifo(INV_XYZ_GYRO | INV_XYZ_ACCEL))     //选择将哪些传感器推入FIFO。{rt_kprintf("mpu_configure_fifo complete ......\n");}else{rt_kprintf("mpu_configure_fifo come across error ......\n");}//mpu_set_sample_rateif(!mpu_set_sample_rate(DEFAULT_MPU_HZ))          //设置采样率。采样率必须在4Hz到1kHz之间。{rt_kprintf("mpu_set_sample_rate complete ......\n");}else{rt_kprintf("mpu_set_sample_rate error ......\n");}//dmp_load_motion_driver_firmvareif(!dmp_load_motion_driver_firmware())  //用此映像加载DMP。{ rt_kprintf("dmp_load_motion_driver_firmware complete ......\n");}else{rt_kprintf("dmp_load_motion_driver_firmware come across error ......\n");}//dmp_set_orientationif(!dmp_set_orientation(inv_orientation_matrix_to_scalar(gyro_orientation)))   //将陀螺仪和加速度方向推向DMP。 compass_orientation{rt_kprintf("dmp_set_orientation complete ......\n");}else{rt_kprintf("dmp_set_orientation come across error ......\n");}///*    inv_set_compass_orientation_and_scale(inv_orientation_matrix_to_scalar(compass_pdata.orientation),(long)compass_fsr<<15);*/if(!dmp_set_orientation(inv_orientation_matrix_to_scalar(compass_orientation)))   //将compass方向推向DMP。 compass_orientation{rt_kprintf("compassdmp_set_orientation complete ......\n");}else{rt_kprintf("compass dmp_set_orientation come across error ......\n");}//dmp_enable_featureif(!dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT | DMP_FEATURE_TAP |DMP_FEATURE_ANDROID_ORIENT | DMP_FEATURE_SEND_RAW_ACCEL | DMP_FEATURE_SEND_CAL_GYRO |DMP_FEATURE_GYRO_CAL)){rt_kprintf("dmp_enable_feature complete ......\n");}else{rt_kprintf("dmp_enable_feature come across error ......\n");}//dmp_set_fifo_rateif(!dmp_set_fifo_rate(DEFAULT_MPU_HZ)){rt_kprintf("dmp_set_fifo_rate complete ......\n");}else{rt_kprintf("dmp_set_fifo_rate come across error ......\n");}//不开自检,以水平作为零度//开启自检以当前位置作为零度run_self_test();if(!mpu_set_dmp_state(1)){rt_kprintf("mpu_set_dmp_state complete ......\n");}else{rt_kprintf("mpu_set_dmp_state come across error ......\n");}rt_kprintf("MPU9250_Init ok\n");}
}

初始化成功后可以开始读取数据

void MPU9250_Pose(void)
{dmp_read_fifo(gyro, accel, quat, &sensor_timestamp, &sensors,&more);    /* Gyro and accel data are written to the FIFO by the DMP in chip frame and hardware units.* This behavior is convenient because it keeps the gyro and accel outputs of dmp_read_fifo and mpu_read_fifo consistent.**//*if (sensors & INV_XYZ_GYRO )send_packet(PACKET_TYPE_GYRO, gyro);if (sensors & INV_XYZ_ACCEL)send_packet(PACKET_TYPE_ACCEL, accel); *//* Unlike gyro and accel, quaternions are written to the FIFO in the body frame, q30.* The orientation is set by the scalar passed to dmp_set_orientation during initialization. **/if(sensors & INV_WXYZ_QUAT ){q0 = quat[0] / q30; q1 = quat[1] / q30;q2 = quat[2] / q30;q3 = quat[3] / q30;Pitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3 - 1;    // pitchRoll  = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)*57.3;    // rollYaw   = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3;  //yaw/*这里使用的RT-Thread嵌入式开发系统,说以打印函数是rt_kprintf*/rt_kprintf("\n==*****************************==\n");rt_kprintf("Pitch:%d,Roll:%d,Yaw:%d \n",(int)Pitch,(int)Roll,(int)Yaw);rt_kprintf("gyro[0]:%d,gyro[1]:%d,gyro[2]:%d\n",gyro[0],gyro[1],gyro[2]);/* For any MPU device with an AKM on the auxiliary I2C bus, the raw* magnetometer registers are copied to special gyro registers.*/
//      rt_kprintf("%d\n",mpu_get_compass_reg(compass_short, &sensor_timestamp));if (!mpu_get_compass_reg(compass_short, &sensor_timestamp)) {compass[0] = (long)compass_short[0];compass[1] = (long)compass_short[1];compass[2] = (long)compass_short[2];rt_kprintf("compass[0]:%d,compass[1]:%d,compass[2]:%d\n",compass[0],compass[1],compass[2]);/* NOTE: If using a third-party compass calibration library,* pass in the compass data in uT * 2^16 and set the second* parameter to INV_CALIBRATED | acc, where acc is the* accuracy from 0 to 3.*///inv_build_compass(compass, 0, sensor_timestamp);rt_thread_delay(500); //延时}}}

欢迎大家交流学习

MPU9250使用笔记相关推荐

  1. linux串口读取mpu9250数据,模拟 I2C 读取 MPU9250 数据的测试笔记

    硬件:STM32F103ZET6 + GY9250 软件:Keil MDK(v5.27)+ STM32CUBEMX(v5.2.1) 这里我在使用STM32CUBEMX最新版本(v5.5.0)生成Kei ...

  2. MPU9250 使用 DMP 输出姿态角:DMP 库到 STM32 平台移植笔记

    本文开发环境: MCU型号:STM32F103C8T6 IDE环境: MDK 5.27 代码生成工具:STM32CubeMx 5.6.1 HAL库版本:STM32Cube_FW_F1_V1.8.0 本 ...

  3. STM32入门笔记(02):MPU6050、MPU9250、ICM20948及姿态解算(SPL库函数版)

    目录 MPU6050 什么是MPU6050? MPU6050的特点 MPU6050框图 MPU6050初始化 MPU6050寄存器 电源管理寄存器1(0X6B) 陀螺仪配置寄存器(0X1B) 加速度传 ...

  4. RT-Thread实战笔记|MPU6050使用详解及DMP姿态解算

    小伙伴们大家好,好久不更新RT-Thread实战笔记啦,今天来搞一搞MPU6050,话不多说,淦! 本章源码获取 欢迎文末留言区或者公众号后台回复"MPU6050"即可获取本教程源 ...

  5. 【读书笔记】知易行难,多实践

    前言: 其实,我不喜欢看书,只是喜欢找答案,想通过专业的解答来解决我生活的困惑.所以,我听了很多书,也看了很多书,但看完书,没有很多的实践,导致我并不很深入在很多时候. 分享读书笔记: <高效1 ...

  6. 【运维学习笔记】生命不息,搞事开始。。。

    001生命不息,搞事不止!!! 这段时间和hexesdesu搞了很多事情! 之前是机械硬盘和固态硬盘的测速,我就在那默默的看着他一个硬盘一个机械测来测去. 坐在他后面,每天都能看到这位萌萌的小男孩,各 ...

  7. SSAN 关系抽取 论文笔记

    20210621 https://zhuanlan.zhihu.com/p/353183322 [KG笔记]八.文档级(Document Level)关系抽取任务 共指id嵌入一样 但是实体嵌入的时候 ...

  8. pandas以前笔记

    # -*- coding: utf-8 -*- """ Created on Sat Jul 21 20:06:20 2018@author: heimi "& ...

  9. PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 call

    您的位置 首页 PyTorch 学习笔记系列 PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 发布: 2017年8月4日 7,195阅读 ...

最新文章

  1. Linux 安装Boost
  2. php5.5 mysql网站空间_PHP环境配置IIS5.0+PHP5.23+MYSQL5+phpMyAdmin
  3. Apache 各启动方式的差别
  4. Python词云#疫情退去后,你最想做什么
  5. 10tb服务器硬盘 选购,2017最靠谱大容量机械硬盘选购指南(基于Backblaze硬盘寿命可靠性报告)...
  6. Debug和Release区别
  7. 消费金融盈利分析及风控能力建设
  8. 安装程序提示本地计算机已存在源,MSI文件安装错误码不再烦
  9. java检索电脑的所有图片_查找电脑里重复的照片
  10. AspNet Core 2.2 SendGrid邮件发送(可群发)
  11. 01背包与完全背包的区分
  12. Prometheus原理详解
  13. AntiVir UNIX 在Ubuntu 8.04下的安装
  14. Jungle Roads丛林道路(最小生成树PrimKruskal算法)
  15. Python爬取彼岸图4k壁纸,想要什么类型的壁纸就输入什么壁纸,太方便了。
  16. 小米刷Magisk(Root)
  17. matlab实现RBF的相关函数
  18. 好员工,别以为裁员与你无关(上
  19. Python调整Excel格式
  20. 怎么安装python3.72_这才是 Python 的 “72 变”玩法!

热门文章

  1. http_proxy设置
  2. 攻防世界--no-strings-attached
  3. AutoGAN-Distiller: Searching to Compress Generative Adversarial Networks, ICML2020
  4. 内存XMP是什么意思
  5. rtp server
  6. js中向数组中添加元素unshift() 方法
  7. 机器学习之PQ量化算法
  8. 四周无人机的姿态解算(2)
  9. PS 不能使用移动工具 因为目标图层被隐藏怎么办
  10. TexturePacker批处理python