From 74672d6653ed6c146bcce6eb4df915feea77d1a0 Mon Sep 17 00:00:00 2001 From: Martin Aronsen Date: Tue, 30 Sep 2025 15:12:14 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Satt=20opp=20prosjekt=20for=20=C3=B8ving=20?= =?UTF-8?q?4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oving_4/.gitignore | 3 +++ oving_4/.vscode/extensions.json | 13 ++++++++++++ oving_4/.vscode/launch.json | 15 +++++++++++++ oving_4/.vscode/settings.json | 7 +++++++ oving_4/main.py | 18 ++++++++++++++++ oving_4/robot.py | 37 +++++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 oving_4/.gitignore create mode 100644 oving_4/.vscode/extensions.json create mode 100644 oving_4/.vscode/launch.json create mode 100644 oving_4/.vscode/settings.json create mode 100644 oving_4/main.py create mode 100644 oving_4/robot.py diff --git a/oving_4/.gitignore b/oving_4/.gitignore new file mode 100644 index 0000000..00f2d38 --- /dev/null +++ b/oving_4/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +.venv/ diff --git a/oving_4/.vscode/extensions.json b/oving_4/.vscode/extensions.json new file mode 100644 index 0000000..f8f1a44 --- /dev/null +++ b/oving_4/.vscode/extensions.json @@ -0,0 +1,13 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "lego-education.ev3-micropython" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + "ms-python.python" + ] +} \ No newline at end of file diff --git a/oving_4/.vscode/launch.json b/oving_4/.vscode/launch.json new file mode 100644 index 0000000..d933aeb --- /dev/null +++ b/oving_4/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Download and Run", + "type": "ev3devBrowser", + "request": "launch", + "program": "/home/robot/${workspaceRootFolderName}/main.py", + "interactiveTerminal": false + } + ] +} diff --git a/oving_4/.vscode/settings.json b/oving_4/.vscode/settings.json new file mode 100644 index 0000000..b0968c1 --- /dev/null +++ b/oving_4/.vscode/settings.json @@ -0,0 +1,7 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.eol": "\n", + "debug.openDebug": "neverOpen", + "python.linting.enabled": false, + "python.languageServer": "None" +} diff --git a/oving_4/main.py b/oving_4/main.py new file mode 100644 index 0000000..03f4e87 --- /dev/null +++ b/oving_4/main.py @@ -0,0 +1,18 @@ +from robot import * + + +driveMotors = (Motor(port=Port.A), # Left motor for the drive base + Motor(port=Port.C)) # Right motor for the drive base + +dimensions = (56, # Wheel diameter + 114) # Axle track + +clrSnrs = (ColorSensor(port=Port.S2), # Left color sensor + ColorSensor(port=Port.S4)) # Right color sensor + + +robot = Robot(driveMotors, dimensions, clrSnrs) + +robot.print("Hello World!") + + diff --git a/oving_4/robot.py b/oving_4/robot.py new file mode 100644 index 0000000..7108dce --- /dev/null +++ b/oving_4/robot.py @@ -0,0 +1,37 @@ +from pybricks.hubs import EV3Brick +from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, + InfraredSensor, UltrasonicSensor, GyroSensor) +from pybricks.parameters import Port, Stop, Direction, Button, Color +from pybricks.tools import wait, StopWatch, DataLog +from pybricks.robotics import DriveBase +from pybricks.media.ev3dev import SoundFile, ImageFile + +from rttl_player import RTTTLPlayer + +# This program requires LEGO EV3 MicroPython v2.0 or higher. +# Click "Open user guide" on the EV3 extension tab for more information. + + +class Robot(): + def __init__(self, motors: tuple, dimensions: tuple, colorSensors: tuple): + + leftMotor, rightMotor = motors + wd, axlTrck = dimensions + rightClrSnsr, leftClrSnsr = colorSensors + + + self.hub = EV3Brick() + self.driveBase = DriveBase(leftMotor, rightMotor, + wheel_diameter=wd, axle_track=axlTrck) + + self.rightColor = rightClrSnsr + self.leftColor = leftClrSnsr + + def print(self, message: str): + self.hub.screen.print(message) + + def sing(self, rttlString: str, tempo_scale: float = 1.0): + player = RTTTLPlayer(self.hub, rttlString) + player.play(tempo_scale) + + \ No newline at end of file From 957aeddcce0187ccdc84679f922753dd496c9b77 Mon Sep 17 00:00:00 2001 From: Martin Aronsen Date: Fri, 3 Oct 2025 01:05:58 +0200 Subject: [PATCH 2/3] =?UTF-8?q?F=C3=A5tt=20robott=20til=20=C3=A5=20kj?= =?UTF-8?q?=C3=B8re=20frem=20med=20fargesensorer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes Sandbox/.gitignore | 3 ++ Sandbox/.vscode/extensions.json | 13 ++++++ Sandbox/.vscode/launch.json | 15 +++++++ Sandbox/.vscode/settings.json | 7 +++ Sandbox/main.py | 30 +++++++++++++ oving_4/main.py | 75 +++++++++++++++++++++++++++++--- oving_4/robot.py | 37 ---------------- 8 files changed, 138 insertions(+), 42 deletions(-) create mode 100644 Sandbox/.gitignore create mode 100644 Sandbox/.vscode/extensions.json create mode 100644 Sandbox/.vscode/launch.json create mode 100644 Sandbox/.vscode/settings.json create mode 100644 Sandbox/main.py delete mode 100644 oving_4/robot.py diff --git a/.DS_Store b/.DS_Store index c141d4052d8cd825ae1b7040e71a7f2ad50c396a..7d143e187dd093b5badb5b3059cc686fb6ca7032 100644 GIT binary patch delta 53 zcmZoMXfc@J&&awlU^gQp>t-G%RYq}khJ1!HhD?S$hIEE_29uQH delta 32 ocmZoMXfc@J&&aYdU^gQp%Vr)XRmROe%)418Hb`$~=lIJH0G^czu>b%7 diff --git a/Sandbox/.gitignore b/Sandbox/.gitignore new file mode 100644 index 0000000..00f2d38 --- /dev/null +++ b/Sandbox/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +.venv/ diff --git a/Sandbox/.vscode/extensions.json b/Sandbox/.vscode/extensions.json new file mode 100644 index 0000000..f8f1a44 --- /dev/null +++ b/Sandbox/.vscode/extensions.json @@ -0,0 +1,13 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "lego-education.ev3-micropython" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + "ms-python.python" + ] +} \ No newline at end of file diff --git a/Sandbox/.vscode/launch.json b/Sandbox/.vscode/launch.json new file mode 100644 index 0000000..d933aeb --- /dev/null +++ b/Sandbox/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Download and Run", + "type": "ev3devBrowser", + "request": "launch", + "program": "/home/robot/${workspaceRootFolderName}/main.py", + "interactiveTerminal": false + } + ] +} diff --git a/Sandbox/.vscode/settings.json b/Sandbox/.vscode/settings.json new file mode 100644 index 0000000..b0968c1 --- /dev/null +++ b/Sandbox/.vscode/settings.json @@ -0,0 +1,7 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.eol": "\n", + "debug.openDebug": "neverOpen", + "python.linting.enabled": false, + "python.languageServer": "None" +} diff --git a/Sandbox/main.py b/Sandbox/main.py new file mode 100644 index 0000000..b8793ff --- /dev/null +++ b/Sandbox/main.py @@ -0,0 +1,30 @@ +#!/usr/bin/env pybricks-micropython +from pybricks.hubs import EV3Brick +from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, + InfraredSensor, UltrasonicSensor, GyroSensor) +from pybricks.parameters import Port, Stop, Direction, Button, Color +from pybricks.tools import wait, StopWatch, DataLog +from pybricks.robotics import DriveBase +from pybricks.media.ev3dev import SoundFile, ImageFile + + +# This program requires LEGO EV3 MicroPython v2.0 or higher. +# Click "Open user guide" on the EV3 extension tab for more information. + + +# Create your objects here. +ev3 = EV3Brick() + + +# Write your program here. +ev3.speaker.beep() + + +rotMotor = Motor(port=Port.D) + +while True: + rotMotor.run_target(100, 45) + wait(100) + rotMotor.run_target(100, -45) + wait(100) + rotMotor.run_target(100, 45) \ No newline at end of file diff --git a/oving_4/main.py b/oving_4/main.py index 03f4e87..d1fce21 100644 --- a/oving_4/main.py +++ b/oving_4/main.py @@ -1,18 +1,83 @@ -from robot import * +#!/usr/bin/env pybricks-micropython +from pybricks.hubs import EV3Brick +from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, + InfraredSensor, UltrasonicSensor, GyroSensor) +from pybricks.parameters import Port, Stop, Direction, Button, Color +from pybricks.tools import wait, StopWatch, DataLog +from pybricks.robotics import DriveBase +from pybricks.media.ev3dev import SoundFile, ImageFile -driveMotors = (Motor(port=Port.A), # Left motor for the drive base - Motor(port=Port.C)) # Right motor for the drive base +# This program requires LEGO EV3 MicroPython v2.0 or higher. +# Click "Open user guide" on the EV3 extension tab for more information. + + +from rttl_player import RTTTLPlayer + +class Robot(): + def __init__(self, motors: tuple, dimensions: tuple, colorSensors: tuple, rotMotor: Motor): + + leftMotor, rightMotor = motors + wd, axlTrck = dimensions + leftClrSnsr, rightClrSnsr = colorSensors + + self.hub = EV3Brick() + self.driveBase = DriveBase(leftMotor, rightMotor, + wheel_diameter=wd, axle_track=axlTrck) + + self.rightColor = rightClrSnsr + self.leftColor = leftClrSnsr + + self.rotation = rotMotor + + def print(self, message: str): + self.hub.screen.print(message) + + def sing(self, rttlString: str, tempo_scale: float = 1.0): + player = RTTTLPlayer(self.hub, rttlString) + player.play(tempo_scale) + + + +driveMotors = (Motor(port=Port.D), # Left motor for the drive base + Motor(port=Port.A)) # Right motor for the drive base dimensions = (56, # Wheel diameter 114) # Axle track clrSnrs = (ColorSensor(port=Port.S2), # Left color sensor - ColorSensor(port=Port.S4)) # Right color sensor + ColorSensor(port=Port.S1)) # Right color sensor +rotMotor = Motor(port=Port.C) -robot = Robot(driveMotors, dimensions, clrSnrs) +robot = Robot(driveMotors, dimensions, clrSnrs, rotMotor) robot.print("Hello World!") +robot.driveBase.drive(-200,0) + + +while True: + + if(robot.leftColor.reflection() < 10): + robot.rotation.run_target(100, -15) + while robot.leftColor.reflection() < 10: + if (robot.leftColor.reflection() > 10): + break + robot.rotation.run_target(100, 15) + continue + + if(robot.rightColor.reflection() < 10): + robot.rotation.run_target(100, 15) + while robot.rightColor.reflection() < 10: + if (robot.rightColor.reflection() > 10): + break + robot.rotation.run_target(100, -15) + + """ + wait(100) + robot.rotation.run_target(100, -30) + wait(100) """ + + diff --git a/oving_4/robot.py b/oving_4/robot.py deleted file mode 100644 index 7108dce..0000000 --- a/oving_4/robot.py +++ /dev/null @@ -1,37 +0,0 @@ -from pybricks.hubs import EV3Brick -from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, - InfraredSensor, UltrasonicSensor, GyroSensor) -from pybricks.parameters import Port, Stop, Direction, Button, Color -from pybricks.tools import wait, StopWatch, DataLog -from pybricks.robotics import DriveBase -from pybricks.media.ev3dev import SoundFile, ImageFile - -from rttl_player import RTTTLPlayer - -# This program requires LEGO EV3 MicroPython v2.0 or higher. -# Click "Open user guide" on the EV3 extension tab for more information. - - -class Robot(): - def __init__(self, motors: tuple, dimensions: tuple, colorSensors: tuple): - - leftMotor, rightMotor = motors - wd, axlTrck = dimensions - rightClrSnsr, leftClrSnsr = colorSensors - - - self.hub = EV3Brick() - self.driveBase = DriveBase(leftMotor, rightMotor, - wheel_diameter=wd, axle_track=axlTrck) - - self.rightColor = rightClrSnsr - self.leftColor = leftClrSnsr - - def print(self, message: str): - self.hub.screen.print(message) - - def sing(self, rttlString: str, tempo_scale: float = 1.0): - player = RTTTLPlayer(self.hub, rttlString) - player.play(tempo_scale) - - \ No newline at end of file From 602cc768d0327f0ca894378f5b40301659b50366 Mon Sep 17 00:00:00 2001 From: Martin Aronsen Date: Wed, 5 Nov 2025 11:14:43 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Gjort=20ferdig=20=C3=98ving=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes Sandbox/main.py | 8 ---- oving_4/main.py | 46 +++++++++++++-------- rotTest/.gitignore | 3 ++ rotTest/.vscode/extensions.json | 13 ++++++ rotTest/.vscode/launch.json | 15 +++++++ rotTest/.vscode/settings.json | 7 ++++ rotTest/main.py | 70 ++++++++++++++++++++++++++++++++ 8 files changed, 137 insertions(+), 25 deletions(-) create mode 100644 rotTest/.gitignore create mode 100644 rotTest/.vscode/extensions.json create mode 100644 rotTest/.vscode/launch.json create mode 100644 rotTest/.vscode/settings.json create mode 100644 rotTest/main.py diff --git a/.DS_Store b/.DS_Store index 7d143e187dd093b5badb5b3059cc686fb6ca7032..c04c832de4524205f655ea33a109beaefb7eb359 100644 GIT binary patch delta 45 zcmZoMXfc@J&&akhU^gQp+h!gnF-Fdm;^ds9{QMk-$pXw4j0~GSnHRHcX6N|J4*(># B44D7` delta 38 ucmZoMXfc@J&&awlU^gQp>t-G%F~-TZ%xa8`n^Tw 10): - break - robot.rotation.run_target(100, 15) - continue - + robot.print(robot.rotation.angle()) if(robot.rightColor.reflection() < 10): - robot.rotation.run_target(100, 15) - while robot.rightColor.reflection() < 10: - if (robot.rightColor.reflection() > 10): - break - robot.rotation.run_target(100, -15) + robot.turn(right) + + if(robot.leftColor.reflection() < 10): + robot.turn(left) + """ wait(100) robot.rotation.run_target(100, -30) diff --git a/rotTest/.gitignore b/rotTest/.gitignore new file mode 100644 index 0000000..00f2d38 --- /dev/null +++ b/rotTest/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +.venv/ diff --git a/rotTest/.vscode/extensions.json b/rotTest/.vscode/extensions.json new file mode 100644 index 0000000..f8f1a44 --- /dev/null +++ b/rotTest/.vscode/extensions.json @@ -0,0 +1,13 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "lego-education.ev3-micropython" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + "ms-python.python" + ] +} \ No newline at end of file diff --git a/rotTest/.vscode/launch.json b/rotTest/.vscode/launch.json new file mode 100644 index 0000000..d933aeb --- /dev/null +++ b/rotTest/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Download and Run", + "type": "ev3devBrowser", + "request": "launch", + "program": "/home/robot/${workspaceRootFolderName}/main.py", + "interactiveTerminal": false + } + ] +} diff --git a/rotTest/.vscode/settings.json b/rotTest/.vscode/settings.json new file mode 100644 index 0000000..b0968c1 --- /dev/null +++ b/rotTest/.vscode/settings.json @@ -0,0 +1,7 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.eol": "\n", + "debug.openDebug": "neverOpen", + "python.linting.enabled": false, + "python.languageServer": "None" +} diff --git a/rotTest/main.py b/rotTest/main.py new file mode 100644 index 0000000..38a0fb7 --- /dev/null +++ b/rotTest/main.py @@ -0,0 +1,70 @@ +#!/usr/bin/env pybricks-micropython +from pybricks.hubs import EV3Brick +from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, + InfraredSensor, UltrasonicSensor, GyroSensor) +from pybricks.parameters import Port, Stop, Direction, Button, Color +from pybricks.tools import wait, StopWatch, DataLog +from pybricks.robotics import DriveBase +from pybricks.media.ev3dev import SoundFile, ImageFile + + +# This program requires LEGO EV3 MicroPython v2.0 or higher. +# Click "Open user guide" on the EV3 extension tab for more information. + + +class Robot(): + def __init__(self, motors: tuple, dimensions: tuple, colorSensors: tuple, rotMotor: Motor): + + leftMotor, rightMotor = motors + wd, axlTrck = dimensions + leftClrSnsr, rightClrSnsr = colorSensors + self.currentDirection = 0 + + self.hub = EV3Brick() + self.driveBase = DriveBase(leftMotor, rightMotor, + wheel_diameter=wd, axle_track=axlTrck) + + self.rightColor = rightClrSnsr + self.leftColor = leftClrSnsr + + self.rotation = rotMotor + + + def print(self, message: str): + self.hub.screen.print(message) + + def turn(self, direction): + if direction == self.currentDirection: + return + self.currentDirection = direction + + if direction == left: + robot.rotation.track_target(left * 30) + robot.driveBase.drive(speed, left * 90) + return + else: + robot.rotation.track_target(defaultAngle) + robot.rotation.run(right * 30) + robot.driveBase.drive(speed, right * 40) + + + + +driveMotors = (Motor(port=Port.D, positive_direction=Direction.COUNTERCLOCKWISE), # Left motor for the drive base + Motor(port=Port.A, positive_direction=Direction.COUNTERCLOCKWISE)) # Right motor for the drive base + +dimensions = (56, # Wheel diameter + 114) # Axle track + +clrSnrs = (ColorSensor(port=Port.S2), # Left color sensor + ColorSensor(port=Port.S1)) # Right color sensor + +rotMotor = Motor(port=Port.C) +left, right = -1, 1 +defaultAngle = 0 +speed = 500 + +robot = Robot(driveMotors, dimensions, clrSnrs, rotMotor) + +robot.turn(left) +