完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我用rtthread的sensor框架,添加rtt的BMI160软件包,发现读出来的加速度传感器值异常。 当板子平放在桌面上,静止不动,打印的log是 当板子垫一个U盘,使他倾斜一个角度,静止不动,打印的log是 感觉像是陀螺仪的数据而不是加速度的。 代码如下 int bmx160_port(void) { struct rt_sensor_config cfg; cfg.intf.dev_name = “i2c3”; cfg.intf.user_data = (void *)0x68; cfg.irq_pin.pin = RT_PIN_NONE; cfg.irq_pin.mode = PIN_MODE_INPUT_PULLDOWN; rt_hw_bmx160_init(“bmi160”, &cfg); return 0; } static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor_data *sensor_data) { switch (sensor->info.type) { case RT_SENSOR_CLASS_ACCE: rt_kprintf(“num:%3d, x:%5d, y:%5d, z:%5d, timestamp:%5d\n”, num, sensor_data->data.acce.x, sensor_data->data.acce.y, sensor_data->data.acce.z, sensor_data->timestamp); break; case RT_SENSOR_CLASS_GYRO: rt_kprintf(“num:%3d, x:%8d, y:%8d, z:%8d, timestamp:%5d\n”, num, sensor_data->data.gyro.x, sensor_data->data.gyro.y, sensor_data->data.gyro.z, sensor_data->timestamp); break; case RT_SENSOR_CLASS_MAG: rt_kprintf(“num:%3d, x:%5d, y:%5d, z:%5d, timestamp:%5d\n”, num, sensor_data->data.mag.x, sensor_data->data.mag.y, sensor_data->data.mag.z, sensor_data->timestamp); break; case RT_SENSOR_CLASS_HUMI: rt_kprintf(“num:%3d, humi:%3d.%d%%, timestamp:%5d\n”, num, sensor_data->data.humi / 10, sensor_data->data.humi % 10, sensor_data->timestamp); break; case RT_SENSOR_CLASS_TEMP: rt_kprintf(“num:%3d, temp:%3d.%dC, timestamp:%5d\n”, num, sensor_data->data.temp / 10, sensor_data->data.temp % 10, sensor_data->timestamp); break; case RT_SENSOR_CLASS_BARO: rt_kprintf(“num:%3d, press:%5d, timestamp:%5d\n”, num, sensor_data->data.baro, sensor_data->timestamp); break; case RT_SENSOR_CLASS_STEP: rt_kprintf(“num:%3d, step:%5d, timestamp:%5d\n”, num, sensor_data->data.step, sensor_data->timestamp); break; default: break; } } int main(void) { rt_device_t dev = RT_NULL; rt_size_t res, i=0; struct rt_sensor_data data; rt_thread_mdelay(1000); bmx160_port(); /* 查找系统中的传感器设备 */ dev = rt_device_find(“acce_bmi”); if (dev == RT_NULL){ rt_kprintf(“Can’t find device\n”); return 0; } /* 以轮询模式打开传感器设备 */ if (rt_device_open(dev, RT_DEVICE_FLAG_RDONLY) != RT_EOK){ rt_kprintf("open device failed!"); return 0; } while (1){
res = rt_device_read(dev, 0, &data, 1); if (res != 1){
}
} } } |
|
相关推荐
2个回答
|
|
看起来数据是没问题的,加速度计的值确实z轴要比xy轴大得多,倾斜之后xy的值也有变化,这里检查下输出数据的单位,然后换算成m/s/s看看是多少
陀螺仪的值看起来也是正常的,陀螺仪静止时候输出应该是接近0的,且与倾斜角度无关 |
|
|
|
这个应该是陀螺仪的值的,加速度计在静止前提下应该只有地心加速度值
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
655 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
2448 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1292 浏览 0 评论
1895 浏览 0 评论
1486 浏览 0 评论
74875 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 20:01 , Processed in 0.695124 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号