fix: streamline Kobuki communication startup and reconnection logic

This commit is contained in:
ishak jmilou.ishak
2025-01-09 15:52:22 +01:00
parent 7d3a5fa9a3
commit 06dd2d9f48

View File

@@ -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));