encoder.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef _Encoder_H__
  2. #define _Encoder_H__
  3. #include "foc/core/PI_Controller.h"
  4. typedef struct {
  5. bool b_index_found; //I 对齐
  6. s16 enc_offset;
  7. u32 enc_count_off;
  8. u8 motor_poles;
  9. float pwm_angle;
  10. u32 pwm_count;
  11. float abi_angle;
  12. float cali_angle;
  13. float interpolation;
  14. float pll_bandwidth_shadow;
  15. float pll_bandwidth;
  16. float position;
  17. PLL_t est_pll;
  18. bool b_timer_ov;
  19. bool b_lock_pos;
  20. bool b_cali_err;
  21. s16 cpr;
  22. s16 last_cnt;
  23. s16 align_cnt; //z 中断的时候的cnt数,需要计算角度的是时候处理这个align
  24. s16 align_cnt_final; //最终需要补偿的计数,类似对align_cnt 做低通滤波,防止Z信号的干扰导致错误补偿
  25. float align_step;
  26. s16 z_index_cnt;
  27. u32 z_index_counter;
  28. u32 z_index_err_counter;
  29. s16 pwm_start_cnt;
  30. u32 last_us;
  31. s8 direction; //motor running dir, 逆时针 正,顺时针负
  32. float est_vel_counts; //每秒多少个计数
  33. float est_vel_cnt_filter;
  34. float est_angle_counts;
  35. float rpm;
  36. //u8 *encoder_off_count;
  37. //s16 *encoder_off_map;
  38. bool produce_error;
  39. s16 last_delta_cnt;
  40. u32 start_dianostic_cnt;
  41. u8 enc_maybe_err;
  42. u32 pwm_time_ms;
  43. }encoder_t;
  44. #define ENCODER_NO_ERR 0
  45. #define ENCODER_PWM_ERR 1
  46. #define ENCODER_AB_ERR 2
  47. void encoder_init(void);
  48. void encoder_init_clear(void);
  49. float encoder_get_theta(bool detect_err);
  50. float encoder_get_speed(void);
  51. void encoder_set_direction(s8 direction);
  52. float encoder_get_vel_count(void);
  53. void encoder_lock_position(bool enable);
  54. float encoder_get_pwm_angle(void);
  55. float encoder_zero_phase_detect(float *enc_off);
  56. bool ENC_Check_error(void);
  57. float encoder_get_abi_angle(void);
  58. float encoder_get_position(void);
  59. void encoder_clear_cnt_offset(void);
  60. u32 encoder_get_cnt_offset(void);
  61. bool encoder_get_cali_error(void);
  62. void encoder_epm_pll_band(bool epm);
  63. void encoder_produce_error(bool error);
  64. u8 encoder_may_error(void);
  65. #endif /* _Encoder_H__ */