From a3681d4288c92245cd274fb89fff8b12c459921b Mon Sep 17 00:00:00 2001 From: Martin Aronsen Date: Fri, 24 Oct 2025 13:08:32 +0200 Subject: [PATCH] Laget klasser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deklarert diverse klasser for funksjonalitet på robotten. --- py/src/color_sensor.py | 0 py/src/drive.py | 22 ++++++++++++++++++++++ py/src/main.py | 18 ++++++++++++++---- py/src/robot.py | 21 +++++++++++++++++++++ py/src/sensors.py | 17 +++++++++++++++++ py/src/water.py | 0 py/src/water_bucket.py | 10 ++++++++++ 7 files changed, 84 insertions(+), 4 deletions(-) delete mode 100644 py/src/color_sensor.py create mode 100644 py/src/sensors.py delete mode 100644 py/src/water.py create mode 100644 py/src/water_bucket.py diff --git a/py/src/color_sensor.py b/py/src/color_sensor.py deleted file mode 100644 index e69de29..0000000 diff --git a/py/src/drive.py b/py/src/drive.py index e9051b7..d8fa68c 100644 --- a/py/src/drive.py +++ b/py/src/drive.py @@ -1,2 +1,24 @@ #Fil for programmering av kjøring +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.robotics import DriveBase + +class Drive(): + def __init__(self, motors: tuple, dimensions: tuple): + leftMotor, rightMotor = motors + wheelDiameter, axleTrack = dimensions + + + self.driveBase = DriveBase(leftMotor, rightMotor, + wheel_diameter=wheelDiameter, axle_track=axleTrack) + + + def forward(self, speed): + pass + + def backward(self, speed): + pass + \ No newline at end of file diff --git a/py/src/main.py b/py/src/main.py index 9e9700f..5cf4150 100644 --- a/py/src/main.py +++ b/py/src/main.py @@ -7,14 +7,24 @@ from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile +from drive import Drive +from sensors import Sensors +from robot import Robot + # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. +dimensions = ( # Wheel diamter + ) #Axle track + +motors = (Motor(port=Port.D), # Left motor for the drive base + Motor(port=Port.A)) # Right motor for the drive base -# Create your objects here. -ev3 = EV3Brick() +sensors = (ColorSensor(port=Port.S1), # Lyssensor for å måle fargen på jorda + UltrasonicSensor(port=Port.S2)) # Ultrasonisksensor for å sjekke for potensielle hindringer robotten må navigere unna +robotDrive = Drive(motors, dimensions) # Robottens kjørefunksjonalitet +robotSensors = Sensors(sensors) # Robottens sensorfunksjonalitet -# Write your program here. -ev3.speaker.beep() +robot = Robot(robotDrive, robotSensors) # EV3 robot diff --git a/py/src/robot.py b/py/src/robot.py index e69de29..dd2c32f 100644 --- a/py/src/robot.py +++ b/py/src/robot.py @@ -0,0 +1,21 @@ +#Overklasse for all robot funksjonalitet +#!/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 + +from drive import Drive +from sensors import Sensors + +class Robot(): + def __init__(self, drive: Drive, sensors: Sensors): + self.hub = EV3Brick() + self.drive = drive + self.sensors = sensors + + + diff --git a/py/src/sensors.py b/py/src/sensors.py new file mode 100644 index 0000000..d9e2f0e --- /dev/null +++ b/py/src/sensors.py @@ -0,0 +1,17 @@ + +#!/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 + +class Sensors(): + def __init__(self, colorSensor: ColorSensor, ultrasonicSensor: UltrasonicSensor): + + self.color = colorSensor + self.ultrasonic = ultrasonicSensor + + \ No newline at end of file diff --git a/py/src/water.py b/py/src/water.py deleted file mode 100644 index e69de29..0000000 diff --git a/py/src/water_bucket.py b/py/src/water_bucket.py new file mode 100644 index 0000000..d321f16 --- /dev/null +++ b/py/src/water_bucket.py @@ -0,0 +1,10 @@ + +#!/usr/bin/env pybricks-micropython +from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, + InfraredSensor, UltrasonicSensor, GyroSensor) +from pybricks.parameters import Port, Stop, Direction, Button, Color + + +class WaterBucket: + def __init__(self): + pass \ No newline at end of file