fix: add reconnection logic for Kobuki in main loop

This commit is contained in:
ishak jmilou.ishak
2025-01-09 15:32:30 +01:00
parent 1964589abc
commit 82363d393c

View File

@@ -39,6 +39,15 @@ int main() {
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); }); std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
while (true) { while (true) {
if (!robot.isConnected()) {
std::cout << "Kobuki is not connected anymore. Reconnecting..." << std::endl;
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
while (!robot.isConnected()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
std::cout << "Reconnected to Kobuki." << std::endl;
}
std::string message = readMQTT(); std::string message = readMQTT();
if (!message.empty()) { if (!message.empty()) {
parseMQTT(message); parseMQTT(message);