设为首页
收藏本站
找回密码
开启辅助访问
登录
注册
只需一步,快速开始
首页
BBS
在线充值
搜索
工控币获得方法
联系方式
搜索
搜索
本版
帖子
用户
工控论坛
»
首页
›
电子技术
›
上位机开发及系统管理
›
MPU-6050使用Python上位机监控实时动作
返回列表
发新帖
MPU-6050使用Python上位机监控实时动作
[复制链接]
61
|
0
|
2020-1-20 19:52:49
|
显示全部楼层
|
阅读模式
单片机:STM32F4_MD6
上位机:Python
MPU-6050-Python上位机.zip
(19.63 MB, 售价: 1 工控币)
2020-1-20 19:52 上传
点击文件名下载附件
#ifdef COMPASS_ENABLED
void send_status_compass() {
long data[3] = { 0 };
int8_t accuracy = { 0 };
unsigned long timestamp;
inv_get_compass_set(data, &accuracy, (inv_time_t*) ×tamp);
MPL_LOGI("Compass: %7.4f %7.4f %7.4f ",
data[0]/65536.f, data[1]/65536.f, data[2]/65536.f);
MPL_LOGI("Accuracy= %d\r\n", accuracy);
}
#endif
/* Handle sensor on/off combinations. */
static void setup_gyro(void)
{
unsigned char mask = 0, lp_accel_was_on = 0;
if (hal.sensors & ACCEL_ON)
mask |= INV_XYZ_ACCEL;
if (hal.sensors & GYRO_ON) {
mask |= INV_XYZ_GYRO;
lp_accel_was_on |= hal.lp_accel_mode;
}
#ifdef COMPASS_ENABLED
if (hal.sensors & COMPASS_ON) {
mask |= INV_XYZ_COMPASS;
lp_accel_was_on |= hal.lp_accel_mode;
}
#endif
/* If you need a power transition, this function should be called with a
* mask of the sensors still enabled. The driver turns off any sensors
* excluded from this mask.
*/
mpu_set_sensors(mask);
mpu_configure_fifo(mask);
if (lp_accel_was_on) {
unsigned short rate;
hal.lp_accel_mode = 0;
/* Switching out of LP accel, notify MPL of new accel sampling rate. */
mpu_get_sample_rate(&rate);
inv_set_accel_sample_rate(1000000L / rate);
}
}
static void tap_cb(unsigned char direction, unsigned char count)
{
switch (direction) {
case TAP_X_UP:
MPL_LOGI("Tap X+ ");
break;
case TAP_X_DOWN:
MPL_LOGI("Tap X- ");
break;
case TAP_Y_UP:
MPL_LOGI("Tap Y+ ");
break;
case TAP_Y_DOWN:
MPL_LOGI("Tap Y- ");
break;
case TAP_Z_UP:
MPL_LOGI("Tap Z+ ");
break;
case TAP_Z_DOWN:
MPL_LOGI("Tap Z- ");
break;
default:
return;
}
MPL_LOGI("x%d\n", count);
return;
}
static void android_orient_cb(unsigned char orientation)
{
switch (orientation) {
case ANDROID_ORIENT_PORTRAIT:
MPL_LOGI("Portrait\n");
break;
case ANDROID_ORIENT_LANDSCAPE:
MPL_LOGI("Landscape\n");
break;
case ANDROID_ORIENT_REVERSE_PORTRAIT:
MPL_LOGI("Reverse Portrait\n");
break;
case ANDROID_ORIENT_REVERSE_LANDSCAPE:
MPL_LOGI("Reverse Landscape\n");
break;
default:
return;
}
}
static inline void run_self_test(void)
{
int result;
long gyro[3], accel[3];
#if defined (MPU6500) || defined (MPU9250)
result = mpu_run_6500_self_test(gyro, accel, 0);
#elif defined (MPU6050) || defined (MPU9150)
result = mpu_run_self_test(gyro, accel);
#endif
if (result == 0x7) {
MPL_LOGI("Passed!\n");
MPL_LOGI("accel: %7.4f %7.4f %7.4f\n",
accel[0]/65536.f,
accel[1]/65536.f,
accel[2]/65536.f);
MPL_LOGI("gyro: %7.4f %7.4f %7.4f\n",
gyro[0]/65536.f,
gyro[1]/65536.f,
gyro[2]/65536.f);
/* Test passed. We can trust the gyro data here, so now we need to update calibrated data*/
#ifdef USE_CAL_HW_REGISTERS
/*
* This portion of the code uses the HW offset registers that are in the MPUxxxx devices
* instead of pushing the cal data to the MPL software library
*/
unsigned char i = 0;
for(i = 0; i<3; i++) {
gyro[i] = (long)(gyro[i] * 32.8f); //convert to +-1000dps
accel[i] *= 2048.f; //convert to +-16G
accel[i] = accel[i] >> 16;
gyro[i] = (long)(gyro[i] >> 16);
}
mpu_set_gyro_bias_reg(gyro);
#if defined (MPU6500) || defined (MPU9250)
mpu_set_accel_bias_6500_reg(accel);
#elif defined (MPU6050) || defined (MPU9150)
mpu_set_accel_bias_6050_reg(accel);
#endif
#else
/* Push the calibrated data to the MPL library.
*
* MPL expects biases in hardware units << 16, but self test returns
* biases in g's << 16.
*/
unsigned short accel_sens;
float gyro_sens;
mpu_get_accel_sens(&accel_sens);
accel[0] *= accel_sens;
accel[1] *= accel_sens;
accel[2] *= accel_sens;
inv_set_accel_bias(accel, 3);
mpu_get_gyro_sens(&gyro_sens);
gyro[0] = (long) (gyro[0] * gyro_sens);
gyro[1] = (long) (gyro[1] * gyro_sens);
gyro[2] = (long) (gyro[2] * gyro_sens);
inv_set_gyro_bias(gyro, 3);
#endif
}
else {
if (!(result & 0x1))
MPL_LOGE("Gyro failed.\n");
if (!(result & 0x2))
MPL_LOGE("Accel failed.\n");
if (!(result & 0x4))
MPL_LOGE("Compass failed.\n");
}
}
复制代码
Python
相关帖子
•
Python随机森林例子 源码分享
•
LabVIEW调用python代码
•
八数码难题 人工智能python代码含宽度优先算法
•
Python操作csv文件源程序
•
简单的Python程序实现PCAN自动发送CAN报文
•
Python串口助手 TK界面(含源代码)
•
Python移植到SAIL-IMX7D
回复
使用道具
举报
返回列表
发新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
注册
本版积分规则
发表回复
回帖后跳转到最后一页
coolice
437
主题
444
帖子
366
积分
初级会员
初级会员, 积分 366, 距离下一级还需 134 积分
初级会员, 积分 366, 距离下一级还需 134 积分
工控币
366
加好友
发消息
回复楼主
返回列表
电子技术综合讨论
单片机嵌入式
EDA设计仿真
STM32/8
51单片机
上位机开发及系统管理
Labview
Multisim仿真
图文推荐
西门子1200plc与RKC温控模组com-ml profinet通讯gsd 程序 文档
2021-02-24
PLC-LAB-非标自动化2D建模仿真软件 中文说明和操作演示视频
2021-02-15
组态王机械手加反应罐监控系统 工程源文件与设计文档
2021-02-04
太阳能翻板追日控制 采用s7-200plc与光照度模块modbus通信
2021-02-01
基于51单片机数字电压表 程序 原理图 pcb 仿真文件 论文
2021-01-26
热门排行
1
WINCC运行时动态锁定/解锁相应系统组合键
2
普洛菲斯触摸屏软件 GP-Pro EX 4.09
3
最全EPLAN部件库,淘宝购买的
4
彻底搞定C指针(完全版·修订增补版)
5
西门子SINUMERIK 828D 840D sl数控 培训教
6
激光焊接机电控系统 台达PLC程序 威纶触摸
7
GE iFIX 6.5 English安装软件
8
音频功率放大器Multisim仿真电路设计
9
数字电路拔河机Multisim仿真设计
10
函数信号发生器Multisim仿真 可调频 幅值(