1
0

control.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. @copyright None
  3. @file control.h
  4. @author Comment Vivre
  5. @date 2025-12-29
  6. @brief None
  7. */
  8. #ifndef __CONTROL_H_
  9. #define __CONTROL_H_
  10. typedef struct
  11. {
  12. enum
  13. {
  14. TEST_MOTOR_STOP = 0,
  15. TEST_MOTOR_START,
  16. TEST_FAULT
  17. } State; // 当前状态
  18. uint16_t RunTime; // 运行计时
  19. uint16_t StopTime; // 停机计时
  20. uint16_t NormalStartCount; // 成功运行计数
  21. } Start_Test_t;
  22. extern Start_Test_t xdata startTest;
  23. extern bool data isCtrlPowOn;
  24. typedef struct
  25. {
  26. enum
  27. {
  28. OPEN_MODE = 0,
  29. CLOSE_MODE
  30. } LoopState; // 环路状态
  31. enum
  32. {
  33. COMP_RETURN_OIL = 0, // 回油阶段
  34. COMP_RUN
  35. } CompState;
  36. uint16_t ReturnOilCnt; // 回油计数
  37. int8_t CalcTime; // 环路周期
  38. int16_t TargetRef; // 给定目标转速
  39. int16_t ActualRef; // 实际运算目标转速
  40. int16_t Inc; // 加速
  41. int16_t Dec; // 减速
  42. } Loop_Control_t;
  43. extern Loop_Control_t xdata loopCtrl;
  44. typedef struct
  45. {
  46. int16_t ActSpeedFlt; // 估算转速
  47. int16_t ISRef; // PI计算电流
  48. // 电流环给定电流
  49. int16_t IQRef;
  50. int16_t IDRef;
  51. // DQ轴输出电压
  52. int16_t UQFlt;
  53. int16_t UDFlt;
  54. // DQ轴实际电流
  55. int16_t IQFlt;
  56. int16_t IDFlt;
  57. int16_t Power; // 估算功率
  58. uint16_t BackEMF; // 反电动势
  59. int16_t BusCurr; // 估算电流
  60. // ADC采集数据
  61. uint16_t BusVoltage;
  62. uint16_t NTCTemper;
  63. uint16_t AlongVoltage;
  64. uint16_t ActBusCurr;
  65. } Estimated_Data_t;
  66. extern Estimated_Data_t xdata estData;
  67. typedef enum
  68. {
  69. SYS_READY = 0, // 就绪状态
  70. SYS_INIT = 1, // 初始化
  71. GET_CURR_OFFSET = 2, // 检测偏置电压
  72. PRE_DRIVER_CHARGE = 3, // 预充电
  73. TAIL_WIND = 4, // 风向检测
  74. MOTOR_POSI_CHECK = 5, // 初始位置检测
  75. MOTOR_ALIGN = 6, // 预定位
  76. MOTOR_START = 7, // 电机启动
  77. MOTOR_RUN = 8, // 电机运行
  78. MOTOR_STOP = 9, // 电机停止
  79. MOTOR_BREAK = 10, // 刹车
  80. MOTOR_FAULT = 11 // 故障
  81. } Sys_State_e;
  82. extern Sys_State_e xdata sysState;
  83. void Motor_Fault_Handle(void);
  84. void Get_Target_Ref(void);
  85. void Get_LPF_Value(void);
  86. void Loop_Control(void);
  87. void Motor_Control_State(void);
  88. #define MOTOR_START_TEST_SPEED _Q15(2000.0/MOTOR_SPEED_BASE)
  89. #define MOTOR_STOP_TIME 10000
  90. #define MOTOR_RUN_TIME 30000
  91. #endif