diff --git a/.DS_Store b/.DS_Store index c141d40..c04c832 100644 Binary files a/.DS_Store and b/.DS_Store differ 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..cd5cb5d --- /dev/null +++ b/Sandbox/main.py @@ -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() + + 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..21ffd46 --- /dev/null +++ b/oving_4/main.py @@ -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) """ + + 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) +