From ce7094b5cf477170b750f50e0de10f107d097371 Mon Sep 17 00:00:00 2001 From: Konstantin Lampalzer Date: Thu, 14 Oct 2021 13:59:20 +0200 Subject: [PATCH] Fix spidev --- compLib/Spi.py | 1 + docs/source/lib/Linefollower.rst | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/compLib/Spi.py b/compLib/Spi.py index 5f7d964..6e083bf 100644 --- a/compLib/Spi.py +++ b/compLib/Spi.py @@ -16,6 +16,7 @@ SPI_HEALTH = True spi_found = importlib.util.find_spec("spidev") is not None spi = None if spi_found: + import spidev spi = spidev.SpiDev() spi.open(SPI_BUS, SPI_DEVICE) spi.max_speed_hz = SPI_SPEED diff --git a/docs/source/lib/Linefollower.rst b/docs/source/lib/Linefollower.rst index 48fe4d3..41de752 100644 --- a/docs/source/lib/Linefollower.rst +++ b/docs/source/lib/Linefollower.rst @@ -21,18 +21,16 @@ Simple Linefollower IRSensor.set(4, True) IRSensor.set(5, True) - DRIVE_SPEED = 85 - TURN_SPEED = 50 - COLOR_BREAK = 750 - KP = 50.0 + DRIVE_SPEED = 75 + COLOR_BREAK = 900 + KP = 10.0 KD = 0.0 def drive(leftSpeed, rightSpeed): - leftSpeed *= -1 - rightSpeed *= 0.906 + rightSpeed *= -0.906 - Motor.power(1, min(max(-100, leftSpeed), 100)) - Motor.power(2, min(max(-100, rightSpeed), 100)) + Motor.power(1, min(max(-100, rightSpeed), 100)) + Motor.power(4, min(max(-100, leftSpeed), 100)) def follow(sleepTime = 0.1): lastError = 0 @@ -58,7 +56,7 @@ Simple Linefollower error = 3 elif error == -1.5: error = -3 - + lastError = error adjustment = KP * error + KD * (error - lastError)