mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
add tutorial
This commit is contained in:
32
modules/algorithm/algorithm.md
Normal file
32
modules/algorithm/algorithm.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# algorithms
|
||||
|
||||
<p align='right'>neozng1@hnu.edu.cn</p>
|
||||
|
||||
> TODO:
|
||||
>
|
||||
> 1. 实现麦轮和全向轮的速度解算
|
||||
> 2. 实现LQR
|
||||
> 3. 实现一些通用的滤波器,如指数平均,窗平均,低通等
|
||||
> 4. 实现系统辨识
|
||||
|
||||
## 总览和使用
|
||||
|
||||
module层的algorithm提供了一些供其他模块以及app的应用层使用的算法,包括:
|
||||
|
||||
1. PID控制器`controller.h`
|
||||
2. crc8 crc16循环冗余校验
|
||||
3. 卡尔曼滤波器`kalman_filter.h`,可以通过用户自定义函数配置为扩展卡尔曼滤波
|
||||
4. `LQR.h`,线性二次型调节器
|
||||
5. `QuaterninoEKF.h`,用于`ins_task`的四元数姿态解算和扩展卡尔曼滤波融合
|
||||
6. `user_lib.h`,一些通用的函数,包括限幅、数据类型转换、角度弧度转换、快速符号判断以及优化开方等功能。多个模块都会使用的、不好区分的函数可以放置于此
|
||||
|
||||
## 代码结构
|
||||
|
||||
.c 为算法的实现,.h为算法对外接口的头文件
|
||||
|
||||
|
||||
|
||||
在编写应用的时候,你基本不会使用这里的函数,或是修改其实现。
|
||||
|
||||
若发现bug或需要增加功能,联系组长讨论。
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
******************************************************************************
|
||||
* @file user_lib.c
|
||||
* @author Wang Hongxi
|
||||
* @version V1.0.0
|
||||
* @author modified by neozng
|
||||
* @version 0.2 beta
|
||||
* @date 2021/2/18
|
||||
* @brief
|
||||
******************************************************************************
|
||||
@@ -24,7 +25,7 @@
|
||||
|
||||
uint8_t GlobalDebugMode = 7;
|
||||
|
||||
//快速开方
|
||||
// 快速开方
|
||||
float Sqrt(float x)
|
||||
{
|
||||
float y;
|
||||
@@ -51,29 +52,7 @@ float Sqrt(float x)
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 斜波函数计算,根据输入的值进行叠加, 输入单位为 /s 即一秒后增加输入的值
|
||||
* @author RM
|
||||
* @param[in] 斜波函数结构体
|
||||
* @param[in] 输入值
|
||||
* @retval 返回空
|
||||
*/
|
||||
float ramp_calc(ramp_function_source_t *ramp_source_type, float input)
|
||||
{
|
||||
ramp_source_type->input = input;
|
||||
ramp_source_type->out += ramp_source_type->input * ramp_source_type->frame_period;
|
||||
if (ramp_source_type->out > ramp_source_type->max_value)
|
||||
{
|
||||
ramp_source_type->out = ramp_source_type->max_value;
|
||||
}
|
||||
else if (ramp_source_type->out < ramp_source_type->min_value)
|
||||
{
|
||||
ramp_source_type->out = ramp_source_type->min_value;
|
||||
}
|
||||
return ramp_source_type->out;
|
||||
}
|
||||
|
||||
//绝对值限制
|
||||
// 绝对值限制
|
||||
float abs_limit(float num, float Limit)
|
||||
{
|
||||
if (num > Limit)
|
||||
@@ -87,7 +66,7 @@ float abs_limit(float num, float Limit)
|
||||
return num;
|
||||
}
|
||||
|
||||
//判断符号位
|
||||
// 判断符号位
|
||||
float sign(float value)
|
||||
{
|
||||
if (value >= 0.0f)
|
||||
@@ -100,7 +79,7 @@ float sign(float value)
|
||||
}
|
||||
}
|
||||
|
||||
//浮点死区
|
||||
// 浮点死区
|
||||
float float_deadband(float Value, float minValue, float maxValue)
|
||||
{
|
||||
if (Value < maxValue && Value > minValue)
|
||||
@@ -120,7 +99,7 @@ int16_t int16_deadline(int16_t Value, int16_t minValue, int16_t maxValue)
|
||||
return Value;
|
||||
}
|
||||
|
||||
//限幅函数
|
||||
// 限幅函数
|
||||
float float_constrain(float Value, float minValue, float maxValue)
|
||||
{
|
||||
if (Value < minValue)
|
||||
@@ -131,7 +110,7 @@ float float_constrain(float Value, float minValue, float maxValue)
|
||||
return Value;
|
||||
}
|
||||
|
||||
//限幅函数
|
||||
// 限幅函数
|
||||
int16_t int16_constrain(int16_t Value, int16_t minValue, int16_t maxValue)
|
||||
{
|
||||
if (Value < minValue)
|
||||
@@ -142,7 +121,7 @@ int16_t int16_constrain(int16_t Value, int16_t minValue, int16_t maxValue)
|
||||
return Value;
|
||||
}
|
||||
|
||||
//循环限幅函数
|
||||
// 循环限幅函数
|
||||
float loop_float_constrain(float Input, float minValue, float maxValue)
|
||||
{
|
||||
if (maxValue < minValue)
|
||||
@@ -169,9 +148,9 @@ float loop_float_constrain(float Input, float minValue, float maxValue)
|
||||
return Input;
|
||||
}
|
||||
|
||||
//弧度格式化为-PI~PI
|
||||
// 弧度格式化为-PI~PI
|
||||
|
||||
//角度格式化为-180~180
|
||||
// 角度格式化为-180~180
|
||||
float theta_format(float Ang)
|
||||
{
|
||||
return loop_float_constrain(Ang, -180.0f, 180.0f);
|
||||
|
||||
@@ -87,39 +87,9 @@ extern uint8_t GlobalDebugMode;
|
||||
#define VAL_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define VAL_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float input; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float out; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float min_value; //<2F><EFBFBD><DEB7><EFBFBD>Сֵ
|
||||
float max_value; //<2F><EFBFBD><DEB7><EFBFBD><EFBFBD>ֵ
|
||||
float frame_period; //ʱ<><CAB1><EFBFBD><EFBFBD>
|
||||
} ramp_function_source_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t Order;
|
||||
uint32_t Count;
|
||||
|
||||
float *x;
|
||||
float *y;
|
||||
|
||||
float k;
|
||||
float b;
|
||||
|
||||
float StandardDeviation;
|
||||
|
||||
float t[4];
|
||||
} Ordinary_Least_Squares_t;
|
||||
|
||||
//<2F><><EFBFBD>ٿ<EFBFBD><D9BF><EFBFBD>
|
||||
float Sqrt(float x);
|
||||
|
||||
//б<><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
void ramp_init(ramp_function_source_t *ramp_source_type, float frame_period, float max, float min);
|
||||
//б<><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float ramp_calc(ramp_function_source_t *ramp_source_type, float input);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float abs_limit(float num, float Limit);
|
||||
//<2F>жϷ<D0B6><CFB7><EFBFBD>λ
|
||||
|
||||
Reference in New Issue
Block a user