資源簡介
樹莓派下使用I2C讀取mpu9250,獲得歐拉角YAW,PITCH,ROLL,并輸出,穩定
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?“MotionSensor.h“
#define?delay_ms(a)?usleep(a*1000)
/*SQLITE3?DB*/
?
static?sqlite3?*db?=?NULL;
static?char?*errmsg?=?NULL;
int?main()?{
????char?sql[512]?;?//插入數據庫語句
????int?ret;
????int?insert;
????ret?=?sqlite3_open(“mpu9250.db“?&db);
????if(ret)
????{
????????printf(“can?not?open?database.\n“);
????}
????else
????{
????????printf(“open?database?succsee.\n“);
????}
???int?i??=?0;
ms_open();
????while(i?5000){
????????ms_update();
????????sprintf(sql“insert?into?mpu9250?values?(%d%2.1f%2.1f?%2.1f?%2.1f?%2.1f?%2.1f);“?i?ypr[YAW]?ypr[PITCH]?ypr[ROLL]compass[0]compass[1]compass[2]);
????????insert?=??sqlite3_exec(db?sql?0?0?&errmsg);//插入
????????printf(“index=?%d\tyaw?=?%2.1f\tpitch?=?%2.1f\troll?=?%2.1f\ttemperature?=?%2.1f\tcompass?=?%2.1f?%2.1f?%2.1f\n“?iypr[YAW]?ypr[PITCH]ypr[ROLL]tempcompass[0]compass[1]compass[2]);
????????delay_ms(5);
????????i++;
????}
????sqlite3_close(db);
return?0;
}
評論
共有 條評論