mc_config.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. int vehicle_w;
  30. int wheel_c;
  31. float gear_ratio;
  32. u16 max_fw_id;
  33. u16 max_torque;
  34. s16 encoder_offset;
  35. }mot_params_t;
  36. typedef struct {
  37. float kp;
  38. float ki;
  39. float kd;
  40. }pid_t;
  41. typedef struct {
  42. s16 max_dc_vol;
  43. s16 min_dc_vol;
  44. s16 max_phase_curr;
  45. s16 max_torque;
  46. s16 max_rpm;
  47. s16 max_epm_rpm;
  48. s16 max_epm_torque;
  49. s16 max_epm_back_rpm;
  50. s16 max_epm_back_torque;
  51. s16 max_ebrk_torque;
  52. s16 max_idc;
  53. s16 max_autohold_torque;
  54. s16 dq_loop_bandwith;
  55. float thro_start_vol;
  56. float thro_end_vol;
  57. float thro_min_vol;
  58. float thro_max_vol;
  59. u16 thro_dec_time;
  60. pid_t pid[PID_Max_ID];
  61. pid_t epm_pid;
  62. u8 _pad[64];
  63. }controller_t;
  64. typedef struct {
  65. bool auto_hold;
  66. bool brk_shut_power;
  67. bool tcs_enable;
  68. }settings_t;
  69. typedef struct {
  70. s16 max_speed; //最大速度, rpm
  71. s16 max_torque; //最大扭矩
  72. s16 max_idc; //最大母线电流
  73. u16 zero_accl; //零速启动扭矩给定时间,防止翘头
  74. u16 accl_time; //加速的扭矩斜坡时间
  75. u8 torque[CONFIG_GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比)
  76. }gear_t;
  77. typedef struct {
  78. s16 enter_pointer;
  79. s16 exit_pointer;
  80. s16 limit_value;
  81. }limiter_t;
  82. typedef struct {
  83. s16 torque;
  84. u16 time;
  85. }eng_reco_l_t;
  86. typedef struct {
  87. float low;
  88. float high;
  89. float min_step;
  90. float normal_step;
  91. }cross_zero_t;
  92. typedef struct {
  93. u8 version;
  94. mot_params_t m;
  95. controller_t c;
  96. settings_t s;
  97. gear_t g_n[CONFIG_MAX_GEARS];
  98. gear_t g_l[CONFIG_MAX_GEARS];
  99. limiter_t p_mot[CONFIG_TEMP_PROT_NUM];
  100. limiter_t p_mos[CONFIG_TEMP_PROT_NUM];
  101. limiter_t p_vol;
  102. eng_reco_l_t e_r[CONFIG_EBRK_LVL_NUM];
  103. cross_zero_t cz;
  104. u16 crc;
  105. }mc_config;
  106. extern mc_config conf;
  107. bool mc_conf_begin_recv(int len);
  108. bool mc_conf_recv_data(u8 *buff, int offset, int len);
  109. bool mc_conf_finish_recv(u16 crc);
  110. bool mc_conf_begin_send(void);
  111. int mc_conf_send_data(u8 *buff, int offset, int len);
  112. int mc_conf_finish_send(u8 *buff);
  113. void mc_conf_load(void);
  114. void mc_conf_decode_configs(void);
  115. int mc_conf_encode_configs(u8 *buff);
  116. void mc_conf_save(void);
  117. void mc_conf_set_pid(u8 id, pid_t *pid);
  118. void mc_conf_get_pid(u8 id, pid_t *pid);
  119. bool mc_conf_set_gear(u8 mode, u8 *data, int len);
  120. int mc_conf_get_gear(u8 mode, u8 *data);
  121. bool mc_conf_set_limter(u8 *data, int len);
  122. int mc_conf_get_limter(u8 *data);
  123. void mc_conf_init(void);
  124. int mc_conf_decode_pid(pid_t *pid, u8 *buff);
  125. int mc_conf_encode_pid(pid_t *pid, u8 *buff);
  126. static mc_config *mc_conf(void) {
  127. return &conf;
  128. }
  129. #endif /* _MC_CONFIG_H__ */