Skip to content

Commit 03d57fb

Browse files
authored
Merge pull request #37 from ATILIUS-REGULUS/open_loop_velocity
check for floating point error due to insufficient precision
2 parents 15cc0b3 + e9bfbba commit 03d57fb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/BLDCMotor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ void BLDCMotor::velocityOpenloop(float target_velocity){
390390
// calculate the necessary angle to achieve target velocity
391391
shaft_angle += target_velocity*Ts;
392392

393+
// check if shaft_angle gets too large
394+
if (shaft_angle >= (_2PI * 4))
395+
{
396+
shaft_angle = 0;
397+
}
398+
393399
// set the maximal allowed voltage (voltage_limit) with the necessary angle
394400
setPhaseVoltage(voltage_limit, 0, _electricalAngle(shaft_angle, pole_pairs));
395401

0 commit comments

Comments
 (0)