@@ -636,9 +636,11 @@ float BLDCMotor::velocityOpenloop(float target_velocity){
636
636
637
637
// use voltage limit or current limit
638
638
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
+ }
642
644
// set the maximal allowed voltage (voltage_limit) with the necessary angle
643
645
setPhaseVoltage (Uq, 0 , _electricalAngle (shaft_angle, pole_pairs));
644
646
@@ -674,8 +676,11 @@ float BLDCMotor::angleOpenloop(float target_angle){
674
676
675
677
// use voltage limit or current limit
676
678
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
+ }
679
684
// set the maximal allowed voltage (voltage_limit) with the necessary angle
680
685
// sensor precision: this calculation is OK due to the normalisation
681
686
setPhaseVoltage (Uq, 0 , _electricalAngle (_normalizeAngle (shaft_angle), pole_pairs));
0 commit comments