nv_storage.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef _NV_Storage_H__
  2. #define _NV_Storage_H__
  3. #include "os/os_types.h"
  4. #include "foc/core/PMSM_FOC_Core.h"
  5. #include "foc/commands.h"
  6. #pragma pack (push,1)
  7. typedef struct {
  8. float s_PhaseCurrLim;
  9. float s_maxDCVol;
  10. float s_minDCVol;
  11. float s_maxRPM;
  12. float s_maxEpmRPM;
  13. float s_maxEpmPhaseCurrLim;
  14. float s_maxTorque;
  15. float s_PhaseCurreBrkLim;
  16. float s_iDCeBrkLim;
  17. float s_LimitiDC;
  18. float n_currentBand; //电流环带宽
  19. float n_minThroVol;
  20. float n_maxThroVol;
  21. u8 n_brkShutPower;
  22. u8 n_autoHold;
  23. u32 n_acc_time;
  24. u32 n_dec_time;
  25. u32 n_ebrk_time;
  26. u8 n_FwEnable;
  27. pid_conf_t pid_conf[PID_Max_id];
  28. u16 crc16;
  29. }foc_params_t;
  30. typedef struct {
  31. u8 mot_nr;
  32. u8 poles;
  33. float r;
  34. float ld;
  35. float lq;
  36. float flux_linkage;
  37. float back_emf;
  38. s32 hall_table[8];
  39. float offset;
  40. float est_pll_band; //normal工作模式下的pll带宽
  41. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  42. u16 crc16;
  43. }motor_params_t;
  44. typedef struct {
  45. u16 u_maxRPM;
  46. u16 u_maxTorque;
  47. u16 u_maxIdc;
  48. u16 u_accTime;//加速曲线
  49. }mc_gear_t;
  50. #define CONFIG_MAX_GEAR_NUM 5
  51. typedef struct {
  52. mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM];
  53. mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM];
  54. u16 crc16;
  55. }mc_gear_config_t;
  56. #define MAX_TRQ_POINTS 60
  57. #define MAX_SPD_POINTS 100
  58. #define TBL_TRQ_INTVAL 10
  59. #define TBL_SPD_INTVAL 100
  60. struct lut_dq {
  61. s16 d;
  62. s16 q;
  63. };
  64. typedef struct {
  65. struct lut_dq dq[MAX_TRQ_POINTS][MAX_SPD_POINTS];
  66. u16 magic;
  67. u16 crc16;
  68. }torque_lut_t;
  69. #pragma pack(pop)
  70. #define motorParam_idx_0 3
  71. #define motorParam_idx_1 (motorParam_idx_0 + 1)
  72. #define focParam_idx_0 (motorParam_idx_0 + 2)
  73. #define focParam_idx_1 (motorParam_idx_0 + 3)
  74. #define trq_Tbl_idx (focParam_idx_1 + 1)
  75. #define trq_Tbl_size (30)
  76. #define gear_config_idx_0 (trq_Tbl_idx + trq_Tbl_size)
  77. #define gear_config_idx_1 (gear_config_idx_0 + 1)
  78. void nv_storage_init(void);
  79. motor_params_t *nv_get_motor_params(void);
  80. foc_params_t *nv_get_foc_params(void);
  81. mc_gear_config_t *nv_get_gear_configs(void);
  82. void nv_save_angle_offset(float offset);
  83. void nv_save_motor_params(void);
  84. void nv_read_motor_params(void);
  85. void nv_save_foc_params(void);
  86. void nv_read_foc_params(void);
  87. void nv_save_hall_table(s32 *hall_table);
  88. void nv_set_pid(u8 id, pid_conf_t *pid);
  89. void nv_get_pid(u8 id, pid_conf_t *pid);
  90. void nv_set_hwbrake_mode(u8 mode);
  91. void nv_set_throttle_vol(float min, float max);
  92. void nv_set_ebrake_current(float phase_curr, float dc_curr);
  93. torque_lut_t *nv_get_trq_tlb(void);
  94. #endif /* _NV_Storage_H__ */