From bb5f06ffef86379060ff5a6e515378bc343dc31e Mon Sep 17 00:00:00 2001 From: Odin Grav Date: Wed, 17 Sep 2025 09:11:06 +0200 Subject: [PATCH 1/3] =?UTF-8?q?started=20=C3=A5=20f=C3=A5=20robotten=20til?= =?UTF-8?q?=20=C3=A5=20f=C3=B8lge=20en=20linje?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oving_3/main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/oving_3/main.py b/oving_3/main.py index e4b38bf..937fbff 100644 --- a/oving_3/main.py +++ b/oving_3/main.py @@ -39,7 +39,19 @@ leftMotor = Motor(port=Port.A) rightMotor = Motor(port=Port.B) - robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=110) -robotDriveBase.drive(1000, 0) \ No newline at end of file +startBtn = TouchSensor(port=Port.S1) +usSensor = UltrasonicSensor(port=Port.S3) + +leftColorSensor = ColorSensor(port=Port.S2) +rightColorSensor = ColorSensor(port=Port.S4) + +while True: + if leftColorSensor.color() == Color.BLACK: + robotDriveBase.turn(5) + + elif rightColorSensor.color() == Color.BLACK: + robotDriveBase.turn(-5) + + DriveBase.run(100) \ No newline at end of file From 88998503d1133e6803da670263c1f012100a2ee0 Mon Sep 17 00:00:00 2001 From: Odin Grav Date: Wed, 17 Sep 2025 10:28:16 +0200 Subject: [PATCH 2/3] progress --- oving_3/main.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/oving_3/main.py b/oving_3/main.py index 937fbff..e7c4963 100644 --- a/oving_3/main.py +++ b/oving_3/main.py @@ -9,6 +9,7 @@ from rtttl_player import RTTTLPlayer from random import randint +import time @@ -38,7 +39,7 @@ #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=110) startBtn = TouchSensor(port=Port.S1) @@ -47,11 +48,28 @@ leftColorSensor = ColorSensor(port=Port.S2) rightColorSensor = ColorSensor(port=Port.S4) +BLACK = 9 +WHITE = 85 +threshold = (BLACK + WHITE) / 2 + +lastCorrectino = time.time() +lastDirection = 1 + while True: - if leftColorSensor.color() == Color.BLACK: - robotDriveBase.turn(5) + if time.time() - lastCorrectino > 1: + while leftColorSensor.reflection() > 10 or rightColorSensor.reflection() < 10: + robotDriveBase.drive(-100, 50 * lastDirection) - elif rightColorSensor.color() == Color.BLACK: - robotDriveBase.turn(-5) + if leftColorSensor.reflection() < 10: + robotDriveBase.drive(-100, 50) + lastCorrectino == time.time() + lastDirection = 1 + continue - DriveBase.run(100) \ No newline at end of file + elif rightColorSensor.reflection() < 10: + robotDriveBase.drive(-100, -50) + lastCorrectino = time.time() + lastDirection = -1 + continue + + robotDriveBase.drive(-100, 50) \ No newline at end of file From bdfe43ec00a3d8b0ba948f62f2c592f22bdd04af Mon Sep 17 00:00:00 2001 From: Odin Grav Date: Wed, 17 Sep 2025 12:56:32 +0200 Subject: [PATCH 3/3] =?UTF-8?q?roboten=20f=C3=B8lger=20linjen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oving_3/main.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) 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