|
@@ -22,8 +22,10 @@ void foc_init(foc_t *foc) {
|
|
|
foc->qaxis.ki = mc_conf()->c.pid[PID_IQ_ID].ki;
|
|
foc->qaxis.ki = mc_conf()->c.pid[PID_IQ_ID].ki;
|
|
|
foc->qaxis.kd = mc_conf()->c.pid[PID_IQ_ID].kd;
|
|
foc->qaxis.kd = mc_conf()->c.pid[PID_IQ_ID].kd;
|
|
|
foc->qaxis.DT = foc->ts;
|
|
foc->qaxis.DT = foc->ts;
|
|
|
- foc->ramp_curr_dq.d = 0;
|
|
|
|
|
- foc->ramp_curr_dq.q = 0;
|
|
|
|
|
|
|
+ line_ramp_init(&foc->in.target_id, CURRENT_LOOP_RAMP_COUNT);
|
|
|
|
|
+ line_ramp_set_minstep(&foc->in.target_id, 5.0f);
|
|
|
|
|
+ line_ramp_init(&foc->in.target_iq, CURRENT_LOOP_RAMP_COUNT);
|
|
|
|
|
+ line_ramp_set_minstep(&foc->in.target_iq, 5.0f);
|
|
|
foc->mot_velocity_filterd = 0;
|
|
foc->mot_velocity_filterd = 0;
|
|
|
foc->mot_vel_radusPers = 0;
|
|
foc->mot_vel_radusPers = 0;
|
|
|
memset(&foc->in, 0, sizeof(foc_in_t));
|
|
memset(&foc->in, 0, sizeof(foc_in_t));
|
|
@@ -64,20 +66,13 @@ void foc_update(foc_t *foc) {
|
|
|
arm_sin_cos(foc->in.mot_angle, &foc->sin, &foc->cos);
|
|
arm_sin_cos(foc->in.mot_angle, &foc->sin, &foc->cos);
|
|
|
park(foc, &foc->in.curr_ab, &foc->out.curr_dq);
|
|
park(foc, &foc->in.curr_ab, &foc->out.curr_dq);
|
|
|
if (!foc->in.b_openloop) {
|
|
if (!foc->in.b_openloop) {
|
|
|
- float d_step = (foc->in.target_curr_dq.d - foc->ramp_curr_dq.d) / foc->d_ramp_time;
|
|
|
|
|
- float q_step = (foc->in.target_curr_dq.q - foc->ramp_curr_dq.q) / foc->q_ramp_time;
|
|
|
|
|
- if (d_step < 0) {
|
|
|
|
|
- d_step = -d_step;
|
|
|
|
|
- }
|
|
|
|
|
- if (q_step < 0) {
|
|
|
|
|
- q_step = -q_step;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
/* limiter Vd output for PI controller */
|
|
/* limiter Vd output for PI controller */
|
|
|
float max_vd = max_Vdc * SQRT3_BY_2;
|
|
float max_vd = max_Vdc * SQRT3_BY_2;
|
|
|
foc->daxis.max = max_vd;
|
|
foc->daxis.max = max_vd;
|
|
|
foc->daxis.min = -max_vd;
|
|
foc->daxis.min = -max_vd;
|
|
|
- step_towards(&foc->ramp_curr_dq.d, foc->in.target_curr_dq.d, d_step);
|
|
|
|
|
- float err = foc->ramp_curr_dq.d - foc->out.curr_dq.d;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ float err = line_ramp_step(&foc->in.target_id) - foc->out.curr_dq.d;
|
|
|
float id_ff = id_feedforward(foc);
|
|
float id_ff = id_feedforward(foc);
|
|
|
foc->in.target_vol_dq.d = PI_Controller_Current(&foc->daxis, err, id_ff);
|
|
foc->in.target_vol_dq.d = PI_Controller_Current(&foc->daxis, err, id_ff);
|
|
|
|
|
|
|
@@ -85,8 +80,7 @@ void foc_update(foc_t *foc) {
|
|
|
float max_vq = sqrtf(SQ(max_vd) - SQ(foc->in.target_vol_dq.d));
|
|
float max_vq = sqrtf(SQ(max_vd) - SQ(foc->in.target_vol_dq.d));
|
|
|
foc->qaxis.max = max_vq;
|
|
foc->qaxis.max = max_vq;
|
|
|
foc->qaxis.min = -max_vq;
|
|
foc->qaxis.min = -max_vq;
|
|
|
- step_towards(&foc->ramp_curr_dq.q, foc->in.target_curr_dq.q, q_step);
|
|
|
|
|
- err = foc->ramp_curr_dq.q - foc->out.curr_dq.q;
|
|
|
|
|
|
|
+ err = line_ramp_step(&foc->in.target_iq) - foc->out.curr_dq.q;
|
|
|
float iq_ff = iq_feedforward(foc);
|
|
float iq_ff = iq_feedforward(foc);
|
|
|
foc->in.target_vol_dq.q = PI_Controller_Current(&foc->qaxis, err, iq_ff);
|
|
foc->in.target_vol_dq.q = PI_Controller_Current(&foc->qaxis, err, iq_ff);
|
|
|
}else {
|
|
}else {
|