mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
Compare commits
9 Commits
2bfd11276a
...
71091f57dd
Author | SHA1 | Date | |
---|---|---|---|
|
71091f57dd | ||
|
fa85be2df5 | ||
|
4bf3cd6d37 | ||
|
361c17fbdb | ||
|
fe3fe2b8cf | ||
|
bcac062cdf | ||
|
b12e4c7539 | ||
|
a979d15a6e | ||
|
184e723379 |
@@ -15,8 +15,6 @@ CKobuki robot;
|
|||||||
std::string readMQTT();
|
std::string readMQTT();
|
||||||
void parseMQTT(std::string message);
|
void parseMQTT(std::string message);
|
||||||
void CapnSend();
|
void CapnSend();
|
||||||
void reconnectKobuki();
|
|
||||||
void monitorKobukiConnection();
|
|
||||||
// ip, clientID, username, password
|
// ip, clientID, username, password
|
||||||
MqttClient client("ws://145.92.224.21/ws/", "KobukiRPI", "rpi",
|
MqttClient client("ws://145.92.224.21/ws/", "KobukiRPI", "rpi",
|
||||||
"rpiwachtwoordofzo"); // create a client object
|
"rpiwachtwoordofzo"); // create a client object
|
||||||
@@ -31,13 +29,12 @@ void setup() {
|
|||||||
|
|
||||||
client.connect();
|
client.connect();
|
||||||
client.subscribe("home/commands");
|
client.subscribe("home/commands");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
setup();
|
setup();
|
||||||
reconnectKobuki();
|
|
||||||
|
|
||||||
std::thread connectionMonitor(monitorKobukiConnection);
|
|
||||||
std::thread image(CapnSend);
|
std::thread image(CapnSend);
|
||||||
std::thread safety([&]() { robot.robotSafety(&message); });
|
std::thread safety([&]() { robot.robotSafety(&message); });
|
||||||
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
||||||
@@ -54,31 +51,6 @@ int main() {
|
|||||||
image.join();
|
image.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnectKobuki() {
|
|
||||||
unsigned char *null_ptr(0);
|
|
||||||
while (true) {
|
|
||||||
if (robot.startCommunication("/dev/ttyUSB0", true, null_ptr) != -1) {
|
|
||||||
std::cout << "Kobuki opnieuw verbonden!" << std::endl;
|
|
||||||
break; // Verlaat de loop als de verbinding succesvol is
|
|
||||||
} else {
|
|
||||||
std::cerr << "Kobuki niet verbonden. Probeer opnieuw over 3 seconden..." << std::endl;
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void monitorKobukiConnection() {
|
|
||||||
while (true) {
|
|
||||||
// Check regelmatig of de verbinding actief is
|
|
||||||
if (!robot.isConnected()) {
|
|
||||||
std::cerr << "Kobuki verbinding verloren. Reconnectie starten..." << std::endl;
|
|
||||||
reconnectKobuki();
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5)); // Check iedere 5 seconden
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string readMQTT() {
|
std::string readMQTT() {
|
||||||
static std::string lastMessage;
|
static std::string lastMessage;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user