|
|
@@ -154,6 +154,11 @@ static void PMSM_FOC_Conf_PID(void) {
|
|
|
gFoc_Ctrl.pi_lock->kb = nv_get_foc_params()->pid_conf[PID_Lock_id].kb;
|
|
|
gFoc_Ctrl.pi_lock->DT = (1.0f/(float)CONFIG_SPD_CTRL_TS);
|
|
|
|
|
|
+ gFoc_Ctrl.pi_fw->kp = nv_get_foc_params()->pid_conf[PID_FW_id].kp;
|
|
|
+ gFoc_Ctrl.pi_fw->ki = nv_get_foc_params()->pid_conf[PID_FW_id].ki;
|
|
|
+ gFoc_Ctrl.pi_fw->kb = nv_get_foc_params()->pid_conf[PID_FW_id].kb;
|
|
|
+ gFoc_Ctrl.pi_fw->DT = (1.0f/(float)CONFIG_SPD_CTRL_TS);
|
|
|
+ PI_Controller_max(gFoc_Ctrl.pi_fw, 0, -CONFIG_MAX_FW_D_CURR);
|
|
|
}
|
|
|
|
|
|
static void PMSM_FOC_UserInit(void) {
|
|
|
@@ -207,10 +212,12 @@ void PMSM_FOC_CoreInit(void) {
|
|
|
shark_task_create(PMSM_FOC_Debug_Task, NULL);
|
|
|
g_focinit = true;
|
|
|
}
|
|
|
+
|
|
|
gFoc_Ctrl.params.n_modulation = CONFIG_SVM_MODULATION;//SVM_Modulation;
|
|
|
gFoc_Ctrl.params.n_PhaseFilterCeof = (CONFIG_CURR_LP_PARAM>1.0f?1.0f:CONFIG_CURR_LP_PARAM);
|
|
|
gFoc_Ctrl.params.n_poles = nv_get_motor_params()->poles;//MOTOR_POLES;
|
|
|
gFoc_Ctrl.in.s_manualAngle = INVALID_ANGLE;
|
|
|
+ gFoc_Ctrl.in.b_fwEnable = nv_get_foc_params()->n_FwEnable;
|
|
|
gFoc_Ctrl.in.s_vDC = nv_get_foc_params()->s_maxDCVol;//(CONFIG_RATED_DC_VOL);
|
|
|
|
|
|
eRamp_init_target(&gFoc_Ctrl.in.cruiseRpmRamp, 0, CONFIG_ACC_TIME, CONFIG_DEC_TIME);
|
|
|
@@ -258,6 +265,7 @@ static __INLINE void PMSM_FOC_Update_Hardware(void) {
|
|
|
//sample current
|
|
|
phase_current_get(gFoc_Ctrl.in.s_iABC);
|
|
|
get_phase_vols(gFoc_Ctrl.in.s_vABC);
|
|
|
+#if 0
|
|
|
gFoc_Ctrl.in.s_vABC[0] -= gFoc_Ctrl.in.s_vDC/2.0f;
|
|
|
gFoc_Ctrl.in.s_vABC[1] -= gFoc_Ctrl.in.s_vDC/2.0f;
|
|
|
gFoc_Ctrl.in.s_vABC[2] -= gFoc_Ctrl.in.s_vDC/2.0f;
|
|
|
@@ -265,7 +273,7 @@ static __INLINE void PMSM_FOC_Update_Hardware(void) {
|
|
|
Clark(gFoc_Ctrl.in.s_vABC[0], gFoc_Ctrl.in.s_vABC[1], gFoc_Ctrl.in.s_vABC[2], &vAB);
|
|
|
|
|
|
Park(&vAB, gFoc_Ctrl.in.s_motAngle, &gFoc_Ctrl.out.s_RealVdq);
|
|
|
-
|
|
|
+#endif
|
|
|
#ifdef PHASE_LFP
|
|
|
LowPass_Filter(gFoc_Ctrl.in.s_iABCFilter[0], gFoc_Ctrl.in.s_iABC[0], gFoc_Ctrl.params.n_PhaseFilterCeof);
|
|
|
LowPass_Filter(gFoc_Ctrl.in.s_iABCFilter[1], gFoc_Ctrl.in.s_iABC[1], gFoc_Ctrl.params.n_PhaseFilterCeof);
|
|
|
@@ -382,7 +390,7 @@ void PMSM_FOC_Schedule(void) {
|
|
|
if (gFoc_Ctrl.plot_type == Plot_Phase_curr) {
|
|
|
plot_3data16(FtoS16(gFoc_Ctrl.in.s_iABC[0]), FtoS16(gFoc_Ctrl.in.s_iABC[1]), FtoS16(gFoc_Ctrl.in.s_iABC[2]));
|
|
|
}else if (gFoc_Ctrl.plot_type == Plot_Phase_vol) {
|
|
|
- plot_3data16(FtoS16x10(gFoc_Ctrl.in.s_vABC[0]), FtoS16x10(gFoc_Ctrl.in.s_vABC[1]), FtoS16x10(gFoc_Ctrl.in.s_vABC[2]));
|
|
|
+ plot_3data16(FtoS16(gFoc_Ctrl.in.s_vABC[0]), FtoS16(gFoc_Ctrl.in.s_vABC[1]), FtoS16(gFoc_Ctrl.in.s_vABC[2]));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -435,6 +443,11 @@ u8 PMSM_FOC_CtrlMode(void) {
|
|
|
}
|
|
|
|
|
|
/* MPTA, 弱磁, 功率限制,主要是分配DQ轴电流 */
|
|
|
+static __INLINE void PMSM_FOC_FieldWeak(void) {
|
|
|
+ if (!gFoc_Ctrl.in.b_fwEnable) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+}
|
|
|
static __INLINE float PMSM_FOC_Limit_iDC(float maxTrq) {
|
|
|
#if 1
|
|
|
PI_Ctrl_Power.max = maxTrq;
|
|
|
@@ -463,6 +476,7 @@ static __INLINE void PMSM_FOC_idq_Assign(void) {
|
|
|
}
|
|
|
}else if ((gFoc_Ctrl.out.n_RunMode == CTRL_MODE_TRQ) || (gFoc_Ctrl.out.n_RunMode == CTRL_MODE_SPD)) {
|
|
|
torque_get_idq(gFoc_Ctrl.in.s_targetTorque, gFoc_Ctrl.in.s_motRPM, &gFoc_Ctrl.in.s_targetIdq);
|
|
|
+ PMSM_FOC_FieldWeak();
|
|
|
}
|
|
|
u32 mask = cpu_enter_critical();
|
|
|
FOC_Set_iDqRamp(&gFoc_Ctrl.idq_ctl[0], gFoc_Ctrl.in.s_targetIdq.d);
|
|
|
@@ -558,7 +572,10 @@ void PMSM_FOC_Slow_Task(void) {
|
|
|
}
|
|
|
|
|
|
float PMSM_FOC_Get_Real_Torque(void) {
|
|
|
- return sqrtf(SQ(gFoc_Ctrl.out.s_FilterIdq.d) + SQ(gFoc_Ctrl.out.s_FilterIdq.q));
|
|
|
+ if (gFoc_Ctrl.out.s_RealCurrent == 0) {
|
|
|
+ gFoc_Ctrl.out.s_RealCurrent = sqrtf(SQ(gFoc_Ctrl.out.s_FilterIdq.d) + SQ(gFoc_Ctrl.out.s_FilterIdq.q));
|
|
|
+ }
|
|
|
+ return gFoc_Ctrl.out.s_RealCurrent;
|
|
|
}
|
|
|
|
|
|
PMSM_FOC_Ctrl *PMSM_FOC_Get(void) {
|
|
|
@@ -606,9 +623,27 @@ void PMSM_FOC_SpeedLimit(float speedLimit) {
|
|
|
speedLimit = gFoc_Ctrl.hwLim.s_motRPMMax;
|
|
|
}
|
|
|
gFoc_Ctrl.userLim.s_motRPMLim = (speedLimit);
|
|
|
+ eRamp_set_time(&gFoc_Ctrl.rtLim.rpmLimRamp, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
|
|
|
eRamp_set_step_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
}
|
|
|
|
|
|
+/* 扭矩模式下的限速,主要是处理转把对应的最高速 */
|
|
|
+void PMSM_FOC_Torque_SpeedLimit(float speedLimit) {
|
|
|
+ if (speedLimit > gFoc_Ctrl.hwLim.s_motRPMMax) {
|
|
|
+ speedLimit = gFoc_Ctrl.hwLim.s_motRPMMax;
|
|
|
+ }
|
|
|
+ if (speedLimit > gFoc_Ctrl.userLim.s_motRPMLim) {
|
|
|
+ speedLimit = gFoc_Ctrl.userLim.s_motRPMLim;
|
|
|
+ }
|
|
|
+ eRamp_set_time(&gFoc_Ctrl.rtLim.rpmLimRamp, 1000, 1000);
|
|
|
+ if (gFoc_Ctrl.in.s_motRPM == 0) {
|
|
|
+ eRamp_reset_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit/1.3f);//1.3的系数防止限速过冲
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
+ }else {
|
|
|
+ eRamp_set_step_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
float PMSM_FOC_GetSpeedLimit(void) {
|
|
|
return gFoc_Ctrl.userLim.s_motRPMLim;
|
|
|
}
|
|
|
@@ -906,8 +941,8 @@ u32 PMSM_FOC_GetCriticalError(void) {
|
|
|
void PMSM_FOC_Set_PlotType(Plot_t t) {
|
|
|
gFoc_Ctrl.plot_type = t;
|
|
|
}
|
|
|
-//获取母线电流
|
|
|
-float PMSM_FOC_Calc_iDC(void) {
|
|
|
+//获取母线电流和实际输出电流矢量大小
|
|
|
+void PMSM_FOC_Calc_Current(void) {
|
|
|
float vd = gFoc_Ctrl.out.s_OutVdq.d;
|
|
|
float vq = gFoc_Ctrl.out.s_OutVdq.q;
|
|
|
|
|
|
@@ -924,7 +959,9 @@ float PMSM_FOC_Calc_iDC(void) {
|
|
|
}
|
|
|
float raw_idc = m_pow / get_vbus_float() * (1.0f - 0.2f * id_thr/100.0f);// * 1.5f * 0.66f; //s16q5
|
|
|
LowPass_Filter(gFoc_Ctrl.out.s_FilteriDC, raw_idc, 0.1f);
|
|
|
- return gFoc_Ctrl.out.s_FilteriDC;
|
|
|
+
|
|
|
+ gFoc_Ctrl.out.s_RealCurrent = sqrtf(SQ(gFoc_Ctrl.out.s_FilterIdq.d) + SQ(gFoc_Ctrl.out.s_FilterIdq.q));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void PMSM_FOC_Brake(bool brake) {
|