@@ -416,12 +416,23 @@ void HFIBLDCMotor::process_hfi(){
416
416
if (flux_beta<-flux_linkage){flux_beta=-flux_linkage;}
417
417
i_alpha_prev=ABcurrent.alpha ;
418
418
i_beta_prev=ABcurrent.beta ;
419
- flux_observer_angle=atan2 (flux_beta,flux_alpha)+_PI;
420
- bemf = voltage.q -phase_resistance * current_meas.q ;
419
+ flux_observer_angle=atan2 (flux_beta,flux_alpha);
420
+ if (flux_observer_angle<0 ){flux_observer_angle+=_2PI;}
421
+ bemf=(polarity_correction*(voltage.q -phase_resistance * current_meas.q ));
421
422
if (bemf>bemf_threshold){
423
+ bemf_count+=2 ;
424
+ }
425
+ else {
426
+ bemf_count-=2 ;
427
+ if (bemf_count<0 ){bemf_count=0 ;}
428
+ }
429
+ if (bemf_count>100 ){
430
+ bemf_count+=1 ;
431
+ if (bemf_count>200 ){bemf_count=200 ;}
422
432
hfi_out=flux_observer_angle;
423
- hfi_int=hfi_out-hfi_out_prev ;
433
+ hfi_velocity=((bemf*KV_rating*_SQRT3*_2PI)/( 60 . 0f )) ;
424
434
hfi_out_prev=hfi_out;
435
+ hfi_v_act=0 ;
425
436
}
426
437
else
427
438
{
@@ -455,20 +466,21 @@ void HFIBLDCMotor::process_hfi(){
455
466
hfi_curangleest = -error_saturation_limit;
456
467
hfi_error = -hfi_curangleest;
457
468
hfi_int += Ts * hfi_error * hfi_gain2; // This the the double integrator
469
+ hfi_velocity=hfi_int /(Ts*pole_pairs);
458
470
hfi_out += hfi_gain1 * Ts * hfi_error + hfi_int; // This is the integrator and the double integrator
471
+ }
472
+ current_err.q = polarity_correction * current_setpoint.q - current_meas.q ;
473
+ current_err.d = polarity_correction * current_setpoint.d - current_meas.d ;
459
474
460
- current_err.q = polarity_correction * current_setpoint.q - current_meas.q ;
461
- current_err.d = polarity_correction * current_setpoint.d - current_meas.d ;
462
-
463
- voltage_pid.q = PID_current_q (current_err.q , Ts);
464
- voltage_pid.d = PID_current_d (current_err.d , Ts);
475
+ voltage_pid.q = PID_current_q (current_err.q , Ts);
476
+ voltage_pid.d = PID_current_d (current_err.d , Ts);
465
477
466
- // lowpass does a += on the first arg
467
- LOWPASS (voltage.q , voltage_pid.q , 0 .34f );
468
- LOWPASS (voltage.d , voltage_pid.d , 0 .34f );
478
+ // lowpass does a += on the first arg
479
+ LOWPASS (voltage.q , voltage_pid.q , 0 .34f );
480
+ LOWPASS (voltage.d , voltage_pid.d , 0 .34f );
469
481
470
- voltage.d += hfi_v_act;
471
- }
482
+ voltage.d += hfi_v_act;
483
+ hfi_out_prev = hfi_out;
472
484
}
473
485
// // PMSM decoupling control and BEMF FF
474
486
// stateX->VqFF = stateX->we * ( confX->Ld * stateX->Id_SP + confX->Lambda_m);
@@ -608,7 +620,7 @@ void HFIBLDCMotor::move(float new_target) {
608
620
float tmp_hfi_int = hfi_int;
609
621
interrupts ();
610
622
shaft_angle = (hfi_full_turns *_2PI + tmp_electrical_angle)/pole_pairs;
611
- hfi_velocity = tmp_hfi_int /(Ts*pole_pairs);
623
+ // hfi_velocity = tmp_hfi_int /(Ts*pole_pairs);
612
624
} else {
613
625
if (!sensor){
614
626
shaft_angle = shaftAngle (); // read value even if motor is disabled to keep the monitoring updated but not in openloop mode
0 commit comments