motor.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _MOTOR_H__
  2. #define _MOTOR_H__
  3. #include "os/os_types.h"
  4. #include "foc/core/PMSM_FOC_Core.h"
  5. #include "foc/motor/hall.h"
  6. #include "foc/motor/encoder.h"
  7. typedef struct {
  8. bool b_start;
  9. float throttle;
  10. bool b_ignor_throttle;
  11. s16 s_testAngle;
  12. s32 s_targetFix;
  13. s8 s_direction;
  14. }motor_t;
  15. void mc_init(void);
  16. bool mc_start(u8 mode);
  17. bool mc_stop(void);
  18. void mc_encoder_calibrate(s16 vd);
  19. bool mc_throttle_released(void);
  20. bool mc_lock_motor(bool lock);
  21. void mc_set_spd_torque(s32 target);
  22. void mc_use_throttle(void);
  23. static __INLINE float motor_encoder_get_angle(void) {
  24. #ifdef USE_ENCODER_HALL
  25. return hall_sensor_get_theta();
  26. #elif defined (USE_ENCODER_ABI)
  27. return encoder_get_theta();
  28. #else
  29. #error "Postion sensor ERROR"
  30. #endif
  31. }
  32. static __INLINE float motor_encoder_get_speed(void) {
  33. #ifdef USE_ENCODER_HALL
  34. return hall_sensor_get_speed();
  35. #elif defined (USE_ENCODER_ABI)
  36. return encoder_get_speed();
  37. #else
  38. #error "Postion sensor ERROR"
  39. #endif
  40. }
  41. static __INLINE void motor_encoder_init(void) {
  42. #ifdef USE_ENCODER_HALL
  43. hall_sensor_init();
  44. #elif defined (USE_ENCODER_ABI)
  45. encoder_init();
  46. #else
  47. #error "Postion sensor ERROR"
  48. #endif
  49. }
  50. static __INLINE void motor_encoder_start(s8 direction) {
  51. #ifdef USE_ENCODER_HALL
  52. hall_sensor_clear(direction);
  53. #elif defined (USE_ENCODER_ABI)
  54. encoder_init_clear(direction);
  55. #else
  56. #error "Postion sensor ERROR"
  57. #endif
  58. }
  59. static __INLINE void motor_encoder_offset(float angle) {
  60. #ifdef USE_ENCODER_HALL
  61. hall_detect_offset(angle);
  62. #elif defined (USE_ENCODER_ABI)
  63. encoder_detect_offset(angle);
  64. #else
  65. #error "Postion sensor ERROR"
  66. #endif
  67. }
  68. static __INLINE void motor_encoder_offset_finish(void) {
  69. #ifdef USE_ENCODER_HALL
  70. hall_detect_offset_finish();
  71. #elif defined (USE_ENCODER_ABI)
  72. #else
  73. #error "Postion sensor ERROR"
  74. #endif
  75. }
  76. static __INLINE void motor_encoder_set_direction(s8 dir) {
  77. #ifdef USE_ENCODER_HALL
  78. hall_set_direction(dir);
  79. #elif defined (USE_ENCODER_ABI)
  80. encoder_set_direction(dir);
  81. #else
  82. #error "Postion sensor ERROR"
  83. #endif
  84. }
  85. #endif /* _MOTOR_H__ */