Logging, more documentation
This commit is contained in:
parent
6eebab871e
commit
4a5f630d40
11 changed files with 66 additions and 27 deletions
|
@ -26,6 +26,7 @@ asynchronousLogstashHandler = AsynchronousLogstashHandler(
|
|||
database_path='logs.db'
|
||||
)
|
||||
|
||||
|
||||
class StreamToLogger(object):
|
||||
"""
|
||||
Fake file-like stream object that redirects writes to a logger instance.
|
||||
|
@ -53,6 +54,7 @@ class StreamToLogger(object):
|
|||
self.linebuf = ''
|
||||
asynchronousLogstashHandler.flush()
|
||||
|
||||
|
||||
try:
|
||||
r = requests.head(f"http://{host}:{port}")
|
||||
if r.status_code == 400:
|
||||
|
@ -67,12 +69,23 @@ except requests.exceptions.ConnectionError as identifier:
|
|||
print(f"Could not connect to {host}!")
|
||||
pass
|
||||
|
||||
|
||||
class Logging(object):
|
||||
"""Can be used to manually use the logger or turn up the logging level used for debugging this library.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_logger() -> logging.Logger:
|
||||
"""Get the logger object used to communicate with logstash
|
||||
|
||||
:return: Python logger
|
||||
:rtype: logging.Logger
|
||||
"""
|
||||
return logstash_logger
|
||||
|
||||
@staticmethod
|
||||
def set_debug():
|
||||
"""Turns up the logging level of the library to debug. Should be used, when debugging with the
|
||||
Competition organizers
|
||||
"""
|
||||
logstash_logger.setLevel(logging.DEBUG)
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in a new issue