hpm_smc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2021-2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SMC_H
  8. #define HPM_SMC_H
  9. #if defined(__cplusplus)
  10. extern "C" {
  11. #endif /* __cplusplus */
  12. /**
  13. * @addtogroup mcl_smc_interface HPMicro MCL SMC APIs
  14. * @ingroup middleware_mcl_interfaces
  15. * @{
  16. *
  17. */
  18. /**
  19. * @brief smc phase locked loop parameters
  20. *
  21. */
  22. typedef struct hpm_smc_pll_para {
  23. float theta_last; /**< the last angle of the filter */
  24. float err; /**< angle errors */
  25. float speedout; /**< speed resulting from phase locked loop processing */
  26. float theta; /**< electrical angle */
  27. float kp; /**< pid kp */
  28. float ki; /**< pid ki */
  29. float max_i; /**< max integral */
  30. float min_i; /**< min integral */
  31. float max_o; /**< max output */
  32. float min_o; /**< min output */
  33. float mem; /**< integral storage */
  34. float theta0; /**< initial angle */
  35. float loop_in_sec; /**< cycle time in s */
  36. void (*func_getspd)(void *str);
  37. } hpm_smc_pll_para_t;
  38. #define BLDC_CONTROL_SMC_PLL_PARA_DEFAULTS {0, 0, 0, 0,\
  39. 0, 0, 0, 0,\
  40. 0, 0, 0, 0, 0,\
  41. NULL}
  42. /**
  43. * @brief sliding mode control(SMC)
  44. *
  45. */
  46. typedef struct hpm_mcl_para {
  47. float zero; /**< slip mode convergence */
  48. float ksmc; /**< Slide coefficient */
  49. float filter_coeff; /**< low-pass filter coefficients */
  50. float *ualpha; /**< alpha voltage */
  51. float *ubeta; /**< beta voltage */
  52. float *ialpha; /**< alpha current */
  53. float *ibeta; /**< beta current */
  54. float ialpha_mem; /**< Internal Data */
  55. float ibeta_mem; /**< Internal Data */
  56. float alpha_cal; /**< Internal Data */
  57. float zalpha_cal; /**< Internal Data */
  58. float beta_cal; /**< Internal Data */
  59. float zbeta_cal; /**< Internal Data */
  60. hpm_motor_para_t *i_motorpar; /**< Motor parameters @ref hpm_motor_para_t */
  61. void (*func_smc)(void *str); /**< Slide-mode controller */
  62. } hpm_mcl_para_t;
  63. #define BLDC_CONTROL_SMC_PARA_DEFAULTS {0, 0, 0, NULL, NULL,\
  64. NULL, NULL, 0, 0, 0,\
  65. 0, 0, 0,\
  66. NULL,\
  67. NULL}
  68. /**
  69. * @brief Sliding mode control function
  70. *
  71. * @param[inout] par @ref hpm_mcl_para_t
  72. */
  73. void hpm_mcl_smc_pos_cal(hpm_mcl_para_t *par);
  74. /**
  75. * @brief Calculation of sliding mode control static parameters
  76. *
  77. * @param[inout] par @ref hpm_motor_para_t
  78. */
  79. void hpm_mcl_smc_const_cal(hpm_motor_para_t *par);
  80. /**
  81. * @brief Phase-locked loop filtering of angles after smc processing
  82. *
  83. * @param[in] par @ref hpm_mcl_para_t
  84. * @param[inout] pll @ref hpm_smc_pll_para_t
  85. * @return angle
  86. */
  87. float hpm_mcl_smc_pll(hpm_mcl_para_t *par, hpm_smc_pll_para_t *pll);
  88. /**
  89. * @brief smc current loop
  90. *
  91. * @param[inout] par @ref BLDC_CONTROL_FOC_PARA
  92. * @param[inout] smc @ref hpm_mcl_para_t
  93. * @param[inout] pll @ref hpm_smc_pll_para_t
  94. * @param[in] is_smc_enable true: smc enable, false: smc disable
  95. */
  96. void hpm_mcl_smc_loop(BLDC_CONTROL_FOC_PARA *par, hpm_mcl_para_t *smc, hpm_smc_pll_para_t *pll, uint8_t *is_smc_enable);
  97. #if defined(__cplusplus)
  98. }
  99. #endif /* __cplusplus */
  100. /**
  101. * @}
  102. *
  103. */
  104. #endif