made thread to wait 1 sec before reconnect

This commit is contained in:
ishak jmilou.ishak
2025-01-09 13:29:25 +01:00
parent 2396d61eae
commit 1c081451aa
2 changed files with 3 additions and 1 deletions

View File

@@ -68,7 +68,8 @@ int CKobuki::connect(char *comportT) {
HCom = open(comportT, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (HCom == -1) {
printf("unable to connect\n");
std::cerr <<"unable to connect. retry in 1 second" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
return HCom;
} else {
set_interface_attribs2(HCom, B115200,0); // set speed to 115,200 bps, 8n1 (no parity)

View File

@@ -327,6 +327,7 @@ void sendKobukiData(TKobukiData &data) {
while (true) {
if(!robot.isConnected()){
std::cout << "Kobuki is not connected anymore" << std::endl;
robot.connect("/dev/ttyUSB0");
while(!robot.isConnected()){
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
std::this_thread::sleep_for(std::chrono::seconds(1));