2022-10-20 17:13:02 +08:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @file ins_task.h
|
|
|
|
* @author Wang Hongxi
|
2022-11-23 22:10:44 +08:00
|
|
|
* @author annotation and modification by NeoZeng
|
2022-10-20 17:13:02 +08:00
|
|
|
* @version V2.0.0
|
|
|
|
* @date 2022/2/23
|
|
|
|
* @brief
|
|
|
|
******************************************************************************
|
2022-11-23 22:10:44 +08:00
|
|
|
* @attention INS任务的初始化不要放入实时系统!应该由application拥有实例,随后在
|
|
|
|
* 应用层调用初始化函数.
|
2023-01-02 23:20:35 +08:00
|
|
|
*
|
2022-10-20 17:13:02 +08:00
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
#ifndef __INS_TASK_H
|
|
|
|
#define __INS_TASK_H
|
|
|
|
|
|
|
|
#include "stdint.h"
|
|
|
|
#include "BMI088driver.h"
|
|
|
|
#include "QuaternionEKF.h"
|
|
|
|
|
|
|
|
#define X 0
|
|
|
|
#define Y 1
|
|
|
|
#define Z 2
|
|
|
|
|
|
|
|
#define INS_TASK_PERIOD 1
|
|
|
|
|
2022-11-01 22:32:15 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2023-01-02 23:20:35 +08:00
|
|
|
float Gyro[3]; // 角速度
|
|
|
|
float Accel[3]; // 加速度
|
2022-12-04 14:35:42 +08:00
|
|
|
// 还需要增加角速度数据
|
2022-11-01 22:32:15 +08:00
|
|
|
float Roll;
|
|
|
|
float Pitch;
|
|
|
|
float Yaw;
|
|
|
|
float YawTotalAngle;
|
2023-01-02 23:20:35 +08:00
|
|
|
} attitude_t; // 最终解算得到的角度,以及yaw转动的总角度(方便多圈控制)
|
2022-11-01 22:32:15 +08:00
|
|
|
|
2022-10-20 17:13:02 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
float q[4]; // 四元数估计值
|
|
|
|
|
|
|
|
float MotionAccel_b[3]; // 机体坐标加速度
|
|
|
|
float MotionAccel_n[3]; // 绝对系加速度
|
|
|
|
|
|
|
|
float AccelLPF; // 加速度低通滤波系数
|
|
|
|
|
2023-01-02 23:20:35 +08:00
|
|
|
// bodyframe在绝对系的向量表示
|
2022-10-20 17:13:02 +08:00
|
|
|
float xn[3];
|
|
|
|
float yn[3];
|
|
|
|
float zn[3];
|
|
|
|
|
2023-01-02 23:20:35 +08:00
|
|
|
// 加速度在机体系和XY两轴的夹角
|
|
|
|
// float atanxz;
|
|
|
|
// float atanyz;
|
2022-10-20 17:13:02 +08:00
|
|
|
|
2023-01-02 23:20:35 +08:00
|
|
|
// IMU量测值
|
|
|
|
float Gyro[3]; // 角速度
|
|
|
|
float Accel[3]; // 加速度
|
2022-10-20 17:13:02 +08:00
|
|
|
// 位姿
|
|
|
|
float Roll;
|
|
|
|
float Pitch;
|
|
|
|
float Yaw;
|
|
|
|
float YawTotalAngle;
|
2023-06-05 22:43:25 +08:00
|
|
|
|
|
|
|
uint8_t init;
|
2022-10-20 17:13:02 +08:00
|
|
|
} INS_t;
|
|
|
|
|
2022-11-23 22:10:44 +08:00
|
|
|
/* 用于修正安装误差的参数 */
|
2022-10-20 17:13:02 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t flag;
|
|
|
|
|
|
|
|
float scale[3];
|
|
|
|
|
|
|
|
float Yaw;
|
|
|
|
float Pitch;
|
|
|
|
float Roll;
|
|
|
|
} IMU_Param_t;
|
|
|
|
|
2022-11-01 22:32:15 +08:00
|
|
|
/**
|
|
|
|
* @brief 初始化惯导解算系统
|
|
|
|
*
|
|
|
|
*/
|
2022-12-03 15:20:17 +08:00
|
|
|
attitude_t *INS_Init(void);
|
2022-11-01 22:32:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 此函数放入实时系统中,以1kHz频率运行
|
|
|
|
* p.s. osDelay(1);
|
|
|
|
*
|
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
void INS_Task(void);
|
2022-11-01 22:32:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 四元数更新函数,即实现dq/dt=0.5Ωq
|
|
|
|
*
|
|
|
|
* @param q 四元数
|
|
|
|
* @param gx
|
|
|
|
* @param gy
|
|
|
|
* @param gz
|
|
|
|
* @param dt 距离上次调用的时间间隔
|
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
void QuaternionUpdate(float *q, float gx, float gy, float gz, float dt);
|
2022-11-01 22:32:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 四元数转换成欧拉角 ZYX
|
|
|
|
*
|
|
|
|
* @param q
|
|
|
|
* @param Yaw
|
|
|
|
* @param Pitch
|
|
|
|
* @param Roll
|
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
void QuaternionToEularAngle(float *q, float *Yaw, float *Pitch, float *Roll);
|
2022-11-01 22:32:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ZYX欧拉角转换为四元数
|
|
|
|
*
|
|
|
|
* @param Yaw
|
|
|
|
* @param Pitch
|
|
|
|
* @param Roll
|
|
|
|
* @param q
|
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
void EularAngleToQuaternion(float Yaw, float Pitch, float Roll, float *q);
|
2022-11-01 22:32:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 机体系到惯性系的变换函数
|
|
|
|
*
|
|
|
|
* @param vecBF body frame
|
|
|
|
* @param vecEF earth frame
|
|
|
|
* @param q
|
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
void BodyFrameToEarthFrame(const float *vecBF, float *vecEF, float *q);
|
2022-11-01 22:32:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 惯性系转换到机体系
|
|
|
|
*
|
|
|
|
* @param vecEF
|
|
|
|
* @param vecBF
|
|
|
|
* @param q
|
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
void EarthFrameToBodyFrame(const float *vecEF, float *vecBF, float *q);
|
|
|
|
|
|
|
|
#endif
|