-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.陀螺仪校准支持三个gyro 2.加速度增加一级滑动滤波,提高数据质量 3.优化飞控任务逻辑,使得电机驱动与惯性导航独立运行 4.限制角…
…速度感知范围
- Loading branch information
Showing
6 changed files
with
175 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* File: \kalmanFilter.h | ||
* Project: algorithm | ||
* Created Date: 2024-04-29 20:41:02 | ||
* Author: Guoyi | ||
* ----- | ||
* Last Modified: 2024-04-29 20:57:21 | ||
* Modified By: Guoyi | ||
* ----- | ||
* Copyright (c) 2024 Guoyi Inc. | ||
* | ||
* ------------------------------------ | ||
*/ | ||
|
||
float kalman_filter(float angle_m, float gyro_m, float *angle_f, float *angle_dot_f) | ||
{ | ||
//------------------------------ | ||
static float angle, angle_dot; | ||
const float Q_angle = 0.000001, Q_gyro = 0.0001, R_angle = 0.5, dt = 0.002; | ||
static float P[2][2] = { | ||
{1, 0}, | ||
{0, 1}}; | ||
static float Pdot[4] = {0, 0, 0, 0}; | ||
const uint8 C_0 = 1; | ||
static float q_bias, angle_err, PCt_0, PCt_1, E, K_0, K_1, t_0, t_1; | ||
//------------------------------ | ||
angle += (gyro_m - q_bias) * dt; | ||
|
||
Pdot[0] = Q_angle - P[0][1] - P[1][0]; | ||
Pdot[1] = -P[1][1]; | ||
Pdot[2] = -P[1][1]; | ||
Pdot[3] = Q_gyro; | ||
|
||
P[0][0] += Pdot[0] * dt; | ||
P[0][1] += Pdot[1] * dt; | ||
P[1][0] += Pdot[2] * dt; | ||
P[1][1] += Pdot[3] * dt; | ||
|
||
angle_err = angle_m - angle; | ||
|
||
PCt_0 = C_0 * P[0][0]; | ||
PCt_1 = C_0 * P[1][0]; | ||
|
||
E = R_angle + C_0 * PCt_0; | ||
|
||
K_0 = PCt_0 / E; | ||
K_1 = PCt_1 / E; | ||
|
||
t_0 = PCt_0; | ||
t_1 = C_0 * P[0][1]; | ||
|
||
P[0][0] -= K_0 * t_0; | ||
P[0][1] -= K_0 * t_1; | ||
P[1][0] -= K_1 * t_0; | ||
P[1][1] -= K_1 * t_1; | ||
|
||
angle += K_0 * angle_err; | ||
q_bias += K_1 * angle_err; | ||
angle_dot = gyro_m - q_bias; | ||
|
||
*angle_f = angle; | ||
*angle_dot_f = angle_dot; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* File: \slidingFilter.h | ||
* Project: algorithm | ||
* Created Date: 2024-04-29 21:10:08 | ||
* Author: Guoyi | ||
* ----- | ||
* Last Modified: 2024-04-29 22:54:36 | ||
* Modified By: Guoyi | ||
* ----- | ||
* Copyright (c) 2024 Guoyi Inc. | ||
* | ||
* ------------------------------------ | ||
*/ | ||
|
||
#ifndef SLIDING_FILTER_H | ||
#define SLIDING_FILTER_H | ||
|
||
#include <stdio.h> | ||
#include "utils/F3D.h" | ||
|
||
#define SLIDING_FILTER_QUEUE_LEN 10 | ||
|
||
// 只对加速度进行滑动滤波 | ||
static float SlidingFilterQueue[3][SLIDING_FILTER_QUEUE_LEN]; // gcc默认初始化全0,不用手动置为零 | ||
static int insertStart = 0; | ||
static float sumX = 0; | ||
static float sumY = 0; | ||
static float sumZ = 0; | ||
|
||
F3D performSlidingFilter(F3D OriginalData) | ||
{ | ||
float ax = OriginalData.x; | ||
float ay = OriginalData.y; | ||
float az = OriginalData.z; | ||
|
||
// 更新sum | ||
sumX += ax / SLIDING_FILTER_QUEUE_LEN - SlidingFilterQueue[0][insertStart]; | ||
sumY += ay / SLIDING_FILTER_QUEUE_LEN - SlidingFilterQueue[1][insertStart]; | ||
sumZ += az / SLIDING_FILTER_QUEUE_LEN - SlidingFilterQueue[2][insertStart]; | ||
|
||
// 更新队列 | ||
SlidingFilterQueue[0][insertStart] = ax / SLIDING_FILTER_QUEUE_LEN; | ||
SlidingFilterQueue[1][insertStart] = ay / SLIDING_FILTER_QUEUE_LEN; | ||
SlidingFilterQueue[2][insertStart] = az / SLIDING_FILTER_QUEUE_LEN; | ||
insertStart++; | ||
if (insertStart >= SLIDING_FILTER_QUEUE_LEN) | ||
{ | ||
insertStart = 0; | ||
} | ||
|
||
// 包装值,并返回F3D | ||
F3D ret = { | ||
.x = sumX, | ||
.y = sumY, | ||
.z = sumZ, | ||
}; | ||
return ret; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters