From 06dd2d9f48deda1d282f50ea2e1f92b49e36505b Mon Sep 17 00:00:00 2001 From: "ishak jmilou.ishak" Date: Thu, 9 Jan 2025 15:52:22 +0100 Subject: [PATCH] fix: streamline Kobuki communication startup and reconnection logic --- src/C++/Driver/src/main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/C++/Driver/src/main.cpp b/src/C++/Driver/src/main.cpp index 6d2c67e..712deb2 100644 --- a/src/C++/Driver/src/main.cpp +++ b/src/C++/Driver/src/main.cpp @@ -20,7 +20,8 @@ void sendKobukiData(TKobukiData &data); void setup() { unsigned char *null_ptr(0); std::cout << "Attempting to start communication with Kobuki..." << std::endl; - if (!robot.startCommunication("/dev/ttyUSB0", true, null_ptr)) { + robot.startCommunication("/dev/ttyUSB0", true, null_ptr); + if (!robot.isConnected()) { std::cerr << "Failed to start communication with Kobuki." << std::endl; } else { std::cout << "Successfully started communication with Kobuki." << std::endl; @@ -41,9 +42,7 @@ int main() { while (true) { if (!robot.isConnected()) { std::cout << "Kobuki is not connected anymore. Reconnecting..." << std::endl; - if (!robot.startCommunication("/dev/ttyUSB0", true, nullptr)) { - std::cerr << "Failed to reconnect to Kobuki." << std::endl; - } + robot.startCommunication("/dev/ttyUSB0", true, nullptr); while (!robot.isConnected()) { std::cout << "Attempting to reconnect..." << std::endl; std::this_thread::sleep_for(std::chrono::seconds(1));