mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
Add Kobuki connection monitoring and automatic start/stop functionality
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
CKobuki robot;
|
CKobuki robot;
|
||||||
|
std::atomic<bool> kobuki_connected(false);
|
||||||
|
|
||||||
|
|
||||||
std::string readMQTT();
|
std::string readMQTT();
|
||||||
void parseMQTT(std::string message);
|
void parseMQTT(std::string message);
|
||||||
@@ -28,6 +30,24 @@ void setup()
|
|||||||
client.subscribe("home/commands");
|
client.subscribe("home/commands");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkKobukiConnection() {
|
||||||
|
while (true) {
|
||||||
|
bool connected = robot.isConnected();
|
||||||
|
if (connected && !kobuki_connected) {
|
||||||
|
cout << "Kobuki is connected" << endl;
|
||||||
|
kobuki_connected = true;
|
||||||
|
// Start de Kobuki automatisch
|
||||||
|
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
|
||||||
|
} else if (!connected && kobuki_connected) {
|
||||||
|
cout << "Kobuki is disconnected" << endl;
|
||||||
|
kobuki_connected = false;
|
||||||
|
// Stop de Kobuki automatisch
|
||||||
|
robot.sendNullMessage();
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5)); // Controleer elke 5 seconden
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
@@ -46,6 +66,7 @@ int main()
|
|||||||
sendMqtt.join();
|
sendMqtt.join();
|
||||||
safety.join();
|
safety.join();
|
||||||
image.join();
|
image.join();
|
||||||
|
connectionThread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string readMQTT()
|
std::string readMQTT()
|
||||||
|
Reference in New Issue
Block a user