| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /**
- @copyright None
- @file control.h
- @author Comment Vivre
- @date 2025-12-29
- @brief None
- */
- #ifndef __CONTROL_H_
- #define __CONTROL_H_
- typedef struct
- {
- enum
- {
- TEST_MOTOR_STOP = 0,
- TEST_MOTOR_START,
- TEST_FAULT
- } State; // 当前状态
- uint16_t RunTime; // 运行计时
- uint16_t StopTime; // 停机计时
- uint16_t NormalStartCount; // 成功运行计数
- } Start_Test_t;
- extern Start_Test_t xdata startTest;
- extern bool data isCtrlPowOn;
- typedef struct
- {
- enum
- {
- OPEN_MODE = 0,
- CLOSE_MODE
- } State; // 环路状态
- int8_t CalcTime; // 环路周期
- int16_t TargetRef; // 给定目标转速
- int16_t ActualRef; // 实际运算目标转速
- int16_t Inc; // 加速
- int16_t Dec; // 减速
- } Loop_Control_t;
- extern Loop_Control_t xdata loopCtrl;
- typedef struct
- {
- int16_t ActSpeedFlt; // 估算转速
- int16_t ISRef; // PI计算电流
- // 电流环给定电流
- int16_t IQRef;
- int16_t IDRef;
- // DQ轴输出电压
- int16_t UQFlt;
- int16_t UDFlt;
- // DQ轴实际电流
- int16_t IQFlt;
- int16_t IDFlt;
-
- int16_t Power; // 估算功率
- uint16_t BackEMF; // 反电动势
- int16_t BusCurr; // 估算电流
- // ADC采集数据
- uint16_t BusVoltage;
- uint16_t NTCTemper;
- uint16_t AlongVoltage;
- uint16_t ActBusCurr;
- } Estimated_Data_t;
- extern Estimated_Data_t xdata estData;
- typedef enum
- {
- SYS_READY = 0, // 就绪状态
- SYS_INIT = 1, // 初始化
- GET_CURR_OFFSET = 2, // 检测偏置电压
- PRE_DRIVER_CHARGE = 3, // 预充电
- TAIL_WIND = 4, // 风向检测
- MOTOR_POSI_CHECK = 5, // 初始位置检测
- MOTOR_ALIGN = 6, // 预定位
- MOTOR_START = 7, // 电机启动
- MOTOR_RUN = 8, // 电机运行
- MOTOR_STOP = 9, // 电机停止
- MOTOR_BREAK = 10, // 刹车
- MOTOR_FAULT = 11 // 故障
- } Sys_State_e;
- extern Sys_State_e xdata sysState;
- void Motor_Fault_Handle(void);
- void Get_Target_Ref(void);
- void Get_LPF_Value(void);
- void Loop_Control(void);
- void Motor_Control_State(void);
- #define MOTOR_START_TEST_SPEED _Q15(2000.0/MOTOR_SPEED_BASE)
- #define MOTOR_STOP_TIME 10000
- #define MOTOR_RUN_TIME 30000
- #endif
|