encoder.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef _Encoder_H__
  2. #define _Encoder_H__
  3. #include "bsp/enc_intf.h"
  4. #include "foc/core/PI_Controller.h"
  5. typedef struct {
  6. bool b_index_found; //I 对齐
  7. float enc_offset;
  8. u8 motor_poles;
  9. float pwm_angle;
  10. u32 pwm_count;
  11. float abi_angle;
  12. float interpolation;
  13. float pll_bandwidth_shadow;
  14. float pll_bandwidth;
  15. float postion;
  16. PLL_t est_pll;
  17. bool b_timer_ov;
  18. bool b_lock_pos;
  19. u32 cpr;
  20. u32 last_cnt;
  21. u32 b_index_cnt;
  22. u32 last_us;
  23. s8 enc_dir; //encoder count dir UP or DOWN
  24. s8 direction; //motor running dir, 逆时针 正,顺时针负
  25. u16 p_dir_cnt;
  26. u16 n_dir_cnt;
  27. float est_vel_counts; //每秒多少个计数
  28. float est_angle_counts;
  29. float rpm;
  30. }encoder_t;
  31. void encoder_init(void);
  32. void encoder_init_clear(s8 direction);
  33. float encoder_get_theta(void);
  34. float encoder_get_speed(void);
  35. void encoder_detect_offset(float angle, bool r);
  36. void encoder_set_direction(s8 direction);
  37. float encoder_get_vel_count(void);
  38. void encoder_lock_position(bool enable);
  39. float encoder_detect_finish(bool r);
  40. float encoder_get_pwm_angle(void);
  41. void encoder_detect_off_finished(void);
  42. #endif /* _Encoder_H__ */