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
4 Commits
c31689ac70
...
2c630bf89b
Author | SHA1 | Date | |
---|---|---|---|
|
2c630bf89b | ||
|
ef3407b742 | ||
|
3d9a68ff7f | ||
|
aedff1c2cc |
@@ -61,23 +61,45 @@ void checkKobukiConnection()
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(connectionMutex);
|
std::lock_guard<std::mutex> lock(connectionMutex);
|
||||||
bool connected = robot.isConnected();
|
|
||||||
if (!connected && kobuki_connected)
|
// Controleer of het apparaat beschikbaar is
|
||||||
{
|
if (!std::ifstream("/dev/ttyUSB0")){
|
||||||
cout << "Kobuki is disconnected" << endl;
|
if (kobuki_connected){
|
||||||
kobuki_connected = false;
|
cout << "Kobuki disconnected: USB device not found." << endl;
|
||||||
|
kobuki_connected = false;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
|
continue; // Probeer later opnieuw
|
||||||
}
|
}
|
||||||
else if (connected && !kobuki_connected)
|
|
||||||
{
|
// Controleer of de Kobuki verbonden is
|
||||||
cout << "Kobuki is reconnecting..." << endl;
|
if (!robot.isConnected()){
|
||||||
|
if (kobuki_connected){
|
||||||
|
cout << "Kobuki disconnected." << endl;
|
||||||
|
kobuki_connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Attempting to reconnect Kobuki..." << endl;
|
||||||
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
|
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
|
||||||
|
|
||||||
|
if (robot.isConnected()){
|
||||||
|
cout << "Kobuki reconnected successfully!" << endl;
|
||||||
|
kobuki_connected = true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cout << "Failed to reconnect Kobuki, retrying in 5 seconds..." << endl;
|
||||||
|
}
|
||||||
|
}else if (!kobuki_connected){
|
||||||
|
// Update status als de verbinding hersteld is
|
||||||
|
cout << "Kobuki is connected." << endl;
|
||||||
kobuki_connected = true;
|
kobuki_connected = true;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5)); // Controleer elke 5 seconden
|
|
||||||
|
// Wacht voordat je opnieuw controleert
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string readMQTT()
|
std::string readMQTT()
|
||||||
{
|
{
|
||||||
static std::string lastMessage;
|
static std::string lastMessage;
|
||||||
|
Reference in New Issue
Block a user