add uart rx; 4 bytes cmd parse
This commit is contained in:
25
3rd/dfoc.c
25
3rd/dfoc.c
@@ -16,7 +16,7 @@
|
||||
#define _2_SQRT3 1.15470053838f
|
||||
|
||||
volatile float Ua = 0, Ub = 0, Uc = 0, Ualpha, Ubeta = 0, dc_a = 0, dc_b = 0, dc_c = 0;
|
||||
const float voltage_limit = 12;
|
||||
const float voltage_limit = 8;
|
||||
const float voltage_power_supply = 12.0f;
|
||||
volatile float zero_electric_Angle = 0.0;
|
||||
|
||||
@@ -66,7 +66,7 @@ void SetPwm(float Ua, float Ub, float Uc)
|
||||
U_a = constrain(Ua, 0.0f, voltage_limit);
|
||||
U_b = constrain(Ub, 0.0f, voltage_limit);
|
||||
U_c = constrain(Uc, 0.0f, voltage_limit);
|
||||
//printf("Ua : %f -- Ub : %f -- Uc : %f -- U_a : %f -- U_b : %f -- U_c : %f \n",Ua,Ub,Uc,U_a,U_b,U_c);
|
||||
//printf("Ua : %f -- Ub : %f -- Uc : %f -- U_a : %f -- U_b : %f -- U_c : %f \n",Ua,Ub,Uc,U_a,U_b,U_c);
|
||||
dc_a = constrain(U_a / voltage_power_supply, 0.0f, 1.0f);
|
||||
dc_b = constrain(U_b / voltage_power_supply, 0.0f, 1.0f);
|
||||
dc_c = constrain(U_c / voltage_power_supply, 0.0f, 1.0f);
|
||||
@@ -96,8 +96,8 @@ void SetPhaseVoltage(float Uq, float Ud, float angle_el)
|
||||
|
||||
SetPwm(Ua, Ub, Uc);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
last_test_angle = angle_el;
|
||||
}
|
||||
|
||||
@@ -124,8 +124,17 @@ void FOC_Init(float power)
|
||||
// 单角度环
|
||||
void Set_Angle(float Target)
|
||||
{
|
||||
volatile float angle = GetAngle();
|
||||
volatile float Uq = PID_Controller(0.133, 0.01, 0, (Target - Dir * angle) * 180 / PI);
|
||||
volatile float langle = GetAngle();
|
||||
if(DEBUG_ENABLED & DEBUG_DFOC_ENABLED)
|
||||
{
|
||||
printf("angle readback in dfoc.c is %f \n", langle);
|
||||
}
|
||||
volatile float Uq = PID_Controller(0.133, 0.01, 0, (Target - Dir * langle) * 180 / PI);
|
||||
//volatile float Uq = PID_Controller(0.06, 0, 0, (Target - Dir * langle) * 180 / PI);
|
||||
if(DEBUG_ENABLED)
|
||||
{
|
||||
printf("Uq is %f \n", Uq);
|
||||
}
|
||||
SetPhaseVoltage(Uq, 0, electricAngle());
|
||||
}
|
||||
|
||||
@@ -157,14 +166,14 @@ float velocityopenloop(float target)
|
||||
|
||||
if(DEBUG_ENABLED)
|
||||
{
|
||||
//printf("shaft_angle : %f -- target : %f -- Ts : %f",shaft_angle,target,Ts);
|
||||
//printf("shaft_angle : %f -- target : %f -- Ts : %f \n",shaft_angle,target,Ts);
|
||||
}
|
||||
|
||||
|
||||
Uq = voltage_limit;
|
||||
|
||||
SetPhaseVoltage(Uq, 0, shaft_angle);
|
||||
printf("shaft_angle : %f \n",shaft_angle);
|
||||
printf("shaft_angle : %f \n", shaft_angle);
|
||||
openloop_timestamp = now_ts;
|
||||
|
||||
return Uq;
|
||||
|
||||
Reference in New Issue
Block a user