Merge branch 'master' of github.com:F-WuTS/compLIB

This commit is contained in:
Konstantin Lampalzer 2021-09-05 12:20:29 +02:00
commit 7aa415f860
4 changed files with 25 additions and 11 deletions

View file

@ -44,7 +44,11 @@ class Encoder(object):
if port <= 0 or port > MOTOR_COUNT: if port <= 0 or port > MOTOR_COUNT:
raise IndexError("Invalid encoder port specified!") raise IndexError("Invalid encoder port specified!")
return Encoder.read_raw(port) - encoder_start_values[port] diff = Encoder.read_raw(port) - encoder_start_values[port]
if diff > 2 ** 31:
diff -= 2 ** 32
return diff
@staticmethod @staticmethod
def clear(port: int): def clear(port: int):
@ -58,6 +62,11 @@ class Encoder(object):
encoder_start_values[port] = Encoder.read_raw(port) encoder_start_values[port] = Encoder.read_raw(port)
@staticmethod
def clear_all():
"""Reset all encoder positions to 0
"""
for i in range(1, MOTOR_COUNT + 1): for i in range(1, MOTOR_COUNT + 1):
encoder_start_values[i] = Encoder.read_raw(i) encoder_start_values[i] = Encoder.read_raw(i)

View file

@ -1,6 +1,7 @@
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
import time import time
GPIO.setwarnings(False)
RESET_PIN = 23 RESET_PIN = 23
@ -13,4 +14,4 @@ class Reset:
GPIO.output(RESET_PIN, GPIO.LOW) GPIO.output(RESET_PIN, GPIO.LOW)
time.sleep(0.1) time.sleep(0.1)
GPIO.output(RESET_PIN, GPIO.HIGH) GPIO.output(RESET_PIN, GPIO.HIGH)
time.sleep(0.5) time.sleep(1.5)

View file

@ -174,13 +174,14 @@ class Spi(object):
print("Unable to read Version! Make sure the mainboard is connected!") print("Unable to read Version! Make sure the mainboard is connected!")
sys.exit() sys.exit()
@staticmethod
def start_health_check_loop():
health_check_thread = Thread(target=Spi.health_check_loop)
health_check_thread.setDaemon(True)
health_check_thread.start()
@staticmethod @staticmethod
def health_check_loop(): def health_check_loop():
while True: while True:
Spi.health_check() Spi.health_check()
time.sleep(0.5) time.sleep(0.5)
health_check_thread = Thread(target=Spi.health_check_loop)
health_check_thread.setDaemon(True)
health_check_thread.start()

View file

@ -3,6 +3,7 @@ __version__ = "0.1.5-1"
import compLib.LogstashLogging import compLib.LogstashLogging
import compLib.Spi import compLib.Spi
import compLib.Reset import compLib.Reset
import compLib.Encoder
import logging import logging
import apt import apt
@ -19,3 +20,5 @@ except Exception as e:
compLib.Reset.Reset.reset_bot() compLib.Reset.Reset.reset_bot()
compLib.Spi.Spi.health_check() compLib.Spi.Spi.health_check()
compLib.Spi.Spi.start_health_check_loop()
compLib.Encoder.Encoder.clear_all()