| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #ifndef _MOTOR_H__
- #define _MOTOR_H__
- #include "os/os_types.h"
- #include "foc/core/PMSM_FOC_Core.h"
- #include "foc/motor/hall.h"
- #include "foc/motor/encoder.h"
- typedef struct {
- bool b_start;
- float throttle;
- bool b_ignor_throttle;
- bool b_calibrate;
- bool b_runStall; //是否堵转
- bool b_epm;
- EPM_Dir_t epm_dir;
- float lim_rpm;
- u32 runStall_time;
- s16 s_testAngle;
- s32 s_targetFix;
- s8 s_direction;
- u32 n_brake_errors;
- u8 mode;
- }motor_t;
- void mc_init(void);
- bool mc_start(u8 mode);
- bool mc_stop(void);
- void mc_encoder_off_calibrate(s16 vd);
- bool mc_throttle_released(void);
- bool mc_lock_motor(bool lock);
- void mc_set_spd_torque(s32 target);
- void mc_use_throttle(void);
- bool mc_current_sensor_calibrate(float current);
- bool mc_encoder_zero_calibrate(s16 vd);
- bool mc_set_foc_mode(u8 mode);
- bool mc_is_epm(void);
- bool mc_start_epm(bool epm);
- bool mc_start_epm_move(EPM_Dir_t dir);
- static __INLINE float motor_encoder_get_angle(void) {
- #ifdef USE_ENCODER_HALL
- return hall_sensor_get_theta();
- #elif defined (USE_ENCODER_ABI)
- return encoder_get_theta();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_update(void) {
- #ifdef USE_ENCODER_HALL
- hall_sensor_get_theta();
- #elif defined (USE_ENCODER_ABI)
- encoder_get_theta();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE float motor_encoder_get_speed(void) {
- #ifdef USE_ENCODER_HALL
- return hall_sensor_get_speed();
- #elif defined (USE_ENCODER_ABI)
- return encoder_get_speed();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE float motor_encoder_get_vel_count(void) {
- #ifdef USE_ENCODER_HALL
- return 0;
- #elif defined (USE_ENCODER_ABI)
- return encoder_get_vel_count();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_init(void) {
- #ifdef USE_ENCODER_HALL
- hall_sensor_init();
- #elif defined (USE_ENCODER_ABI)
- encoder_init();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_start(s8 direction) {
- #ifdef USE_ENCODER_HALL
- hall_sensor_clear(direction);
- #elif defined (USE_ENCODER_ABI)
- encoder_init_clear(direction);
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_offset(float angle) {
- #ifdef USE_ENCODER_HALL
- hall_detect_offset(angle);
- #elif defined (USE_ENCODER_ABI)
- encoder_detect_offset(angle);
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_offset_finish(void) {
- #ifdef USE_ENCODER_HALL
- hall_detect_offset_finish();
- #elif defined (USE_ENCODER_ABI)
- encoder_detect_finish();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE bool motor_encoder_offset_is_finish(void) {
- #ifdef USE_ENCODER_HALL
- return false;
- #elif defined (USE_ENCODER_ABI)
- return encoder_detect_finish();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE float motor_encoder_zero_phase_detect(void){
- #ifdef USE_ENCODER_HALL
- return 0.0f;
- #elif defined (USE_ENCODER_ABI)
- return encoder_zero_phase_detect();
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_set_direction(s8 dir) {
- #ifdef USE_ENCODER_HALL
- hall_set_direction(dir);
- #elif defined (USE_ENCODER_ABI)
- encoder_set_direction(dir);
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- static __INLINE void motor_encoder_lock_pos(bool lock) {
- #ifdef USE_ENCODER_HALL
-
- #elif defined (USE_ENCODER_ABI)
- encoder_lock_position(lock);
- #else
- #error "Postion sensor ERROR"
- #endif
- }
- #endif /* _MOTOR_H__ */
|