-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from IDATT1004-Team13-H2025/oving-4
Oving 4
- Loading branch information
Showing
16 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| .venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| .venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) """ | ||
|
|
||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| .venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|