diff --git a/oving_3/main.py b/oving_3/main.py index e7c4963..b7189b5 100644 --- a/oving_3/main.py +++ b/oving_3/main.py @@ -34,13 +34,13 @@ ] # Lag spiller og kjør -player = RTTTLPlayer(ev3, songs[3]) +#player = RTTTLPlayer(ev3, songs[3]) #ev3.screen.print("Spiller", player.name, "...") #player.play() leftMotor = Motor(port=Port.A) rightMotor = Motor(port=Port.C) -robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=110) +robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=160) startBtn = TouchSensor(port=Port.S1) usSensor = UltrasonicSensor(port=Port.S3) @@ -48,27 +48,34 @@ leftColorSensor = ColorSensor(port=Port.S2) rightColorSensor = ColorSensor(port=Port.S4) -BLACK = 9 -WHITE = 85 -threshold = (BLACK + WHITE) / 2 +speaker = ev3.speaker -lastCorrectino = time.time() +leftSensorThreshold = 9 +rigthSensorThreshold = 9 + +currentTime = time.time() +lastCorrectino = currentTime lastDirection = 1 while True: - if time.time() - lastCorrectino > 1: + currentTime = time.time() + + if currentTime - lastCorrectino > 2: while leftColorSensor.reflection() > 10 or rightColorSensor.reflection() < 10: robotDriveBase.drive(-100, 50 * lastDirection) + + lastCorrectino = time.time() + continue - if leftColorSensor.reflection() < 10: - robotDriveBase.drive(-100, 50) - lastCorrectino == time.time() + if leftColorSensor.reflection() < leftSensorThreshold: + robotDriveBase.drive(-100, 25) + lastCorrectino == currentTime lastDirection = 1 continue - elif rightColorSensor.reflection() < 10: - robotDriveBase.drive(-100, -50) - lastCorrectino = time.time() + if rightColorSensor.reflection() < rigthSensorThreshold: + robotDriveBase.drive(-100, -25) + lastCorrectino = currentTime lastDirection = -1 continue