有把加速度计和陀螺仪融合的算法吗
答案:2 悬赏:0 手机版
解决时间 2021-02-11 04:41
- 提问者网友:謫仙
- 2021-02-10 04:46
有把加速度计和陀螺仪融合的算法吗
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-02-10 06:14
有把加 速度计和陀螺仪融合的算法吗 有把加速度 计和陀螺仪融合的 算法吗
全部回答
- 1楼网友:山君与见山
- 2021-02-10 07:29
给你arduino的卡尔曼滤波融合算法,非原创,我只是封装了算法。
h文件:
#ifndef kalmanfilter_h
#define kalmanfilter_h
#include
class kalmanfilter
{
public:
kalmanfilter();
void getvalue(double angle_m, double gyro_m, double dt, double &outangle, double &outangledot);
private:
double c_0, q_angle, q_gyro, r_angle;
double q_bias, angle_err, pct_0, pct_1, e, k_0, k_1, t_0, t_1;
double angle, angle_dot;
double p[2][2];
double pdot[4];
};
cpp文件:
#include "kalmanfilter.h"
kalmanfilter::kalmanfilter()
{
c_0 = 1.0f;
q_angle = 0.001f;
q_gyro = 0.003f;
r_angle = 0.5f;
q_bias = angle_err = pct_0 = pct_1 = e = k_0 = k_1 = t_0 = t_1 = 0.0f;
angle = angle_dot = 0.0f;
p[0][0] = 1.0f;
p[0][1] = 0.0f;
p[1][0] = 0.0f;
p[1][1] = 1.0f;
pdot[0] = 0.0f;
pdot[1] = 0.0f;
pdot[2] = 0.0f;
pdot[3] = 0.0f;
}
void kalmanfilter::getvalue(double angle_m, double gyro_m, double dt, double &outangle, double &outangledot)
{
angle+=(gyro_m-q_bias) * dt;
angle_err = angle_m - angle;
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;
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;
outangle = angle;
outangledot = angle_dot;
}
#endif
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯