mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
refactor: change portname parameter to const char* in startCommunication and improve USB device check logic
This commit is contained in:
@@ -59,7 +59,7 @@ public:
|
|||||||
|
|
||||||
long loop(void *user_data, TKobukiData &Kobuki_data);
|
long loop(void *user_data, TKobukiData &Kobuki_data);
|
||||||
|
|
||||||
void startCommunication(char *portname,bool CommandsEnabled,void *userDataL);
|
void startCommunication(const char *portname,bool CommandsEnabled,void *userDataL);
|
||||||
int measure(); //thread function, contains an infinite loop and reads data
|
int measure(); //thread function, contains an infinite loop and reads data
|
||||||
void setLed(int led1 = 0, int led2 = 0); //led1 green/red 2/1, //led2 green/red 2/1
|
void setLed(int led1 = 0, int led2 = 0); //led1 green/red 2/1, //led2 green/red 2/1
|
||||||
void setTranslationSpeed(int mmpersec);
|
void setTranslationSpeed(int mmpersec);
|
||||||
|
@@ -77,10 +77,9 @@ void checkKobukiConnection()
|
|||||||
std::lock_guard<std::mutex> lock(connectionMutex);
|
std::lock_guard<std::mutex> lock(connectionMutex);
|
||||||
std::string port = findKobukiPort();
|
std::string port = findKobukiPort();
|
||||||
|
|
||||||
// Controleer of het apparaat beschikbaar is
|
if (port.empty()) {
|
||||||
if (!std::ifstream("/dev/ttyUSB0")){
|
if (kobuki_connected) {
|
||||||
if (kobuki_connected){
|
cout << "Kobuki disconnected: No USB device found." << endl;
|
||||||
cout << "Kobuki disconnected: USB device not found." << endl;
|
|
||||||
kobuki_connected = false;
|
kobuki_connected = false;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
@@ -95,7 +94,7 @@ void checkKobukiConnection()
|
|||||||
}
|
}
|
||||||
|
|
||||||
cout << "Attempting to reconnect Kobuki..." << endl;
|
cout << "Attempting to reconnect Kobuki..." << endl;
|
||||||
robot.startCommunication(const_cast<char*>(port.c_str()), true, nullptr);
|
robot.startCommunication((port.c_str()), true, nullptr);
|
||||||
|
|
||||||
if (robot.isConnected()){
|
if (robot.isConnected()){
|
||||||
cout << "Kobuki reconnected successfully!" << endl;
|
cout << "Kobuki reconnected successfully!" << endl;
|
||||||
|
Reference in New Issue
Block a user