made more debug

This commit is contained in:
ishak jmilou.ishak
2025-01-20 10:58:34 +01:00
parent c31689ac70
commit aedff1c2cc

View File

@@ -60,24 +60,35 @@ void checkKobukiConnection()
{ {
while (true) while (true)
{ {
std::lock_guard<std::mutex> lock(connectionMutex);
bool connected = robot.isConnected();
if (!connected && kobuki_connected)
{ {
cout << "Kobuki is disconnected" << endl; std::lock_guard<std::mutex> lock(connectionMutex);
kobuki_connected = false; if (!robot.isConnected())
} {
else if (connected && !kobuki_connected) if (kobuki_connected)
{ {
cout << "Kobuki is reconnecting..." << endl; cout << "Kobuki is disconnected" << endl;
robot.startCommunication("/dev/ttyUSB0", true, nullptr); kobuki_connected = false;
kobuki_connected = true; }
// Probeer opnieuw te verbinden
cout << "Attempting to reconnect Kobuki..." << endl;
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
kobuki_connected = robot.isConnected();
if (kobuki_connected)
{
cout << "Kobuki reconnected successfully!" << endl;
}
else
{
cout << "Failed to reconnect Kobuki, retrying in 5 seconds..." << endl;
}
}
} }
std::this_thread::sleep_for(std::chrono::seconds(5)); // Controleer elke 5 seconden std::this_thread::sleep_for(std::chrono::seconds(5)); // Controleer elke 5 seconden
} }
} }
std::string readMQTT() std::string readMQTT()
{ {
static std::string lastMessage; static std::string lastMessage;