mirror of
https://github.com/PotentiaRobotics/control-system.git
synced 2025-04-09 22:50:17 -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
|
# 1 for executing the first action in the priority queue
|
||||||
|
|
||||||
from Propioception import *
|
from Propioception import *
|
||||||
from commands import *
|
# from commands import *
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
import heapq
|
import heapq
|
||||||
import time
|
import time
|
||||||
import serial
|
#import serial
|
||||||
|
|
||||||
class Receiver:
|
class Receiver:
|
||||||
def __init__(self, host, port):
|
def __init__(self, host, port):
|
||||||
self.commands = [""]
|
self.commands = []
|
||||||
self.execute = [""]
|
self.executions = []
|
||||||
self.transmit = [""]
|
self.transmit = []
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
self.HOST = host
|
self.HOST = host
|
||||||
self.PORT = port
|
self.PORT = port
|
||||||
|
@ -46,6 +46,7 @@ class Receiver:
|
||||||
action = self.conn.recv(1024).decode('UTF-8')
|
action = self.conn.recv(1024).decode('UTF-8')
|
||||||
if len(action) > 0:
|
if len(action) > 0:
|
||||||
heapq.heappush(self.commands,action)
|
heapq.heappush(self.commands,action)
|
||||||
|
print("Received|"+action)
|
||||||
heapq.heappush(self.transmit,"Received|"+action)
|
heapq.heappush(self.transmit,"Received|"+action)
|
||||||
|
|
||||||
"""Method checks commands from queue and adds to execution queue"""
|
"""Method checks commands from queue and adds to execution queue"""
|
||||||
|
@ -57,35 +58,43 @@ class Receiver:
|
||||||
#in command statement
|
#in command statement
|
||||||
pattern = "^[0-5]\|.*\|[0-9]{2}:[0-9]{2}\|" #everything but the checksum value
|
pattern = "^[0-5]\|.*\|[0-9]{2}:[0-9]{2}\|" #everything but the checksum value
|
||||||
checksum = "\w+$" #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)
|
com = re.findall(pattern, popped)
|
||||||
numval = re.findall(checksum, popped)
|
numval = re.findall(checksum, popped)
|
||||||
|
numval = numval[0]
|
||||||
numval = int(numval,16) #converts hex to int
|
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]]):
|
if numval == sum([ord(i) for i in com[0]]):
|
||||||
|
print("working")
|
||||||
heapq.heappush(self.transmit, "Correct|"+popped)
|
heapq.heappush(self.transmit, "Correct|"+popped)
|
||||||
heapq.heappush(self.execute, popped)
|
heapq.heappush(self.executions, popped)
|
||||||
|
print(self.transmit)
|
||||||
|
print(self.executions)
|
||||||
else:
|
else:
|
||||||
heappq.heappush(self.transmit, "Incorrect|"+popped)
|
heapq.heappush(self.transmit, "Incorrect|"+popped)
|
||||||
|
|
||||||
def telemetryTransmit(self):
|
def telemetryTransmit(self):
|
||||||
while True:
|
while True:
|
||||||
if len(self.transmit) > 0:
|
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):
|
def execute(self):
|
||||||
while len(self.actions) > 0:
|
while True:
|
||||||
if self.timer == 0:
|
if len(self.executions) > 0:
|
||||||
command = heapq.heappop(self.actions)
|
command = heapq.heappop(self.executions)
|
||||||
if command == "Password A_on_LED":
|
print(command)
|
||||||
if onAndOfffLed():
|
heapq.heappush(self.transmit, "Executed|"+command)
|
||||||
print("Executed: ", command)
|
# if command == "Password A_on_LED":
|
||||||
else:
|
# if onAndOfffLed():
|
||||||
print("Did not execute correctly ", command)
|
# print("Executed: ", command)
|
||||||
|
# else:
|
||||||
|
# print("Did not execute correctly ", command)
|
||||||
|
print("Inside execute",self.executions)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
if "Password Balancing" not in self.actions:
|
if "Balancing" not in self.executions:
|
||||||
heapq.heappush(self.actions, "Password Balancing")
|
heapq.heappush(self.executions, "Balancing")
|
||||||
print("Inside execute",self.actions)
|
|
||||||
|
|
||||||
def balance(self):
|
def balance(self):
|
||||||
print("Nothing")
|
print("Nothing")
|
||||||
|
@ -97,16 +106,17 @@ class Receiver:
|
||||||
print("Nothing")
|
print("Nothing")
|
||||||
|
|
||||||
def sensorData(self):
|
def sensorData(self):
|
||||||
|
var = ""
|
||||||
# Test
|
# Test
|
||||||
print("Inside")
|
# print("Inside")
|
||||||
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
|
# ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
|
||||||
ser.reset_input_buffer()
|
# ser.reset_input_buffer()
|
||||||
while True:
|
# while True:
|
||||||
print("Inside data")
|
# print("Inside data")
|
||||||
# Read from Arduinos to know what motors and sensors there are
|
## # Read from Arduinos to know what motors and sensors there are
|
||||||
ser.write("Send ****s plz\n".encode('utf-8'))
|
# ser.write("Send ****s plz\n".encode('utf-8'))
|
||||||
line = ser.readline().decode('utf-8').rstrip()
|
# line = ser.readline().decode('utf-8').rstrip()
|
||||||
print(line)
|
# print(line)
|
||||||
|
|
||||||
def runSimul(self):
|
def runSimul(self):
|
||||||
threading.Thread(target=self.telemetryReceive).start()
|
threading.Thread(target=self.telemetryReceive).start()
|
||||||
|
@ -114,12 +124,12 @@ class Receiver:
|
||||||
threading.Thread(target=self.telemetryTransmit).start()
|
threading.Thread(target=self.telemetryTransmit).start()
|
||||||
threading.Thread(target=self.execute).start()
|
threading.Thread(target=self.execute).start()
|
||||||
|
|
||||||
threading.Thread(target=self.sensorData).start()
|
# threading.Thread(target=self.sensorData).start()
|
||||||
|
|
||||||
threading.Thread(target=self.balance).start()
|
# threading.Thread(target=self.balance).start()
|
||||||
threading.Thread(target=self.gaitGen).start()
|
# threading.Thread(target=self.gaitGen).start()
|
||||||
threading.Thread(target=self.comuterVision).start()
|
# threading.Thread(target=self.comuterVision).start()
|
||||||
|
|
||||||
def startBoot():
|
def startBoot():
|
||||||
simulation = Receiver('10.235.1.148',12345)
|
simulation = Receiver('10.235.1.145',12345)
|
||||||
simulation.runSimul()
|
simulation.runSimul()
|
||||||
|
|
26
client1.py
26
client1.py
|
@ -1,13 +1,27 @@
|
||||||
import socket
|
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
|
PORT = 12345 # Pick an open Port (1000+ recommended), must match the server port
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((HOST,PORT))
|
s.connect((HOST,PORT))
|
||||||
|
|
||||||
#Lets loop awaiting for your input
|
#Lets loop awaiting for your input
|
||||||
while True:
|
|
||||||
command = input('Enter your command: ')
|
def telemetryReceive():
|
||||||
s.send(bytes(command, 'utf-8'))
|
while True:
|
||||||
reply = s.recv(1024)
|
reply = s.recv(1024)
|
||||||
print(reply)
|
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