移除冗余的 `_electricalAngle` 函数,修正 `setPhaseVoltage` 中电气角度的计算方式 在定时器中断中增加实时角度更新,支持新增的无 PID 角度控制模式。
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
// 函数声明
|
|
#ifndef _DENGFOC_H
|
|
#define _DENGFOC_H
|
|
#include "pid.h"
|
|
#include <stdint.h>
|
|
class FOC_Controlroller {
|
|
public:
|
|
FOC_Controlroller();
|
|
|
|
float control_mode = 0;
|
|
float limit_voltage = 0.0f;
|
|
float limit_velocity = 0.0f;
|
|
float target_angle = 0.0f;
|
|
float target_velocity = 0.0f;
|
|
float rt_angle = 0.0f;
|
|
float rt_velocity = 0.0f;
|
|
u8 over_current = 0;
|
|
u8 temp_error = 0;
|
|
u8 voltage_error = 0;
|
|
u8 is_shut_down = 0;
|
|
|
|
float velocity_open_loop();
|
|
float angle_control(float target_angle);
|
|
float velocity_control(float target_velocity);
|
|
float angle_control_NPID(float target_angle);
|
|
|
|
void update_power(void);
|
|
void DFOC_alignSensor(int _PP);
|
|
void shut_down(void);
|
|
void resume(void);
|
|
|
|
protected:
|
|
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;
|
|
float voltage_power_supply = 24.0f; // 电源电压
|
|
float v_half = voltage_power_supply * 0.5f; // 电源电压的一半
|
|
|
|
PIDController vel_loop =PIDController{1.75f, 1.0f, 0.0002f, 1000000, voltage_power_supply};
|
|
PIDController angle_loop =
|
|
PIDController{140.0f, 80.0f, 0.005f, 10000000, voltage_power_supply};
|
|
|
|
void setPhaseVoltage(float Uq, float Ud);
|
|
};
|
|
|
|
float _normalizeAngle(float angle);
|
|
void DFOC_Vbus(float power_supply);
|
|
inline float _electricalAngle();
|
|
float DFOC_M0_Angle(void);
|
|
|
|
#endif |