encoder.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. float 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. u32 cpr;
  22. s16 last_cnt;
  23. u32 b_index_cnt;
  24. u32 last_us;
  25. s8 direction; //motor running dir, 逆时针 正,顺时针负
  26. float est_vel_counts; //每秒多少个计数
  27. float est_angle_counts;
  28. float rpm;
  29. //u8 *encoder_off_count;
  30. //s16 *encoder_off_map;
  31. bool produce_error;
  32. s16 last_delta_cnt;
  33. u16 start_dianostic_cnt;
  34. u8 enc_maybe_err;
  35. u32 pwm_time_ms;
  36. }encoder_t;
  37. #define ENCODER_NO_ERR 0
  38. #define ENCODER_PWM_ERR 1
  39. #define ENCODER_AB_ERR 2
  40. void encoder_init(void);
  41. void encoder_init_clear(void);
  42. float encoder_get_theta(void);
  43. float encoder_get_speed(void);
  44. void encoder_set_direction(s8 direction);
  45. float encoder_get_vel_count(void);
  46. void encoder_lock_position(bool enable);
  47. float encoder_get_pwm_angle(void);
  48. float encoder_zero_phase_detect(float *enc_off);
  49. bool ENC_Check_error(void);
  50. float encoder_get_abi_angle(void);
  51. float encoder_get_position(void);
  52. void encoder_clear_cnt_offset(void);
  53. u32 encoder_get_cnt_offset(void);
  54. bool encoder_get_cali_error(void);
  55. void encoder_epm_pll_band(bool epm);
  56. void encoder_produce_error(bool error);
  57. u8 encoder_may_error(void);
  58. #endif /* _Encoder_H__ */