Skip to content

Commit

Permalink
SNS - Do the optical flow in python cos it gotta work (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomLonergan03 authored Jul 2, 2024
1 parent 2fd85ca commit 6bb6e0d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/pod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ host = "192.168.1.0"
port = 4556

[raspberry]
nodes = ["state_machine", "mqtt_broker", "navigator", "accelerometer", "keyence"]
nodes = ["state_machine", "mqtt_broker", "navigator", "accelerometer", "keyence", "optical_flow"]

[state_machine]
# Possible transition tables are "full_run",
Expand Down
22 changes: 22 additions & 0 deletions lib/sensors/optical_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pmw3901 import PMW3901
import paho.mqtt.client as mqtt
import tomllib
import json
import time

file = open('pod.toml', 'rb')
config = tomllib.load(file)
mqttc = mqtt.Client()
mqttc.connect(config['mqtt']['host'], config['mqtt']['port'])


sensor = PMW3901(spi_cs=0)
mqttc = mqtt.Client()

while True:
(x, y) = sensor.get_motion()
measurement = {'header': {'timestamp': time.time(), 'priority': 1
}, 'payload': {'x': x, 'y': y}}
mqttc.publish('hyped/cart_2024/measurement/optical_flow',
json.dumps(measurement))
time.sleep(0.05)
3 changes: 2 additions & 1 deletion src/pod/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ int main(int argc, char **argv)
return 1;
}
const std::string &ip = *optional_host_ip;

// parse the config file
const toml::table config = toml::parse_file(config_file);
const auto optional_ip = config["hostnames"][hostname].value<std::string>();
Expand Down Expand Up @@ -82,6 +81,8 @@ int main(int argc, char **argv)
} else if (node_name == "navigation") {
auto navigator_config = config["navigation"];
hyped::navigation::Navigator::startNode(navigator_config, mqtt_ip, mqtt_port);
} else if (node_name == "optical_flow") {
execl("/usr/bin/python3", "python", "optical_flow.py", nullptr);
} else if (node_name == "keyence") {
auto keyence_config = config["keyence"];
hyped::sensors::KeyenceNode::startNode(keyence_config, mqtt_ip, mqtt_port);
Expand Down

0 comments on commit 6bb6e0d

Please sign in to comment.