mc_config.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_id_t;
  18. typedef struct
  19. {
  20. u8 poles;
  21. float ld;
  22. float lq;
  23. float rs;
  24. float flux;
  25. float nor_pll_band;
  26. float epm_pll_band;
  27. float pos_pll_band;
  28. int vehicle_w;
  29. int wheel_c;
  30. float gear_ratio;
  31. u16 max_fw_id;
  32. u16 max_torque;
  33. s16 encoder_offset;
  34. }motor_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. }controller_t;
  61. typedef struct {
  62. bool auto_hold;
  63. bool brk_shut_power;
  64. bool tcs_enable;
  65. }settings_t;
  66. typedef struct {
  67. s16 max_speed; //最大速度, rpm
  68. s16 max_torque; //最大扭矩
  69. s16 max_idc; //最大母线电流
  70. u16 zero_accl; //零速启动扭矩给定时间,防止翘头
  71. u16 accl_time; //加速的扭矩斜坡时间
  72. u8 torque[CONFIG_GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比)
  73. }gear_t;
  74. typedef struct {
  75. s16 enter_pointer;
  76. s16 exit_pointer;
  77. s16 limit_value;
  78. }limiter_t;
  79. typedef struct {
  80. s16 torque;
  81. u16 time;
  82. }eng_reco_l_t;
  83. typedef struct {
  84. float low;
  85. float high;
  86. float min_step;
  87. float normal_step;
  88. }cross_zero_t;
  89. typedef struct {
  90. u8 version;
  91. motor_t m;
  92. controller_t c;
  93. settings_t s;
  94. gear_t g_n[CONFIG_MAX_GEARS];
  95. gear_t g_l[CONFIG_MAX_GEARS];
  96. limiter_t p_mot[CONFIG_TEMP_PROT_NUM];
  97. limiter_t p_mos[CONFIG_TEMP_PROT_NUM];
  98. limiter_t p_vol;
  99. eng_reco_l_t e_r[CONFIG_EBRK_LVL_NUM];
  100. cross_zero_t cz;
  101. u16 crc;
  102. }mc_config;
  103. extern mc_config conf;
  104. bool mc_conf_begin_recv(int len);
  105. bool mc_conf_recv_data(u8 *buff, int offset, int len);
  106. bool mc_conf_finish_recv(u16 crc);
  107. bool mc_conf_begin_send(void);
  108. int mc_conf_send_data(u8 *buff, int offset, int len);
  109. int mc_conf_finish_send(u8 *buff);
  110. void mc_conf_load(void);
  111. void mc_conf_decode_configs(void);
  112. int mc_conf_encode_configs(u8 *buff);
  113. void mc_conf_save(void);
  114. void mc_conf_set_pid(u8 id, pid_t *pid);
  115. void mc_conf_get_pid(u8 id, pid_t *pid);
  116. bool mc_conf_set_gear(u8 mode, u8 *data, int len);
  117. int mc_conf_get_gear(u8 mode, u8 *data);
  118. bool mc_conf_set_limter(u8 *data, int len);
  119. int mc_conf_get_limter(u8 *data);
  120. void mc_conf_init(void);
  121. int mc_conf_decode_pid(pid_t *pid, u8 *buff);
  122. int mc_conf_encode_pid(pid_t *pid, u8 *buff);
  123. static mc_config *mc_conf(void) {
  124. return &conf;
  125. }
  126. #endif /* _MC_CONFIG_H__ */