From 9e61023e670c852700a1fbd613d75509726b9d1c Mon Sep 17 00:00:00 2001 From: Konstantin Lampalzer Date: Sat, 4 Sep 2021 14:50:43 +0100 Subject: [PATCH 1/3] Fixed reset delay --- compLib/Reset.py | 3 ++- compLib/Spi.py | 11 ++++++----- compLib/__init__.py | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/compLib/Reset.py b/compLib/Reset.py index 9c7fd7d..4767c1b 100644 --- a/compLib/Reset.py +++ b/compLib/Reset.py @@ -1,6 +1,7 @@ import RPi.GPIO as GPIO import time +GPIO.setwarnings(False) RESET_PIN = 23 @@ -13,4 +14,4 @@ class Reset: GPIO.output(RESET_PIN, GPIO.LOW) time.sleep(0.1) GPIO.output(RESET_PIN, GPIO.HIGH) - time.sleep(0.5) + time.sleep(1.5) diff --git a/compLib/Spi.py b/compLib/Spi.py index cab8ad9..5f6efb7 100644 --- a/compLib/Spi.py +++ b/compLib/Spi.py @@ -164,13 +164,14 @@ class Spi(object): print("Unable to read Version! Make sure the mainboard is connected!") 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 def health_check_loop(): while True: Spi.health_check() time.sleep(0.5) - - -health_check_thread = Thread(target=Spi.health_check_loop) -health_check_thread.setDaemon(True) -health_check_thread.start() \ No newline at end of file diff --git a/compLib/__init__.py b/compLib/__init__.py index d516a38..fa48d2a 100644 --- a/compLib/__init__.py +++ b/compLib/__init__.py @@ -18,4 +18,5 @@ except Exception as e: print(f"\033[91merror during checking apt package version -> {str(e)}\033[0m\n") compLib.Reset.Reset.reset_bot() -compLib.Spi.Spi.health_check() \ No newline at end of file +compLib.Spi.Spi.health_check() +compLib.Spi.Spi.start_health_check_loop() \ No newline at end of file From 3e7df14da89e99f757cccdca94dce2f25e65da88 Mon Sep 17 00:00:00 2001 From: Konstantin Lampalzer Date: Sat, 4 Sep 2021 15:00:33 +0100 Subject: [PATCH 2/3] Fixed Encoder clear at startup --- compLib/Encoder.py | 11 ++++++++--- compLib/__init__.py | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/compLib/Encoder.py b/compLib/Encoder.py index eddc77f..ae9c1a7 100644 --- a/compLib/Encoder.py +++ b/compLib/Encoder.py @@ -57,7 +57,12 @@ class Encoder(object): raise IndexError("Invalid encoder port specified!") encoder_start_values[port] = Encoder.read_raw(port) - -for i in range(1, MOTOR_COUNT + 1): - encoder_start_values[i] = Encoder.read_raw(i) \ No newline at end of file + @staticmethod + def clear_all(): + """Reset all encoder positions to 0 + """ + + for i in range(1, MOTOR_COUNT + 1): + encoder_start_values[i] = Encoder.read_raw(i) + \ No newline at end of file diff --git a/compLib/__init__.py b/compLib/__init__.py index fa48d2a..e67ec4b 100644 --- a/compLib/__init__.py +++ b/compLib/__init__.py @@ -3,6 +3,7 @@ __version__ = "0.1.5-1" import compLib.LogstashLogging import compLib.Spi import compLib.Reset +import compLib.Encoder import logging import apt @@ -19,4 +20,5 @@ except Exception as e: compLib.Reset.Reset.reset_bot() compLib.Spi.Spi.health_check() -compLib.Spi.Spi.start_health_check_loop() \ No newline at end of file +compLib.Spi.Spi.start_health_check_loop() +compLib.Encoder.Encoder.clear_all() \ No newline at end of file From 74f0f42d2fb0a44c48bd50424e8256e348273fe0 Mon Sep 17 00:00:00 2001 From: Konstantin Lampalzer Date: Sun, 5 Sep 2021 11:11:53 +0100 Subject: [PATCH 3/3] Fixed encoder overflow --- compLib/Encoder.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compLib/Encoder.py b/compLib/Encoder.py index ae9c1a7..3ede960 100644 --- a/compLib/Encoder.py +++ b/compLib/Encoder.py @@ -44,7 +44,11 @@ class Encoder(object): if port <= 0 or port > MOTOR_COUNT: 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 def clear(port: int):