mc_config.h 3.0 KB

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