Skip to content

Commit

Permalink
Fikset krasj under kjøring
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsp committed Nov 5, 2025
1 parent a930dd2 commit 4a8bbba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
5 changes: 2 additions & 3 deletions py/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

try:
from drive import Drive
from sensors import Sensors
from robot import Robot

except Exception as e:
Expand All @@ -29,8 +28,8 @@
motors = (Motor(port=Port.D), # Left motor for the drive base
Motor(port=Port.C)) # Right motor for the drive base

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
sensors = (Port.S3, # Lyssensor for å måle fargen på jorda
Port.S1) # Ultrasonisksensor for å sjekke for potensielle hindringer robotten må navigere unna

robotDrive = Drive(motors, dimensions) # Robottens kjørefunksjonalitet
robot = Robot(robotDrive, *sensors) # EV3 robot
Expand Down
16 changes: 6 additions & 10 deletions py/src/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
from pybricks.media.ev3dev import SoundFile, ImageFile

from drive import Drive
from sensors import Sensors
from sensors import UltraSonic
from sensors import UltraSonic, Colour

class Robot():
def __init__(self, drive: Drive, colorSensor, ultrasonicSensor):
def __init__(self, drive: Drive, colorPort, ultrsonicPort):
self.hub = EV3Brick()
self.drive = drive
self.color = colorSensor
self.ultrasonic = ultrasonicSensor
self.color = Colour(colorPort)
self.ultrasonic = UltraSonic(ultrsonicPort)


def start(self):
Expand All @@ -26,12 +25,9 @@ def start(self):
while True:
wait(50)

UltrasonicSensor = UltraSonic(Port.S2)

if UltrasonicSensor is None:
continue


if UltrasonicSensor.distanceLessThan(100):
if self.ultrasonic.distanceLessThan(100):
self.drive.stop(0)
self.hub.speaker.beep()
wait(1000)
Expand Down
6 changes: 1 addition & 5 deletions py/src/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
GAMMEL SENSOR FUNKSJONALITET
BEHOLDES FREM TIL NY FUNKSJONALITET ER IMPLEMENTERT
"""
class Sensors():
def __init__(self, sensors: tuple):
self.color, self.ultrasonic = sensors



"""
Expand All @@ -39,7 +35,7 @@ def distanceLessThan(self, value):
return True


class Color():
class Colour():
def __init__(self, sensorPort):
self.sensor = ColorSensor(port=sensorPort)

Expand Down

0 comments on commit 4a8bbba

Please sign in to comment.