Skip to content

Commit 22e19c7

Browse files
committed
enabled cross coupling and phase lag compensation for foc_current
1 parent af997e6 commit 22e19c7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/common/base_classes/FOCMotor.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ void FOCMotor::loopFOC() {
616616
voltage.q = current.q * phase_resistance + voltage_bemf;
617617
// constrain voltage within limits
618618
voltage.q = _constrain(voltage.q, -voltage_limit, voltage_limit) + feed_forward_voltage.q;
619-
// d voltage - lag compensation
620-
if(_isset(phase_inductance_dq.d)) voltage.d = _constrain( -current_sp*shaft_velocity*pole_pairs*phase_inductance_dq.d, -voltage_limit, voltage_limit) + feed_forward_voltage.d;
619+
// d voltage - lag compensation
620+
if(_isset(phase_inductance_dq.q)) voltage.d = _constrain( -current_sp*shaft_velocity*pole_pairs*phase_inductance_dq.q, -voltage_limit, voltage_limit) + feed_forward_voltage.d;
621621
else voltage.d = feed_forward_voltage.d;
622622
break;
623623
case TorqueControlType::dc_current:
@@ -631,7 +631,7 @@ void FOCMotor::loopFOC() {
631631
// calculate the phase voltage
632632
voltage.q = PID_current_q(current_sp - current.q) + feed_forward_voltage.q;
633633
// d voltage - lag compensation
634-
if(_isset(phase_inductance_dq.d)) voltage.d = _constrain( -current_sp*shaft_velocity*pole_pairs*phase_inductance_dq.d, -voltage_limit, voltage_limit) + feed_forward_voltage.d;
634+
if(_isset(phase_inductance_dq.q)) voltage.d = _constrain( -current_sp*shaft_velocity*pole_pairs*phase_inductance_dq.q, -voltage_limit, voltage_limit) + feed_forward_voltage.d;
635635
else voltage.d = feed_forward_voltage.d;
636636
break;
637637
case TorqueControlType::foc_current:
@@ -647,7 +647,9 @@ void FOCMotor::loopFOC() {
647647
voltage.q = PID_current_q(current_sp - current.q) + feed_forward_voltage.q;
648648
voltage.d = PID_current_d(feed_forward_current.d - current.d) + feed_forward_voltage.d;
649649
// d voltage - lag compensation - TODO verify
650-
// if(_isset(phase_inductance_dq.d)) voltage.d = _constrain( voltage.d - current_sp*shaft_velocity*pole_pairs*phase_inductance_dq.d, -voltage_limit, voltage_limit);
650+
if(_isset(phase_inductance_dq.q)) voltage.d = _constrain( voltage.d - current.q*shaft_velocity*pole_pairs*phase_inductance_dq.q, -voltage_limit, voltage_limit);
651+
// q voltage - cross coupling compensation - TODO verify
652+
if(_isset(phase_inductance_dq.d)) voltage.q = _constrain( voltage.q + current.d*shaft_velocity*pole_pairs*phase_inductance_dq.d, -voltage_limit, voltage_limit);
651653
break;
652654
default:
653655
// no torque control selected

0 commit comments

Comments
 (0)