Logging, more documentation

This commit is contained in:
Konstantin Lampalzer 2021-01-23 13:37:40 +01:00
parent 6eebab871e
commit 4a5f630d40
No known key found for this signature in database
GPG key ID: 9A60A522835A2AD9
11 changed files with 66 additions and 27 deletions

View file

@ -16,16 +16,20 @@ class Motor(object):
"""
@staticmethod
def power(port: int, percent: int):
def power(port: int, percent: float):
"""Set specified motor to percentage power
:param port: Port, which the motor is connected to. 0-3, 0 -> top left, 3 -> top right
:param percent: Percentage of max speed. between -100 and 100
:raises: IndexError
"""
Logging.get_logger().debug(f"Motor.power {port} {percent}")
if port < 0 or port >= MOTOR_COUNT:
raise IndexError("Invalid Motor port specified!")
raise IndexError("Invalid Motor port specified!")
if percent < -100 or percent > 100:
raise IndexError("Invalid Motor speed specified! Speed is between -100 and 100 percent!")
forward = True
if percent < 0:
@ -36,7 +40,7 @@ class Motor(object):
if port == 1:
forward = not forward
adjusted_speed = int(min(max(0, percent), 100) * MOTOR_PERCENTAGE_MULT)
adjusted_speed = int(min(max(0.0, percent), 100.0) * MOTOR_PERCENTAGE_MULT)
if forward:
pwm.setMotorPwm(port * 2, adjusted_speed)