mc_config.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef _MC_CONFIG_H__
  2. #define _MC_CONFIG_H__
  3. #include "os/os_types.h"
  4. #include "autogen_config.h"
  5. #define CONFIG_MAX_GEARS 4
  6. #define CONFIG_TEMP_PROT_NUM 3
  7. #define CONFIG_GEAR_SPEED_TRQ_NUM 10
  8. #define CONFIG_EBRK_LVL_NUM 10
  9. typedef enum {
  10. PID_ID_ID,
  11. PID_IQ_ID,
  12. PID_Vel_ID,
  13. PID_VelLim_ID,
  14. PID_IDCLim_ID,
  15. PID_AutoHold_ID,
  16. PID_Max_ID,
  17. PID_EPM_ExtID,
  18. }PID_id_t;
  19. typedef struct
  20. {
  21. u8 poles;
  22. float ld;
  23. float lq;
  24. float rs;
  25. float flux;
  26. float nor_pll_band;
  27. float epm_pll_band;
  28. float pos_pll_band;
  29. bool fw_enable;
  30. u8 fw_duty_start; //0-100
  31. u16 max_fw_id;
  32. u16 max_torque;
  33. s16 encoder_offset;
  34. }mot_params_t;
  35. typedef struct {
  36. float kp;
  37. float ki;
  38. float kd;
  39. }pid_t;
  40. typedef struct {
  41. s16 max_dc_vol;
  42. s16 min_dc_vol;
  43. s16 max_phase_curr;
  44. s16 max_torque;
  45. s16 max_rpm;
  46. s16 max_epm_rpm;
  47. s16 max_epm_torque;
  48. s16 max_epm_back_rpm;
  49. s16 max_epm_back_torque;
  50. s16 max_ebrk_torque;
  51. s16 max_idc;
  52. s16 max_autohold_torque;
  53. s16 dq_loop_bandwith;
  54. float thro_start_vol;
  55. float thro_end_vol;
  56. float thro_min_vol;
  57. float thro_max_vol;
  58. u16 thro_dec_time;
  59. pid_t pid[PID_Max_ID];
  60. pid_t epm_pid;
  61. u8 _pad[64];
  62. }controller_t;
  63. typedef struct {
  64. bool auto_hold;
  65. bool brk_shut_power;
  66. bool tcs_enable;
  67. }settings_t;
  68. typedef struct {
  69. s16 max_speed; //最大速度, rpm
  70. s16 max_torque; //最大扭矩
  71. s16 max_idc; //最大母线电流
  72. u16 zero_accl; //零速启动扭矩给定时间,防止翘头
  73. u16 accl_time; //加速的扭矩斜坡时间
  74. u8 torque[CONFIG_GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比)
  75. }gear_t;
  76. typedef struct {
  77. s16 enter_pointer;
  78. s16 exit_pointer;
  79. s16 limit_value;
  80. }limiter_t;
  81. typedef struct {
  82. s16 torque;
  83. u16 time;
  84. }eng_reco_l_t;
  85. typedef struct {
  86. float low;
  87. float high;
  88. float min_step;
  89. float normal_step;
  90. }cross_zero_t;
  91. typedef struct {
  92. u8 version;
  93. mot_params_t m;
  94. controller_t c;
  95. settings_t s;
  96. gear_t g_n[CONFIG_MAX_GEARS];
  97. gear_t g_l[CONFIG_MAX_GEARS];
  98. limiter_t p_mot[CONFIG_TEMP_PROT_NUM];
  99. limiter_t p_mos[CONFIG_TEMP_PROT_NUM];
  100. limiter_t p_vol;
  101. eng_reco_l_t e_r[CONFIG_EBRK_LVL_NUM];
  102. cross_zero_t cz;
  103. u16 crc;
  104. }mc_config;
  105. extern mc_config conf;
  106. bool mc_conf_begin_recv(int len);
  107. bool mc_conf_recv_data(u8 *buff, int offset, int len);
  108. bool mc_conf_finish_recv(u16 crc);
  109. bool mc_conf_begin_send(void);
  110. int mc_conf_send_data(u8 *buff, int offset, int len);
  111. int mc_conf_finish_send(u8 *buff);
  112. void mc_conf_load(void);
  113. void mc_conf_decode_configs(void);
  114. int mc_conf_encode_configs(u8 *buff);
  115. void mc_conf_save(void);
  116. void mc_conf_set_pid(u8 id, pid_t *pid);
  117. void mc_conf_get_pid(u8 id, pid_t *pid);
  118. bool mc_conf_set_gear(u8 mode, u8 *data, int len);
  119. int mc_conf_get_gear(u8 mode, u8 *data);
  120. bool mc_conf_set_limter(u8 *data, int len);
  121. int mc_conf_get_limter(u8 *data);
  122. void mc_conf_init(void);
  123. int mc_conf_decode_pid(pid_t *pid, u8 *buff);
  124. int mc_conf_encode_pid(pid_t *pid, u8 *buff);
  125. static mc_config *mc_conf(void) {
  126. return &conf;
  127. }
  128. #endif /* _MC_CONFIG_H__ */