Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNS - Do the optical flow in python cos it gotta work #126

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
nodes = ["state_machine", "mqtt_broker", "navigator", "optical_flow"]

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

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 = {'x': x, 'y': y}
mqttc.publish('hyped/cart_2024/measurement/optical_flow',
json.dumps(measurement))
sleep(0.05)
4 changes: 3 additions & 1 deletion src/pod/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 @@ -80,6 +79,9 @@ 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") {
execv("/usr/bin/python3",
const char *const argv[] = {"/usr/bin/python3", "optical_flow.py", nullptr};)
} else {
std::cerr << "Unknown node: " << node_name << "\n";
return 1;
Expand Down
Loading