Skip to content

Commit 7de09e1

Browse files
committed
FIX open-loop velocity float bug
1 parent 03d57fb commit 7de09e1

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

src/BLDCMotor.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,7 @@ void BLDCMotor::velocityOpenloop(float target_velocity){
388388
float Ts = (now_us - open_loop_timestamp) * 1e-6;
389389

390390
// calculate the necessary angle to achieve target velocity
391-
shaft_angle += target_velocity*Ts;
392-
393-
// check if shaft_angle gets too large
394-
if (shaft_angle >= (_2PI * 4))
395-
{
396-
shaft_angle = 0;
397-
}
391+
shaft_angle = _normalizeAngle(shaft_angle + target_velocity*Ts);
398392

399393
// set the maximal allowed voltage (voltage_limit) with the necessary angle
400394
setPhaseVoltage(voltage_limit, 0, _electricalAngle(shaft_angle, pole_pairs));

src/StepperMotor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void StepperMotor::velocityOpenloop(float target_velocity){
247247
float Ts = (now_us - open_loop_timestamp) * 1e-6;
248248

249249
// calculate the necessary angle to achieve target velocity
250-
shaft_angle += target_velocity*Ts;
250+
shaft_angle = _normalizeAngle(shaft_angle + target_velocity*Ts);
251251

252252
// set the maximal allowed voltage (voltage_limit) with the necessary angle
253253
setPhaseVoltage(voltage_limit, 0, _electricalAngle(shaft_angle,pole_pairs));

0 commit comments

Comments
 (0)