@@ -358,23 +358,23 @@ void BLDCMotor::loopFOC() {
358
358
// read overall current magnitude
359
359
current.q = current_sense->getDCCurrent (electrical_angle);
360
360
// filter the value values
361
- current.q = LPF_current_q (current.q );
361
+ current.q = LPF_current_q (current.q ) + feed_forward_current. q ;
362
362
// calculate the phase voltage
363
- voltage.q = PID_current_q (current_sp - current.q );
363
+ voltage.q = PID_current_q (current_sp - current.q )+feed_forward_voltage. q ;
364
364
// d voltage - lag compensation
365
- if (_isset (phase_inductance)) voltage.d = _constrain ( -current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
366
- else voltage.d = 0 ;
365
+ if (_isset (phase_inductance)) voltage.d = _constrain ( -current_sp*shaft_velocity*pole_pairs*phase_inductance+feed_forward_voltage. d , -voltage_limit, voltage_limit);
366
+ else voltage.d = feed_forward_voltage. d ;
367
367
break ;
368
368
case TorqueControlType::foc_current:
369
369
if (!current_sense) return ;
370
370
// read dq currents
371
371
current = current_sense->getFOCCurrents (electrical_angle);
372
372
// filter values
373
- current.q = LPF_current_q (current.q );
374
- current.d = LPF_current_d (current.d );
373
+ current.q = LPF_current_q (current.q ) + feed_forward_current. q ;
374
+ current.d = LPF_current_d (current.d ) + feed_forward_current. d ;
375
375
// calculate the phase voltages
376
- voltage.q = PID_current_q (current_sp - current.q );
377
- voltage.d = PID_current_d (-current.d );
376
+ voltage.q = PID_current_q (current_sp - current.q )+feed_forward_voltage. q ;
377
+ voltage.d = PID_current_d (-current.d )+feed_forward_voltage. d ;
378
378
// d voltage - lag compensation - TODO verify
379
379
// if(_isset(phase_inductance)) voltage.d = _constrain( voltage.d - current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
380
380
break ;
@@ -383,7 +383,6 @@ void BLDCMotor::loopFOC() {
383
383
SIMPLEFOC_DEBUG (" MOT: no torque control selected!" );
384
384
break ;
385
385
}
386
-
387
386
// set the phase voltage - FOC heart function :)
388
387
setPhaseVoltage (voltage.q , voltage.d , electrical_angle);
389
388
}
@@ -450,10 +449,10 @@ void BLDCMotor::move(float new_target) {
450
449
if (torque_controller == TorqueControlType::voltage){
451
450
// use voltage if phase-resistance not provided
452
451
if (!_isset (phase_resistance)) voltage.q = current_sp;
453
- else voltage.q = _constrain ( current_sp*phase_resistance + voltage_bemf , -voltage_limit, voltage_limit);
452
+ else voltage.q = _constrain ( ( current_sp+feed_forward_current. q ) *phase_resistance + voltage_bemf, -voltage_limit, voltage_limit);
454
453
// set d-component (lag compensation if known inductance)
455
454
if (!_isset (phase_inductance)) voltage.d = 0 ;
456
- else voltage.d = _constrain ( -current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
455
+ else voltage.d = _constrain ( -( current_sp+feed_forward_current. d ) *shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
457
456
}
458
457
break ;
459
458
case MotionControlType::velocity:
@@ -465,10 +464,10 @@ void BLDCMotor::move(float new_target) {
465
464
if (torque_controller == TorqueControlType::voltage){
466
465
// use voltage if phase-resistance not provided
467
466
if (!_isset (phase_resistance)) voltage.q = current_sp;
468
- else voltage.q = _constrain ( current_sp*phase_resistance + voltage_bemf , -voltage_limit, voltage_limit);
467
+ else voltage.q = _constrain ( ( current_sp+feed_forward_current. q ) *phase_resistance + voltage_bemf, -voltage_limit, voltage_limit);
469
468
// set d-component (lag compensation if known inductance)
470
469
if (!_isset (phase_inductance)) voltage.d = 0 ;
471
- else voltage.d = _constrain ( -current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
470
+ else voltage.d = _constrain ( -( current_sp+feed_forward_current. d ) *shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
472
471
}
473
472
break ;
474
473
case MotionControlType::velocity_openloop:
0 commit comments