#ifndef _HALL_SENSOR_H__ #define _HALL_SENSOR_H__ #include "libs/types.h" #include "hal/hal.h" #define NEGATIVE (int8_t)-1 #define POSITIVE (int8_t)1 #define STATE_0 (uint8_t)0 #define STATE_1 (uint8_t)1 #define STATE_2 (uint8_t)2 #define STATE_3 (uint8_t)3 #define STATE_4 (uint8_t)4 #define STATE_5 (uint8_t)5 #define STATE_6 (uint8_t)6 #define STATE_7 (uint8_t)7 #define THETA_NONE (float)0xFFFF typedef struct { bool alignmnet; float theta; float est_theta; float e_rpm; //当前的电角度, 单位:RPM float e_filted_rpm; //滤波后的电角度 u8 state; u32 ticks; u32 second; bool working; s8 direction; float degree_per_s; //当前的电角度, 单位:rad/s float phase_offset; }hall_t; #define SAMPLE_MAX_COUNT 6 typedef struct { float angle[SAMPLE_MAX_COUNT]; u32 ticks[SAMPLE_MAX_COUNT]; u32 index; bool full; }hall_sample_t; void hall_sensor_init(void); float hall_sensor_get_theta(void); //return degree float hall_sensor_get_speed(void); //return rpm float hall_sensor_avg_speed(void); int hall_sensor_calibrate(float current, u16 *hall_table); #endif /* _HALL_SENSOR_H__ */