Implementing stuff (I suck at commits sometimes lol)
This commit is contained in:
@@ -1,6 +1,35 @@
|
|||||||
|
import Messaging.mqttsession as ms
|
||||||
|
import time
|
||||||
|
import umsgpack
|
||||||
|
|
||||||
class Commander:
|
class Commander:
|
||||||
def get_votes(self):
|
|
||||||
raise Exception("Vote cannot be submitted as it's not implemented")
|
def __init__(self, timeout = 60):
|
||||||
|
self.timeout = timeout
|
||||||
|
self._votes = []
|
||||||
|
self._client = ms.Client()
|
||||||
|
|
||||||
|
def on_message(client, userdata, message):
|
||||||
|
self._votes.append(umsgpack.unpackb(message.payload))
|
||||||
|
|
||||||
|
self.add_subscription("FakeSwarm/FirstTest", on_message)
|
||||||
|
|
||||||
|
self._client.loop_start()
|
||||||
|
|
||||||
|
def get_votes(self, topic, message, qos=0):
|
||||||
|
# Publish a message that votes are needed.
|
||||||
|
ms.client.publish(topic, message, qos)
|
||||||
|
time.sleep(self.timeout)
|
||||||
|
make_decision()
|
||||||
|
|
||||||
def make_decision(self):
|
def make_decision(self):
|
||||||
raise Exception("Vote cannot be submitted as it's not implemented")
|
votes = self._votes
|
||||||
|
|
||||||
|
for vote in votes:
|
||||||
|
continue
|
||||||
|
|
||||||
|
def add_subscription(self, topic, callback=None, qos=0):
|
||||||
|
self._client.subscribe(topic)
|
||||||
|
|
||||||
|
if callback is not None:
|
||||||
|
self._client.message_callback_add(topic, callback)
|
||||||
21
DecisionSystem/mqttvoter.py
Normal file
21
DecisionSystem/mqttvoter.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from voter import Voter
|
||||||
|
import Messaging.mqttsession as ms
|
||||||
|
from Messaging.packmessage import PackMessage
|
||||||
|
|
||||||
|
class MqttVoter(Voter):
|
||||||
|
def __init__(self):
|
||||||
|
# Should use a factory here to always get the same session.
|
||||||
|
# Just going to use a singleton for now, as there should only be
|
||||||
|
# one session in the program.
|
||||||
|
ms.client = ms.Client()
|
||||||
|
ms.host = "10.0.123.11"
|
||||||
|
|
||||||
|
def submit_vote(self):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set_vote(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_vote(self):
|
||||||
|
pass
|
||||||
@@ -1,16 +1,9 @@
|
|||||||
class Vote:
|
from Messaging.packmessage import PackMessage
|
||||||
|
|
||||||
|
class Vote(PackMessage):
|
||||||
def __init__(self, voter, vote):
|
def __init__(self, voter, vote):
|
||||||
self._voter = voter
|
|
||||||
self._vote = vote
|
self._vote = vote
|
||||||
|
|
||||||
@property
|
|
||||||
def voter(self):
|
|
||||||
return self._voter
|
|
||||||
|
|
||||||
@voter.setter
|
|
||||||
def voter(self, value):
|
|
||||||
self._voter = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def vote(self):
|
def vote(self):
|
||||||
return self._vote
|
return self._vote
|
||||||
@@ -19,5 +12,23 @@ class Vote:
|
|||||||
def vote(self, value):
|
def vote(self, value):
|
||||||
self._vote = value
|
self._vote = value
|
||||||
|
|
||||||
def to_string(self):
|
def serialise(self):
|
||||||
|
|
||||||
|
# Still need associated device as well? to know who went the message,
|
||||||
|
# to check that we don't add too many messages in case of multiple
|
||||||
|
# sends.
|
||||||
|
self.message = {"vote": self.vote}
|
||||||
|
|
||||||
|
# Call super method equivalent.
|
||||||
|
super(Vote, self).serialise()
|
||||||
|
|
||||||
|
def deserialise(self):
|
||||||
|
super(Vote, self).deserialise()
|
||||||
|
|
||||||
|
if "vote" in self.message:
|
||||||
|
self.vote = self.message["vote"]
|
||||||
|
else:
|
||||||
|
# Do something.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
class Voter:
|
from Messaging.packmessage import PackMessage
|
||||||
def submit_vote(self):
|
|
||||||
raise Exception("Vote cannot be submitted as it's not implemented")
|
class Voter:
|
||||||
|
def submit_vote(self, vote_contents):
|
||||||
|
NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ img = cv2.imread('H:\car\GestureRecognition\IMG_0818.png', 1)
|
|||||||
img = cv2.resize(img, None, fx=0.1, fy=0.1, interpolation = cv2.INTER_AREA)
|
img = cv2.resize(img, None, fx=0.1, fy=0.1, interpolation = cv2.INTER_AREA)
|
||||||
|
|
||||||
min_seg_threshold = 1.2
|
min_seg_threshold = 1.2
|
||||||
max_seg_threshold = 1.8
|
max_seg_threshold = 3
|
||||||
|
|
||||||
# prevent divide by zero, by just forcing pixel to be ignored.
|
# prevent divide by zero, by just forcing pixel to be ignored.
|
||||||
np.where(img[:,:,1] == 0, 0, img[:,:,1])
|
np.where(img[:,:,1] == 0, 0, img[:,:,1])
|
||||||
|
|||||||
15
GestureRecognition/handrecogniser.py
Normal file
15
GestureRecognition/handrecogniser.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class HandRecogniser:
|
||||||
|
"""
|
||||||
|
Interface for Recognising simple hand gestures from an image (or frame of a video)
|
||||||
|
"""
|
||||||
|
def load_image(self, image_path):
|
||||||
|
"""
|
||||||
|
Loads the given image, can be lazy loading.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_gesture(self):
|
||||||
|
"""
|
||||||
|
Gets a the gesture recognised in the image.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
@@ -1,2 +1,11 @@
|
|||||||
class Message:
|
class Message:
|
||||||
|
"""
|
||||||
|
Message Format
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
def serialise(self):
|
||||||
|
NotImplementedError
|
||||||
|
|
||||||
|
def deserialise(self):
|
||||||
|
NotImplementedError
|
||||||
|
|||||||
25
Messaging/mqttsession.py
Normal file
25
Messaging/mqttsession.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
client = None
|
||||||
|
host = None
|
||||||
|
|
||||||
|
# Arguably not needed, just want to make the client static, but here anyway.
|
||||||
|
def connect():
|
||||||
|
if client is None or host is None:
|
||||||
|
print("Error: Client and/or host are not initialised.")
|
||||||
|
else:
|
||||||
|
client.connect(host, port=1883, keepalive=60, bind_address="")
|
||||||
|
client.loop_start()
|
||||||
|
|
||||||
|
def disconnect():
|
||||||
|
if client is not None:
|
||||||
|
client.loop_stop()
|
||||||
|
client.disconnect()
|
||||||
|
else:
|
||||||
|
print("Error: Client is not initialised.")
|
||||||
|
|
||||||
|
def Client():
|
||||||
|
if client is not None:
|
||||||
|
return mqtt.Client()
|
||||||
|
else:
|
||||||
|
return client
|
||||||
14
Messaging/packmessage.py
Normal file
14
Messaging/packmessage.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import umsgpack
|
||||||
|
from messaginginterface import Message
|
||||||
|
|
||||||
|
class PackMessage(Message):
|
||||||
|
|
||||||
|
def __init__(self, message=None):
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
def serialise(self):
|
||||||
|
return umsgpack.packb(self.message)
|
||||||
|
|
||||||
|
def deserialise(self):
|
||||||
|
return umsgpack.unpackb(self.message)
|
||||||
|
|
||||||
Reference in New Issue
Block a user