Last active
September 16, 2021 09:53
-
-
Save AdroitAnandAI/333ee0cdb57aa2bd9ebb765b539b051a to your computer and use it in GitHub Desktop.
Node 2 Sensor Fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sensor Fusion happens at Node 2 | |
def on_message(client, userdata, msg): | |
word = msg.payload.decode() | |
# objAttributes contains label, | |
# theta min and max separated by | | |
objAttributes = word.split('|') | |
now = time.localtime() | |
if (now.tm_min * 60 + now.tm_sec - int(objAttributes[3]) >= 1): | |
return | |
theta1 = float(objAttributes[1]) | |
theta2 = float(objAttributes[2]) | |
dist = getObjectDistance(int(theta1) + 90 + 59, int(theta2) + 90 + 59) | |
# convert distance from mm to cms | |
dist = round(float (dist / 1000), 1) | |
theta_mid = int((theta1 + theta2) / 2) | |
# if near then announce an alert! | |
# Passing the hue value on MQTT. 0 = Red. 0.3 = Green | |
if (dist < 2.0): | |
announceText = "ALERT ALERT " | |
client.publish("object/flashlight", "0.0") | |
else: | |
announceText = "" | |
client.publish("object/flashlight", "0.3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment