control.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. } State; // 环路状态
  31. int8_t CalcTime; // 环路周期
  32. int16_t TargetRef; // 给定目标转速
  33. int16_t ActualRef; // 实际运算目标转速
  34. int16_t Inc; // 加速
  35. int16_t Dec; // 减速
  36. } Loop_Control_t;
  37. extern Loop_Control_t xdata loopCtrl;
  38. typedef struct
  39. {
  40. int16_t ActSpeedFlt; // 估算转速
  41. int16_t ISRef; // PI计算电流
  42. // 电流环给定电流
  43. int16_t IQRef;
  44. int16_t IDRef;
  45. // DQ轴输出电压
  46. int16_t UQFlt;
  47. int16_t UDFlt;
  48. // DQ轴实际电流
  49. int16_t IQFlt;
  50. int16_t IDFlt;
  51. int16_t Power; // 估算功率
  52. uint16_t BackEMF; // 反电动势
  53. int16_t BusCurr; // 估算电流
  54. // ADC采集数据
  55. uint16_t BusVoltage;
  56. uint16_t NTCTemper;
  57. uint16_t AlongVoltage;
  58. uint16_t ActBusCurr;
  59. } Estimated_Data_t;
  60. extern Estimated_Data_t xdata estData;
  61. typedef enum
  62. {
  63. SYS_READY = 0, // 就绪状态
  64. SYS_INIT = 1, // 初始化
  65. GET_CURR_OFFSET = 2, // 检测偏置电压
  66. PRE_DRIVER_CHARGE = 3, // 预充电
  67. TAIL_WIND = 4, // 风向检测
  68. MOTOR_POSI_CHECK = 5, // 初始位置检测
  69. MOTOR_ALIGN = 6, // 预定位
  70. MOTOR_START = 7, // 电机启动
  71. MOTOR_RUN = 8, // 电机运行
  72. MOTOR_STOP = 9, // 电机停止
  73. MOTOR_BREAK = 10, // 刹车
  74. MOTOR_FAULT = 11 // 故障
  75. } Sys_State_e;
  76. extern Sys_State_e xdata sysState;
  77. void Motor_Fault_Handle(void);
  78. void Get_Target_Ref(void);
  79. void Get_LPF_Value(void);
  80. void Loop_Control(void);
  81. void Motor_Control_State(void);
  82. #define MOTOR_START_TEST_SPEED _Q15(2000.0/MOTOR_SPEED_BASE)
  83. #define MOTOR_STOP_TIME 10000
  84. #define MOTOR_RUN_TIME 30000
  85. #endif