Skip to content

Commit 3de7d34

Browse files
committed
motor: assert to validate rotations and degrees
1 parent b29bee1 commit 3de7d34

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ev3dev/motor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,20 @@ def wait_while(self, s, timeout=None):
726726
return self.wait(lambda state: s not in state, timeout)
727727

728728
def _set_position_rotations(self, speed_pct, rotations):
729+
730+
# +/- speed is used to control direction, rotations must be positive
731+
assert rotations >= 0, "rotations is %s, must be >= 0" % rotations
732+
729733
if speed_pct > 0:
730734
self.position_sp = self.position + int(rotations * self.count_per_rot)
731735
else:
732736
self.position_sp = self.position - int(rotations * self.count_per_rot)
733737

734738
def _set_position_degrees(self, speed_pct, degrees):
739+
740+
# +/- speed is used to control direction, degrees must be positive
741+
assert degrees >= 0, "degrees is %s, must be >= 0" % degrees
742+
735743
if speed_pct > 0:
736744
self.position_sp = self.position + int((degrees * self.count_per_rot)/360)
737745
else:

0 commit comments

Comments
 (0)