-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/AlanWang611/SET2023
- Loading branch information
Showing
4 changed files
with
54 additions
and
9 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,40 @@ | ||
import serial | ||
import time | ||
|
||
arduino = serial.Serial(port='COM5', baudrate=115200, timeout=.1) | ||
time_divisor = 10 | ||
|
||
def write_serial(x): | ||
arduino.write(bytes(x, 'utf-8')) | ||
time.sleep(0.05) | ||
|
||
|
||
def turnRight(angle): | ||
command = "0" + str(angle).zfill(3) + "0000" | ||
write_serial(command) | ||
time.sleep(angle * (time_divisor) / 1000) | ||
|
||
|
||
def turnLeft(angle): | ||
command = "1" + str(angle).zfill(3) + "0000" | ||
write_serial(command) | ||
time.sleep(angle * (time_divisor) / 1000) | ||
|
||
|
||
def goForward(dist): | ||
print('hello') | ||
command = "00001" + str(dist).zfill(3) | ||
print("forward: " + command) | ||
write_serial(command) | ||
time.sleep(dist * (time_divisor) / 1000) | ||
|
||
|
||
def goBackward(dist): | ||
command = "00000" + str(dist).zfill(3) | ||
print("backward: " + command) | ||
write_serial(command) | ||
time.sleep(dist * (time_divisor) / 1000) | ||
|
||
if __name__ == "__main__": | ||
goForward(100) | ||
time.sleep(2) |
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
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
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
from wheels import Wheels | ||
import serial | ||
|
||
# Instantiate the Wheels class with your port number | ||
myFirstWheel = Wheels("COM5") | ||
while True: | ||
arduino = serial.Serial(port='COM5', baudrate=115200, timeout=.1) | ||
|
||
# Instantiate the Wheels class with your port number | ||
myFirstWheel = Wheels('COM5') | ||
|
||
# Test movement commands | ||
# myFirstWheel.move(1,000,110) | ||
myFirstWheel.goForward(100) # Go forward 100 units | ||
myFirstWheel.goBackward(111) # Go backward 50 units | ||
# myFirstWheel.turnRight("90") # Turn right by 90 degrees | ||
# myFirstWheel.turnLeft("45") # Turn left by 45 degrees | ||
|
||
# Test movement commands | ||
# myFirstWheel.move(1,000,110) | ||
# myFirstWheel.goForward(100) # Go forward 100 units | ||
myFirstWheel.move("", 100, 431) | ||
# myFirstWheel.goBackward(111) # Go backward 50 units | ||
# myFirstWheel.turnRight("90") # Turn right by 90 degrees | ||
# myFirstWheel.turnLeft("45") # Turn left by 45 degrees |