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