mc_config.h 3.1 KB

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