Skip to content

Commit d7d1ac0

Browse files
committed
bemf voltage open loop bug #219
1 parent d32d1ce commit d7d1ac0

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/BLDCMotor.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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));

src/StepperMotor.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ float StepperMotor::velocityOpenloop(float target_velocity){
377377

378378
// use voltage limit or current limit
379379
float Uq = voltage_limit;
380-
if(_isset(phase_resistance))
381-
Uq = _constrain(current_limit*phase_resistance + voltage_bemf,-voltage_limit, voltage_limit);
380+
if(_isset(phase_resistance)){
381+
Uq = _constrain(current_limit*phase_resistance + fabs(voltage_bemf),-voltage_limit, voltage_limit);
382+
// recalculate the current
383+
current.q = (Uq - fabs(voltage_bemf))/phase_resistance;
384+
}
382385

383386
// set the maximal allowed voltage (voltage_limit) with the necessary angle
384387
setPhaseVoltage(Uq, 0, _electricalAngle(shaft_angle, pole_pairs));
@@ -412,8 +415,11 @@ float StepperMotor::angleOpenloop(float target_angle){
412415

413416
// use voltage limit or current limit
414417
float Uq = voltage_limit;
415-
if(_isset(phase_resistance))
416-
Uq = _constrain(current_limit*phase_resistance + voltage_bemf,-voltage_limit, voltage_limit);
418+
if(_isset(phase_resistance)){
419+
Uq = _constrain(current_limit*phase_resistance + fabs(voltage_bemf),-voltage_limit, voltage_limit);
420+
// recalculate the current
421+
current.q = (Uq - fabs(voltage_bemf))/phase_resistance;
422+
}
417423
// set the maximal allowed voltage (voltage_limit) with the necessary angle
418424
setPhaseVoltage(Uq, 0, _electricalAngle((shaft_angle), pole_pairs));
419425

0 commit comments

Comments
 (0)