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();
|
|
|
|
|
|
2025-11-12 00:46:26 +08:00
|
|
|
u8 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;
|
2025-11-12 00:46:26 +08:00
|
|
|
bool thermal_uncontrol = 0;
|
|
|
|
|
bool voltage_error = 0;
|
|
|
|
|
bool is_shut_down = 0;
|
|
|
|
|
float voltage_power_supply = 24.0f; // 电源电压
|
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);
|
2025-11-06 02:07:15 +08:00
|
|
|
float velocity_control(float target_velocity);
|
2025-11-08 02:15:14 +08:00
|
|
|
float angle_control_NPID(float target_angle);
|
2025-11-03 02:38:43 +08:00
|
|
|
|
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-11-06 02:07:15 +08:00
|
|
|
float v_half = voltage_power_supply * 0.5f; // 电源电压的一半
|
2025-10-16 21:43:34 +08:00
|
|
|
|
2025-11-12 00:46:26 +08:00
|
|
|
PIDController vel_loop =PIDController{1.8f, 1.2f, 0.0002f, 1000000, voltage_power_supply};
|
2025-11-10 02:08:03 +08:00
|
|
|
PIDController angle_loop =
|
|
|
|
|
PIDController{140.0f, 80.0f, 0.005f, 10000000, voltage_power_supply};
|
2025-11-03 02:38:43 +08:00
|
|
|
|
2025-11-08 02:15:14 +08:00
|
|
|
void setPhaseVoltage(float Uq, float Ud);
|
2025-10-16 21:43:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|