Files
picar/DecisionSystem/DecentralisedActivityFusion/voter.py
2019-01-15 09:29:24 +10:30

42 lines
1.6 KiB
Python

import paho.mqtt.client as mqtt
import time
class Voter:
'''
This class acts to replicate sensor information with the network to come to a consensus
of an activity occurrance. This is based upon research by Song et al. available at:
https://ieeexplore.ieee.org/document/5484586
The main advantage of this approach, as apposed to techniques such as by using zookeeper
or consul, is it can be completely decentralised and so works without a central server,
or needing to elect a central server. Additionally, it does not require all nodes
to run a Zookeeper/Consul server instance, which were not designed for these constrained
combat environments, which will fail if half the nodes fail, and also use a lot of resources
for handling services not required by this task.
The original approach in the paper requires some previous training before sensing, so
that there is a probability of a given action based upon the previous set of actions.
'''
def __init__(self, on_vote):
'''
on_vote: Callback to get the required vote to broadcast.
'''
self.on_vote = on_vote
self.client = mqtt.Client()
def submit_vote(self):
# Publish to swarm where all other voters will receive a vote.
# Wait a certain amount of time for responses, then fuse the information.
self.fuse_algorithm()
# Need the error and number of timestamps since voting started to finalise the consensus.
def fuse_algorithm(self):
pass
def on_message(self, client, userdata, message):
pass