|
@@ -50,10 +50,10 @@ bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
|
|
|
line_ramp_init(&ctrl->ramp_target_current, CONFIG_CURRENT_RAMP_TIME);
|
|
line_ramp_init(&ctrl->ramp_target_current, CONFIG_CURRENT_RAMP_TIME);
|
|
|
line_ramp_init(&ctrl->ramp_input_torque, CONFIG_DEFAULT_TORQUE_RAMP_TIME);
|
|
line_ramp_init(&ctrl->ramp_input_torque, CONFIG_DEFAULT_TORQUE_RAMP_TIME);
|
|
|
line_ramp_init(&ctrl->ramp_adv_angle, CONFIG_CURRENT_RAMP_TIME);
|
|
line_ramp_init(&ctrl->ramp_adv_angle, CONFIG_CURRENT_RAMP_TIME);
|
|
|
- mot_contrl_pid(ctrl);
|
|
|
|
|
mot_contrl_ulimit(ctrl);
|
|
mot_contrl_ulimit(ctrl);
|
|
|
mot_contrl_rtlimit(ctrl);
|
|
mot_contrl_rtlimit(ctrl);
|
|
|
}
|
|
}
|
|
|
|
|
+ mot_contrl_pid(ctrl);
|
|
|
ctrl->b_ebrk_running = false;
|
|
ctrl->b_ebrk_running = false;
|
|
|
ctrl->b_AutoHold = false;
|
|
ctrl->b_AutoHold = false;
|
|
|
ctrl->b_cruiseEna = false;
|
|
ctrl->b_cruiseEna = false;
|
|
@@ -293,8 +293,8 @@ bool mot_contrl_update(mot_contrl_t *ctrl) {
|
|
|
float lowpass = 0.001f;
|
|
float lowpass = 0.001f;
|
|
|
LowPass_Filter(ctrl->out_idq_filterd.d, foc->out.curr_dq.d ,lowpass);
|
|
LowPass_Filter(ctrl->out_idq_filterd.d, foc->out.curr_dq.d ,lowpass);
|
|
|
LowPass_Filter(ctrl->out_idq_filterd.q, foc->out.curr_dq.q ,lowpass);
|
|
LowPass_Filter(ctrl->out_idq_filterd.q, foc->out.curr_dq.q ,lowpass);
|
|
|
- LowPass_Filter(ctrl->out_vdq_filterd.d, foc->out.vol_dq.d ,lowpass);
|
|
|
|
|
- LowPass_Filter(ctrl->out_vdq_filterd.q, foc->out.vol_dq.q ,lowpass);
|
|
|
|
|
|
|
+ LowPass_Filter(ctrl->out_vdq_filterd.d, foc->out.vol_dq.d ,lowpass/1.5f);
|
|
|
|
|
+ LowPass_Filter(ctrl->out_vdq_filterd.q, foc->out.vol_dq.q ,lowpass/1.5f);
|
|
|
|
|
|
|
|
/* 计算母线电流 */
|
|
/* 计算母线电流 */
|
|
|
float vd = ctrl->out_vdq_filterd.d;
|
|
float vd = ctrl->out_vdq_filterd.d;
|
|
@@ -332,17 +332,16 @@ static __INLINE float mot_contrl_dc_curr_limiter(mot_contrl_t *ctrl, float maxTr
|
|
|
}else {
|
|
}else {
|
|
|
ctrl->dc_lim_iq_ff = iq_ff;
|
|
ctrl->dc_lim_iq_ff = iq_ff;
|
|
|
}
|
|
}
|
|
|
- ctrl->pi_power.max = min(maxTrq, ctrl->dc_lim_iq_ff);
|
|
|
|
|
|
|
+ ctrl->pi_power.max = maxTrq;
|
|
|
float errRef = dc_lim - ctrl->dc_curr_filted;
|
|
float errRef = dc_lim - ctrl->dc_curr_filted;
|
|
|
- return PI_Controller_Run(&ctrl->pi_power, errRef, ctrl->dc_lim_iq_ff);
|
|
|
|
|
|
|
+ return PI_Controller_Parallel(&ctrl->pi_power, errRef, ctrl->dc_lim_iq_ff);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static __INLINE float mot_contrl_vel_limiter(mot_contrl_t *ctrl, float maxTrq) {
|
|
static __INLINE float mot_contrl_vel_limiter(mot_contrl_t *ctrl, float maxTrq) {
|
|
|
ctrl->pi_vel_lim.max = maxTrq;
|
|
ctrl->pi_vel_lim.max = maxTrq;
|
|
|
ctrl->pi_vel_lim.min = 0;
|
|
ctrl->pi_vel_lim.min = 0;
|
|
|
-
|
|
|
|
|
float err = line_ramp_get_interp(&ctrl->ramp_vel_lim) - ctrl->foc.in.mot_velocity;
|
|
float err = line_ramp_get_interp(&ctrl->ramp_vel_lim) - ctrl->foc.in.mot_velocity;
|
|
|
- return PI_Controller_RunVel(&ctrl->pi_vel_lim, err);
|
|
|
|
|
|
|
+ return PI_Controller_Parallel(&ctrl->pi_vel_lim, err, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* current vector or torque to dq axis current */
|
|
/* current vector or torque to dq axis current */
|
|
@@ -426,7 +425,7 @@ void mot_contrl_dq_calc(mot_contrl_t *ctrl) {
|
|
|
ctrl->pi_lock.min = -hold_torque;
|
|
ctrl->pi_lock.min = -hold_torque;
|
|
|
float vel_count = motor_encoder_get_vel_count();
|
|
float vel_count = motor_encoder_get_vel_count();
|
|
|
float errRef = 0 - vel_count;
|
|
float errRef = 0 - vel_count;
|
|
|
- ctrl->target_torque = PI_Controller_Run(&ctrl->pi_lock ,errRef, 0);
|
|
|
|
|
|
|
+ ctrl->target_torque = PI_Controller_Parallel(&ctrl->pi_lock ,errRef, 0);
|
|
|
mot_contrl_dq_assign(ctrl);
|
|
mot_contrl_dq_assign(ctrl);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -476,7 +475,7 @@ void mot_contrl_dq_calc(mot_contrl_t *ctrl) {
|
|
|
ctrl->pi_vel.min = 0; //防止倒转
|
|
ctrl->pi_vel.min = 0; //防止倒转
|
|
|
}
|
|
}
|
|
|
float errRef = refSpeed - ctrl->foc.in.mot_velocity;
|
|
float errRef = refSpeed - ctrl->foc.in.mot_velocity;
|
|
|
- float maxTrq = PI_Controller_RunVel(&ctrl->pi_vel, errRef);
|
|
|
|
|
|
|
+ float maxTrq = PI_Controller_Parallel(&ctrl->pi_vel, errRef, 0);
|
|
|
ctrl->target_torque_raw = mot_contrl_dc_curr_limiter(ctrl, maxTrq);
|
|
ctrl->target_torque_raw = mot_contrl_dc_curr_limiter(ctrl, maxTrq);
|
|
|
crosszero_step_towards(&ctrl->target_torque, ctrl->target_torque_raw);
|
|
crosszero_step_towards(&ctrl->target_torque, ctrl->target_torque_raw);
|
|
|
}
|
|
}
|
|
@@ -884,7 +883,7 @@ void mot_contrl_calc_current(mot_contrl_t *ctrl) {
|
|
|
|
|
|
|
|
float raw_idc = get_vbus_current();
|
|
float raw_idc = get_vbus_current();
|
|
|
if (raw_idc != NO_VALID_CURRENT) {
|
|
if (raw_idc != NO_VALID_CURRENT) {
|
|
|
- LowPass_Filter(ctrl->dc_curr_filted, raw_idc, 0.05f);
|
|
|
|
|
|
|
+ LowPass_Filter(ctrl->dc_curr_filted, raw_idc, 0.04f);
|
|
|
}else {
|
|
}else {
|
|
|
ctrl->dc_curr_filted = ctrl->dc_curr_calc;
|
|
ctrl->dc_curr_filted = ctrl->dc_curr_calc;
|
|
|
}
|
|
}
|