mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
fix: add reconnection logic for Kobuki in main loop
This commit is contained in:
@@ -39,6 +39,15 @@ int main() {
|
||||
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
||||
|
||||
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();
|
||||
if (!message.empty()) {
|
||||
parseMQTT(message);
|
||||
|
Reference in New Issue
Block a user