Skip to content

Commit

Permalink
roboten følger linjen
Browse files Browse the repository at this point in the history
  • Loading branch information
Odin Grav committed Sep 17, 2025
1 parent 8899850 commit bdfe43e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions oving_3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,48 @@
]

# 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)

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

Expand Down

0 comments on commit bdfe43e

Please sign in to comment.