9 Commits

Author SHA1 Message Date
ishak jmilou.ishak
71091f57dd removed code that didnt work 2025-01-08 15:25:30 +01:00
ishak jmilou.ishak
fa85be2df5 removed mqtt check 2025-01-08 14:18:46 +01:00
ishak jmilou.ishak
4bf3cd6d37 added mqtt connection safety 2025-01-08 14:15:06 +01:00
ishak jmilou.ishak
361c17fbdb comment everything again 2025-01-08 13:59:06 +01:00
ishak jmilou.ishak
fe3fe2b8cf restored all my code 2025-01-08 13:40:38 +01:00
ishak jmilou.ishak
bcac062cdf comment out monitorKobukiConnection thread for debugging 2025-01-08 13:31:57 +01:00
ishak jmilou.ishak
b12e4c7539 removed thread as well 2025-01-08 13:29:43 +01:00
ishak jmilou.ishak
a979d15a6e commented my new code to check if bug is still here 2025-01-08 13:27:34 +01:00
ishak jmilou.ishak
184e723379 added new thread 2025-01-08 13:05:19 +01:00

View File

@@ -15,8 +15,6 @@ CKobuki robot;
std::string readMQTT();
void parseMQTT(std::string message);
void CapnSend();
void reconnectKobuki();
void monitorKobukiConnection();
// ip, clientID, username, password
MqttClient client("ws://145.92.224.21/ws/", "KobukiRPI", "rpi",
"rpiwachtwoordofzo"); // create a client object
@@ -31,13 +29,12 @@ void setup() {
client.connect();
client.subscribe("home/commands");
}
int main() {
setup();
reconnectKobuki();
std::thread connectionMonitor(monitorKobukiConnection);
std::thread image(CapnSend);
std::thread safety([&]() { robot.robotSafety(&message); });
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
@@ -54,31 +51,6 @@ int main() {
image.join();
}
void reconnectKobuki() {
unsigned char *null_ptr(0);
while (true) {
if (robot.startCommunication("/dev/ttyUSB0", true, null_ptr) != -1) {
std::cout << "Kobuki opnieuw verbonden!" << std::endl;
break; // Verlaat de loop als de verbinding succesvol is
} else {
std::cerr << "Kobuki niet verbonden. Probeer opnieuw over 3 seconden..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3));
}
}
}
void monitorKobukiConnection() {
while (true) {
// Check regelmatig of de verbinding actief is
if (!robot.isConnected()) {
std::cerr << "Kobuki verbinding verloren. Reconnectie starten..." << std::endl;
reconnectKobuki();
}
std::this_thread::sleep_for(std::chrono::seconds(5)); // Check iedere 5 seconden
}
}
std::string readMQTT() {
static std::string lastMessage;