diff --git a/config/pod.toml b/config/pod.toml index 14d80207..bdf97246 100644 --- a/config/pod.toml +++ b/config/pod.toml @@ -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", diff --git a/lib/sensors/optical_flow.py b/lib/sensors/optical_flow.py new file mode 100644 index 00000000..c293200b --- /dev/null +++ b/lib/sensors/optical_flow.py @@ -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) diff --git a/src/pod/main.cpp b/src/pod/main.cpp index 4f780a9d..8c8bce7a 100644 --- a/src/pod/main.cpp +++ b/src/pod/main.cpp @@ -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(); @@ -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);