cmdgen.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * @file cmdgen.h
  3. * @author Zhang, Kai(zhangkai71@midea.com)
  4. * @brief Time task control
  5. * @version 0.1
  6. * @date 2021-09-27
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. #ifndef CMDGEN_H
  12. #define CMDGEN_H
  13. #include "typedefine.h"
  14. /****************************************
  15. *
  16. * Definitions & Macros
  17. *
  18. ****************************************/
  19. #define CMD_GEN_OUT_DEFAULT \
  20. { \
  21. 0, 0, 0, 1, 1, Constant \
  22. } // Default value of CMD_GEN_OUT
  23. #define CMD_GEN_COF_DEFAULT \
  24. { \
  25. 36864, 2730, 16384, 2730, 16384, 33408, 22272, 13344, 33408, 22272, 13344, 55924, 33554, 0 \
  26. } // Default value of CMD_GEN_COF
  27. /***************************************
  28. *
  29. * Type Definations
  30. *
  31. ***************************************/
  32. /**
  33. * @brief torque command input
  34. *
  35. */
  36. typedef struct
  37. {
  38. SLONG slRefRpm; // unit: rpm
  39. SWORD swAccRpmps; // unit: rpm/s
  40. } CMD_GEN_IN;
  41. /**
  42. * @brief torque command coefficient input
  43. *
  44. */
  45. typedef struct
  46. {
  47. UWORD uwRefMaxRpm; // unit: rpm, Maximum speed
  48. UWORD uwAccSw1Rpm; // unit: rpm, Speed switch 1 in acceleration
  49. UWORD uwAccSw2Rpm; // unit: rpm, Speed switch 2 in acceleration
  50. UWORD uwDecSw1Rpm; // unit: rpm, Speed switch 1 in deceleration
  51. UWORD uwDecSw2Rpm; // unit: rpm, Speed switch 2 in deceleration
  52. SWORD swAccLim1Rpmps; // unit: rpm/s, Speed acceleration limit 1
  53. SWORD swAccLim2Rpmps; // unit: rpm/s, Speed acceleration limit 2
  54. SWORD swAccLim3Rpmps; // unit: rpm/s, Speed acceleration limit 3
  55. SWORD swDecLim1Rpmps; // unit: rpm/s, Speed deceleration limit 1
  56. SWORD swDecLim2Rpmps; // unit: rpm/s, Speed deceleration limit 2
  57. SWORD swDecLim3Rpmps; // unit: rpm/s, Speed deceleration limit 3
  58. UWORD uwFTbsHz; // unit: Hz , TBS freq
  59. UWORD uwBaseRpm; // unit: rpm , Speed base
  60. } CMD_GEN_COFIN;
  61. typedef enum CmdDpdSta
  62. {
  63. Decelerate = 0,
  64. Accelerate = 1,
  65. Constant = 2
  66. } CMD_SPD_STATUS;
  67. /**
  68. * @brief torque command output
  69. *
  70. */
  71. typedef struct
  72. {
  73. SWORD swSpdCmdRefPu; // Q15, Speed Pu reference from uart
  74. SWORD swSpdRefPu; // Q15, Speed reference output per tbs
  75. SLONG slSpdRefPu; // Q31, Speed reference output per tbs
  76. SWORD swSpdCmdDir; // speed command direction
  77. SWORD swSpdRefDirNow; // Current speed reference direction
  78. CMD_SPD_STATUS enSpdStatus; // Speed status
  79. } CMD_GEN_OUT;
  80. /**
  81. * @brief torque command coefficient
  82. *
  83. */
  84. typedef struct
  85. {
  86. ULONG ulSpdRefMaxPu; // Q15, Maximum speed
  87. ULONG ulAccSpdSw1Pu; // Q15, Speed switch 1 in acceleration
  88. ULONG ulAccSpdSw2Pu; // Q15, Speed switch 2 in acceleration
  89. ULONG ulDecSpdSw1Pu; // Q15, Speed switch 1 in deceleration
  90. ULONG ulDecSpdSw2Pu; // Q15, Speed switch 2 in deceleration
  91. SLONG slAccLim1Pu; // Q31, Speed acceleration limit 1
  92. SLONG slAccLim2Pu; // Q31, Speed acceleration limit 2
  93. SLONG slAccLim3Pu; // Q31, Speed acceleration limit 3
  94. SLONG slDecLim1Pu; // Q31, Speed deceleration limit 1
  95. SLONG slDecLim2Pu; // Q31, Speed deceleration limit 2
  96. SLONG slDecLim3Pu; // Q31, Speed deceleration limit 3
  97. // UWORD uwFTbsHz; //unit: Hz , TBS freq
  98. UWORD uwFTbsHzInv; // Q25, Tbs frequence inverse
  99. UWORD uwBaseRpmInv; // Q25, Speed base inverse
  100. UWORD uwBaseRpm; // Q0,Speed base
  101. } CMD_GEN_COF;
  102. typedef struct
  103. {
  104. CMD_GEN_COF Coef; ///< Coefficient of current PI controller
  105. CMD_GEN_OUT Out; ///< Output of current PU controller
  106. } CMD_CONTROL;
  107. /****************************************
  108. *
  109. * Exported variable
  110. *
  111. ****************************************/
  112. /****************************************
  113. *
  114. * RAM ALLOCATION (N/A)
  115. *
  116. ****************************************/
  117. /***************************************
  118. *
  119. * Function Definations
  120. *
  121. ***************************************/
  122. /**
  123. * @brief
  124. *
  125. * @param in
  126. * @param coef
  127. * @param out
  128. */
  129. void cmd_voCmdGen(CMD_GEN_IN *in, CMD_CONTROL *s);
  130. void cmd_voCmdDirGen(CMD_GEN_IN *in, CMD_CONTROL *s);
  131. void cmd_voCmdGenCoef(CMD_GEN_COFIN *in, CMD_CONTROL *s);
  132. void cmd_voCmdGenInit(CMD_CONTROL *s);
  133. #endif