mpu.c 945 字节
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <fcntl.h>
#include <termios.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdint.h>
#include "gdu_aircraft_info.h"
#include <gdu_logger.h>
#include "mpu.h"
#include "MotionSensor.h"

#define delay_ms(a) usleep(a*1000)

extern float ypr[3]; //yaw, pitch, roll
extern float accel[3];
extern float gyro[3];
extern float temp;
extern float compass[3];

static void *get_mpu(void *arg);

void mpu_init(){
	pthread_t MPU_task;
	int tts_ret = pthread_create(&MPU_task,NULL,get_mpu,NULL);		//读取线程
	if(tts_ret != 0)
	{
		printf("创建MPU线程失败!\n");
	}
	return;
}


//获取mpu数据线程
void *get_mpu(void *arg)
{
	ms_open();//初始化
	while(1){
		ms_update();//开始读数据
		//printf("yaw = %2.1f\tpitch = %2.1f\troll = %2.1f\ttemperature = %2.1f\t\n",	ypr[YAW], ypr[PITCH],ypr[ROLL],temp);
		delay_ms(100);
	}
	
}