@@ -636,9 +636,11 @@ float BLDCMotor::velocityOpenloop(float target_velocity){
636636
637637 // use voltage limit or current limit
638638 float Uq = voltage_limit;
639- if (_isset (phase_resistance))
640- Uq = _constrain (current_limit*phase_resistance + voltage_bemf,-voltage_limit, voltage_limit);
641-
639+ if (_isset (phase_resistance)){
640+ Uq = _constrain (current_limit*phase_resistance + fabs (voltage_bemf),-voltage_limit, voltage_limit);
641+ // recalculate the current
642+ current.q = (Uq - fabs (voltage_bemf))/phase_resistance;
643+ }
642644 // set the maximal allowed voltage (voltage_limit) with the necessary angle
643645 setPhaseVoltage (Uq, 0 , _electricalAngle (shaft_angle, pole_pairs));
644646
@@ -674,8 +676,11 @@ float BLDCMotor::angleOpenloop(float target_angle){
674676
675677 // use voltage limit or current limit
676678 float Uq = voltage_limit;
677- if (_isset (phase_resistance))
678- Uq = _constrain (current_limit*phase_resistance + voltage_bemf,-voltage_limit, voltage_limit);
679+ if (_isset (phase_resistance)){
680+ Uq = _constrain (current_limit*phase_resistance + fabs (voltage_bemf),-voltage_limit, voltage_limit);
681+ // recalculate the current
682+ current.q = (Uq - fabs (voltage_bemf))/phase_resistance;
683+ }
679684 // set the maximal allowed voltage (voltage_limit) with the necessary angle
680685 // sensor precision: this calculation is OK due to the normalisation
681686 setPhaseVoltage (Uq, 0 , _electricalAngle (_normalizeAngle (shaft_angle), pole_pairs));
0 commit comments