Fix spidev
This commit is contained in:
parent
eafad7ccdb
commit
ce7094b5cf
2 changed files with 8 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in a new issue