diff --git a/Control System/Propioception.pyc b/Control System/Propioception.pyc new file mode 100644 index 0000000..7b17344 Binary files /dev/null and b/Control System/Propioception.pyc differ diff --git a/Control System/__pycache__/Propioception.cpython-37.pyc b/Control System/__pycache__/Propioception.cpython-37.pyc new file mode 100644 index 0000000..8cbfb3e Binary files /dev/null and b/Control System/__pycache__/Propioception.cpython-37.pyc differ diff --git a/Control System/__pycache__/bootup.cpython-37.pyc b/Control System/__pycache__/bootup.cpython-37.pyc new file mode 100644 index 0000000..cd4e84e Binary files /dev/null and b/Control System/__pycache__/bootup.cpython-37.pyc differ diff --git a/Control System/__pycache__/commands.cpython-37.pyc b/Control System/__pycache__/commands.cpython-37.pyc new file mode 100644 index 0000000..acffa62 Binary files /dev/null and b/Control System/__pycache__/commands.cpython-37.pyc differ diff --git a/Control System/bootup.py b/Control System/bootup.py index 175e4f6..406a930 100644 --- a/Control System/bootup.py +++ b/Control System/bootup.py @@ -6,11 +6,13 @@ # 1 for executing the first action in the priority queue from Propioception import * +from commands import * import threading import socket import heapq import time +import serial class Receiver: def __init__(self, host, port): @@ -42,31 +44,46 @@ class Receiver: if "Password" in action: heapq.heappush(self.actions,action) print(self.actions) + conn.send(action.encode()+bytes(" works",'utf-8')) else: print("Incorrect Command") + conn.send(bytes("Incorrect Commandc",'utf-8')) # Sending reply - conn.send(action.encode()+bytes(" works",'utf-8')) + def execute(self): while len(self.actions) > 0: if self.timer == 0: - print("Executed: ", heapq.heappop(self.actions)) + command = heapq.heappop(self.actions) + if command == "Password A_on_LED": + if onAndOfffLed(): + print("Executed: ", command) + else: + print("Did not execute correctly ", command) + time.sleep(5) - heapq.heappush(self.actions, "Password Balancing") + if "Password Balancing" not in self.actions: + heapq.heappush(self.actions, "Password Balancing") print("Inside execute",self.actions) def sensorData(self): # Test - # Read from Arduinos to know what motors and sensors there are - print("test") - + print("Inside") + ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1) + ser.reset_input_buffer() + while True: + print("Inside data") + # Read from Arduinos to know what motors and sensors there are + ser.write("Send ****s plz\n".encode('utf-8')) + line = ser.readline().decode('utf-8').rstrip() + print(line) def runSimul(self): threading.Thread(target=self.priorityQueue).start() - threading.Thread(target=self.execute()).start() - threading.Thread(target=self.sensorData()).start() + threading.Thread(target=self.execute).start() + threading.Thread(target=self.sensorData).start() def startBoot(): - simulation = Receiver('10.235.1.127',12345) + simulation = Receiver('10.235.1.148',12345) simulation.runSimul() diff --git a/Control System/bootup.pyc b/Control System/bootup.pyc new file mode 100644 index 0000000..409701f Binary files /dev/null and b/Control System/bootup.pyc differ diff --git a/Control System/commands.py b/Control System/commands.py new file mode 100644 index 0000000..3bd1969 --- /dev/null +++ b/Control System/commands.py @@ -0,0 +1,24 @@ +# Commands for arduino + +import serial +import time + +ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) # fix +ser.reset_input_buffer() + +def onAndOfffLed(): + ser.write("ON\n".encode('utf-8')) + line = ser.readline().decode('utf-8').rstrip() + print(line) + + time.sleep(4) + + ser.write("OFF\n".encode('utf-8')) + line = ser.readline().decode('utf-8').rstrip() + print(line) + time.sleep(4) + + if line == "You sent me: OFF": + return 1 + else: + return 0 \ No newline at end of file diff --git a/Control System/main.py b/Control System/main.py index 4701413..5b5d9a9 100644 --- a/Control System/main.py +++ b/Control System/main.py @@ -1,6 +1,6 @@ import sys from bootup import * - + def main(): startBoot() # when Olympian is booted up for first time