Skip to content

Commit

Permalink
Merge pull request #21 from IDATT1004-Team13-H2025/oving-4
Browse files Browse the repository at this point in the history
Oving 4
  • Loading branch information
martaron authored Nov 5, 2025
2 parents eddc160 + 602cc76 commit 08c882b
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions Sandbox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
.venv/
13 changes: 13 additions & 0 deletions Sandbox/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
15 changes: 15 additions & 0 deletions Sandbox/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
7 changes: 7 additions & 0 deletions Sandbox/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
22 changes: 22 additions & 0 deletions Sandbox/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/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()


3 changes: 3 additions & 0 deletions oving_4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
.venv/
13 changes: 13 additions & 0 deletions oving_4/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
15 changes: 15 additions & 0 deletions oving_4/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
7 changes: 7 additions & 0 deletions oving_4/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
95 changes: 95 additions & 0 deletions oving_4/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/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.


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.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 sing(self, rttlString: str, tempo_scale: float = 1.0):
player = RTTTLPlayer(self.hub, rttlString)
player.play(tempo_scale)

def turn(self, direction):
if direction == self.currentDirection:
return
self.currentDirection = direction

if direction == left:
robot.rotation.track_target(left * 20)
robot.driveBase.drive(speed, left * 80)
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.print("Hello World!")


robot.driveBase.drive(speed,0)


while True:
robot.print(robot.rotation.angle())
if(robot.rightColor.reflection() < 10):
robot.turn(right)

if(robot.leftColor.reflection() < 10):
robot.turn(left)


"""
wait(100)
robot.rotation.run_target(100, -30)
wait(100) """


3 changes: 3 additions & 0 deletions rotTest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
.venv/
13 changes: 13 additions & 0 deletions rotTest/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
15 changes: 15 additions & 0 deletions rotTest/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
7 changes: 7 additions & 0 deletions rotTest/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
70 changes: 70 additions & 0 deletions rotTest/main.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 08c882b

Please sign in to comment.