mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 20:35:00 +00:00
fix: streamline Kobuki communication startup and reconnection logic
This commit is contained in:
@@ -20,7 +20,8 @@ void sendKobukiData(TKobukiData &data);
|
|||||||
void setup() {
|
void setup() {
|
||||||
unsigned char *null_ptr(0);
|
unsigned char *null_ptr(0);
|
||||||
std::cout << "Attempting to start communication with Kobuki..." << std::endl;
|
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;
|
std::cerr << "Failed to start communication with Kobuki." << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Successfully started communication with Kobuki." << std::endl;
|
std::cout << "Successfully started communication with Kobuki." << std::endl;
|
||||||
@@ -41,9 +42,7 @@ int main() {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (!robot.isConnected()) {
|
if (!robot.isConnected()) {
|
||||||
std::cout << "Kobuki is not connected anymore. Reconnecting..." << std::endl;
|
std::cout << "Kobuki is not connected anymore. Reconnecting..." << std::endl;
|
||||||
if (!robot.startCommunication("/dev/ttyUSB0", true, nullptr)) {
|
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
|
||||||
std::cerr << "Failed to reconnect to Kobuki." << std::endl;
|
|
||||||
}
|
|
||||||
while (!robot.isConnected()) {
|
while (!robot.isConnected()) {
|
||||||
std::cout << "Attempting to reconnect..." << std::endl;
|
std::cout << "Attempting to reconnect..." << std::endl;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
Reference in New Issue
Block a user