2025-10-16 21:43:34 +08:00
|
|
|
// 函数声明
|
|
|
|
|
#ifndef _DENGFOC_H
|
|
|
|
|
#define _DENGFOC_H
|
2025-11-03 02:38:43 +08:00
|
|
|
#include "pid.h"
|
2025-10-16 21:43:34 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
class FOC_Controlroller {
|
|
|
|
|
public:
|
|
|
|
|
FOC_Controlroller();
|
|
|
|
|
|
|
|
|
|
float control_mode = 0;
|
2025-10-30 20:20:14 +08:00
|
|
|
float limit_voltage = 0.0f;
|
2025-10-16 21:43:34 +08:00
|
|
|
float limit_velocity = 0.0f;
|
|
|
|
|
float target_angle = 0.0f;
|
|
|
|
|
float target_velocity = 0.0f;
|
2025-11-01 20:29:11 +08:00
|
|
|
float rt_angle = 0.0f;
|
|
|
|
|
float rt_velocity = 0.0f;
|
|
|
|
|
u8 over_current = 0;
|
|
|
|
|
u8 temp_error = 0;
|
|
|
|
|
u8 voltage_error = 0;
|
2025-10-29 21:22:10 +08:00
|
|
|
u8 is_shut_down = 0;
|
2025-10-16 21:43:34 +08:00
|
|
|
|
2025-11-03 02:38:43 +08:00
|
|
|
float velocity_open_loop();
|
|
|
|
|
float angle_control(float target_angle);
|
|
|
|
|
// void SET_VEL_PID(float P, float I, float D, float ramp); // 速度环PID设置
|
|
|
|
|
// void SET_ANGLE_PID(float P, float I, float D, float ramp); // 角度环PID设置
|
|
|
|
|
|
2025-11-02 01:54:01 +08:00
|
|
|
void update_power(void);
|
2025-11-03 02:38:43 +08:00
|
|
|
void DFOC_alignSensor(int _PP);
|
2025-10-29 21:22:10 +08:00
|
|
|
void shut_down(void);
|
|
|
|
|
void resume(void);
|
2025-10-16 21:43:34 +08:00
|
|
|
|
2025-11-01 20:29:11 +08:00
|
|
|
protected:
|
2025-10-16 21:43:34 +08:00
|
|
|
std::u64 last_time_us = 0;
|
|
|
|
|
std::u64 now_us = 0;
|
|
|
|
|
float shaft_angle = 0;
|
|
|
|
|
float Ualpha, Ubeta = 0, Ua = 0, Ub = 0, Uc = 0;
|
|
|
|
|
float zero_electric_angle = 0;
|
2025-10-30 20:20:14 +08:00
|
|
|
float voltage_power_supply = 24.0f; // 电源电压
|
2025-10-16 21:43:34 +08:00
|
|
|
|
2025-11-03 02:38:43 +08:00
|
|
|
PIDController vel_loop =
|
|
|
|
|
PIDController{2, 0, 0, 100000, voltage_power_supply / 2};
|
|
|
|
|
PIDController angle_loop = PIDController{2, 0, 0, 100000, 100};
|
|
|
|
|
|
2025-10-16 21:43:34 +08:00
|
|
|
void setPhaseVoltage(float Uq, float Ud, float angle_el);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
float _normalizeAngle(float angle);
|
|
|
|
|
void DFOC_Vbus(float power_supply);
|
2025-11-03 02:38:43 +08:00
|
|
|
inline float _electricalAngle();
|
|
|
|
|
float DFOC_M0_Angle(void);
|
2025-10-16 21:43:34 +08:00
|
|
|
|
2025-10-30 20:20:14 +08:00
|
|
|
#endif
|