/** ****************************************************************************** * @file controller.h * @author Wang Hongxi * @version V1.1.3 * @date 2021/7/3 * @brief ****************************************************************************** * @attention * ****************************************************************************** */ #ifndef _CONTROLLER_H #define _CONTROLLER_H #include "main.h" #include "stdint.h" #include "memory.h" #include "stdlib.h" #include "bsp_dwt.h" #include "arm_math.h" #include #ifndef abs #define abs(x) ((x > 0) ? x : -x) #endif // PID 优化环节使能标志位 typedef enum { PID_IMPROVE_NONE = 0b000000000, // 无优化 0 PID_Integral_Limit = 0b000000001, // 积分限幅 1 PID_Derivative_On_Measurement = 0b000000010, // 微分先行 2 PID_Trapezoid_Intergral = 0b000000100, // 梯形积分 4 PID_Proportional_On_Measurement = 0b000001000, // 比例先行 8 PID_OutputFilter = 0b000010000, // 输出滤波 16 PID_ChangingIntegrationRate = 0b000100000, // 变速积分 32 PID_DerivativeFilter = 0b001000000, // 微分滤波 64 PID_ErrorHandle = 0b010000000, // 错误处理 128 PID_FeedForward = 0b100000000, // 前馈控制 256 } PID_Improvement_e; /* PID 报错类型枚举*/ typedef enum errorType_e { PID_ERROR_NONE = 0x00U, PID_MOTOR_BLOCKED_ERROR = 0x01U } ErrorType_e; typedef struct { uint64_t ERRORCount; ErrorType_e ERRORType; } PID_ErrorHandler_t; /* PID结构体 */ typedef struct { //---------------------------------- init config block // config parameter float Kp; float Ki; float Kd; float MaxOut; float DeadBand; // improve parameter PID_Improvement_e Improve; float IntegralLimit; // 积分限幅 float CoefA; // 变速积分 For Changing Integral float CoefB; // 变速积分 ITerm = Err*((A-abs(err)+B)/A) when B<|err|