mirror of
https://github.com/PotentiaRobotics/control-system.git
synced 2025-04-03 20:00:19 -04:00
Done for today
This commit is contained in:
parent
1652134788
commit
24f9edf0e0
BIN
Control System/__pycache__/Propioception.cpython-38.pyc
Normal file
BIN
Control System/__pycache__/Propioception.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
Control System/__pycache__/commands.cpython-38.pyc
Normal file
BIN
Control System/__pycache__/commands.cpython-38.pyc
Normal file
Binary file not shown.
|
@ -6,20 +6,20 @@
|
|||
# 1 for executing the first action in the priority queue
|
||||
|
||||
from Propioception import *
|
||||
from commands import *
|
||||
# from commands import *
|
||||
|
||||
import re
|
||||
import threading
|
||||
import socket
|
||||
import heapq
|
||||
import time
|
||||
import serial
|
||||
#import serial
|
||||
|
||||
class Receiver:
|
||||
def __init__(self, host, port):
|
||||
self.commands = [""]
|
||||
self.execute = [""]
|
||||
self.transmit = [""]
|
||||
self.commands = []
|
||||
self.executions = []
|
||||
self.transmit = []
|
||||
self.timer = 0
|
||||
self.HOST = host
|
||||
self.PORT = port
|
||||
|
@ -46,6 +46,7 @@ class Receiver:
|
|||
action = self.conn.recv(1024).decode('UTF-8')
|
||||
if len(action) > 0:
|
||||
heapq.heappush(self.commands,action)
|
||||
print("Received|"+action)
|
||||
heapq.heappush(self.transmit,"Received|"+action)
|
||||
|
||||
"""Method checks commands from queue and adds to execution queue"""
|
||||
|
@ -57,35 +58,43 @@ class Receiver:
|
|||
#in command statement
|
||||
pattern = "^[0-5]\|.*\|[0-9]{2}:[0-9]{2}\|" #everything but the checksum value
|
||||
checksum = "\w+$" #checksum value
|
||||
popped = heapq.heapop(self.commands) #gets smallest value command
|
||||
popped = heapq.heappop(self.commands) #gets smallest value command
|
||||
com = re.findall(pattern, popped)
|
||||
numval = re.findall(checksum, popped)
|
||||
numval = numval[0]
|
||||
numval = int(numval,16) #converts hex to int
|
||||
print(com[0])
|
||||
print(sum([ord(i) for i in com[0]]))
|
||||
if numval == sum([ord(i) for i in com[0]]):
|
||||
print("working")
|
||||
heapq.heappush(self.transmit, "Correct|"+popped)
|
||||
heapq.heappush(self.execute, popped)
|
||||
heapq.heappush(self.executions, popped)
|
||||
print(self.transmit)
|
||||
print(self.executions)
|
||||
else:
|
||||
heappq.heappush(self.transmit, "Incorrect|"+popped)
|
||||
heapq.heappush(self.transmit, "Incorrect|"+popped)
|
||||
|
||||
def telemetryTransmit(self):
|
||||
while True:
|
||||
if len(self.transmit) > 0:
|
||||
self.conn.send((heapq.heappop(self.transmit)).encode())
|
||||
print("Transmit queue", self.transmit)
|
||||
self.conn.send(bytes(heapq.heappop(self.transmit),'utf-8'))
|
||||
|
||||
def execute(self):
|
||||
while len(self.actions) > 0:
|
||||
if self.timer == 0:
|
||||
command = heapq.heappop(self.actions)
|
||||
if command == "Password A_on_LED":
|
||||
if onAndOfffLed():
|
||||
print("Executed: ", command)
|
||||
else:
|
||||
print("Did not execute correctly ", command)
|
||||
|
||||
while True:
|
||||
if len(self.executions) > 0:
|
||||
command = heapq.heappop(self.executions)
|
||||
print(command)
|
||||
heapq.heappush(self.transmit, "Executed|"+command)
|
||||
# if command == "Password A_on_LED":
|
||||
# if onAndOfffLed():
|
||||
# print("Executed: ", command)
|
||||
# else:
|
||||
# print("Did not execute correctly ", command)
|
||||
print("Inside execute",self.executions)
|
||||
time.sleep(5)
|
||||
if "Password Balancing" not in self.actions:
|
||||
heapq.heappush(self.actions, "Password Balancing")
|
||||
print("Inside execute",self.actions)
|
||||
if "Balancing" not in self.executions:
|
||||
heapq.heappush(self.executions, "Balancing")
|
||||
|
||||
def balance(self):
|
||||
print("Nothing")
|
||||
|
@ -97,16 +106,17 @@ class Receiver:
|
|||
print("Nothing")
|
||||
|
||||
def sensorData(self):
|
||||
var = ""
|
||||
# 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)
|
||||
# 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.telemetryReceive).start()
|
||||
|
@ -114,12 +124,12 @@ class Receiver:
|
|||
threading.Thread(target=self.telemetryTransmit).start()
|
||||
threading.Thread(target=self.execute).start()
|
||||
|
||||
threading.Thread(target=self.sensorData).start()
|
||||
|
||||
threading.Thread(target=self.balance).start()
|
||||
threading.Thread(target=self.gaitGen).start()
|
||||
threading.Thread(target=self.comuterVision).start()
|
||||
# threading.Thread(target=self.sensorData).start()
|
||||
|
||||
# threading.Thread(target=self.balance).start()
|
||||
# threading.Thread(target=self.gaitGen).start()
|
||||
# threading.Thread(target=self.comuterVision).start()
|
||||
|
||||
def startBoot():
|
||||
simulation = Receiver('10.235.1.148',12345)
|
||||
simulation = Receiver('10.235.1.145',12345)
|
||||
simulation.runSimul()
|
||||
|
|
26
client1.py
26
client1.py
|
@ -1,13 +1,27 @@
|
|||
import socket
|
||||
import threading
|
||||
|
||||
HOST = '10.235.1.127' # Enter IP or Hostname of your server
|
||||
HOST = '10.235.1.145' # Enter IP or Hostname of your server
|
||||
PORT = 12345 # Pick an open Port (1000+ recommended), must match the server port
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((HOST,PORT))
|
||||
|
||||
#Lets loop awaiting for your input
|
||||
while True:
|
||||
command = input('Enter your command: ')
|
||||
s.send(bytes(command, 'utf-8'))
|
||||
reply = s.recv(1024)
|
||||
print(reply)
|
||||
|
||||
def telemetryReceive():
|
||||
while True:
|
||||
reply = s.recv(1024)
|
||||
if reply != None:
|
||||
print(reply)
|
||||
|
||||
def telemetrySend():
|
||||
while True:
|
||||
command = input('Enter your command: ')
|
||||
if command != None:
|
||||
s.send(bytes(command, 'utf-8'))
|
||||
|
||||
def main():
|
||||
threading.Thread(target=telemetryReceive).start()
|
||||
threading.Thread(target=telemetrySend).start()
|
||||
|
||||
main()
|
Loading…
Reference in New Issue
Block a user