Skip to content

Oving 3 follow line #17

Merged
merged 3 commits into from
Sep 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions oving_3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from rtttl_player import RTTTLPlayer
from random import randint
import time



Expand All @@ -33,13 +34,49 @@
]

# 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.B)
rightMotor = Motor(port=Port.C)
robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=160)

robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=110)
startBtn = TouchSensor(port=Port.S1)
usSensor = UltrasonicSensor(port=Port.S3)

robotDriveBase.drive(1000, 0)
leftColorSensor = ColorSensor(port=Port.S2)
rightColorSensor = ColorSensor(port=Port.S4)

speaker = ev3.speaker

leftSensorThreshold = 9
rigthSensorThreshold = 9

currentTime = time.time()
lastCorrectino = currentTime
lastDirection = 1

while True:
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() < leftSensorThreshold:
robotDriveBase.drive(-100, 25)
lastCorrectino == currentTime
lastDirection = 1
continue

if rightColorSensor.reflection() < rigthSensorThreshold:
robotDriveBase.drive(-100, -25)
lastCorrectino = currentTime
lastDirection = -1
continue

robotDriveBase.drive(-100, 50)