mpu.c
945 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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);
}
}