然后在while(1)里,就是最重要的姿态解算函数了。
imu_get_euler_angle(&angle);就是姿态解算函数,并把得到的结果保存到angle变量里。
代码如下:
uint32_t imu_get_euler_angle(imu_float_euler_angle_t * angle)
{
uint8_t err = 0;
int16_t ax,ay,az,gx,gy,gz,mx,my,mz;
imu_raw_data_t raw_data;
// imu_raw_data_t filter_data;
imu_float_data_t float_data;
err += gpIOInstallStruct->imu_get_accel(&ax, &ay, &az);
err += gpIOInstallStruct->imu_get_gyro(&gx, &gy, &gz);
err += gpIOInstallStruct->imu_get_mag(&mx, &my, &mz);
if(err >0)
{
return 1;
}
raw_data.ax = ax;
raw_data.ay = ay;
raw_data.az = az;
raw_data.gx = gx;
raw_data.gy = gy;
raw_data.gz = gz;
raw_data.mx = mx;
raw_data.my = my;
raw_data.mz = mz;
#if 0
//I need rawdata I give you filtered data
imu_sliding_filter(raw_data, &filter_data);
#endif
// I need filtered data I give you float data
imu_format_data(raw_data, &float_data);
//I need float data I give you euler angles
updateAHRS( float_data.gx * Gyro_Gr,
float_data.gy * Gyro_Gr,
float_data.gz * Gyro_Gr,
float_data.ax,
float_data.ay,
float_data.az,
float_data.mx,
float_data.my,
float_data.mz,
angle);
return 0;
}
|