Skip to content

Commit 920a758

Browse files
committed
Use constrain to limit restAngle
1 parent 433287e commit 920a758

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

Firmware/Balanduino/Motor.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ void updatePID(double restAngle, double offset, double turning, double dt) {
4646
restAngle -= offset;
4747
}
4848

49-
if (restAngle - lastRestAngle > 1) // Don't change restAngle with more than 1 degree in each loop
50-
restAngle = lastRestAngle + 1;
51-
else if (restAngle - lastRestAngle < -1)
52-
restAngle = lastRestAngle - 1;
49+
restAngle = constrain(restAngle, lastRestAngle - 1, lastRestAngle + 1); // Don't change restAngle with more than 1 degree in each loop
5350
lastRestAngle = restAngle;
5451

5552
/* Update PID values */

0 commit comments

Comments
 (0)