diff --git a/src/slam_wrapper.cpp b/src/slam_wrapper.cpp index d7e86b2..ba616c1 100644 --- a/src/slam_wrapper.cpp +++ b/src/slam_wrapper.cpp @@ -38,10 +38,11 @@ begin_ = seq->data().find("feedback:", 0); end_ = seq->data().find(";", begin_); str_ = seq->data().substr(begin_ + 9, end_ - begin_ - 9); - if (const int feedback_ = atoi(str_.c_str()); feedback_ == 0 || feedback_ == -1) + if (const int feedback_ = atoi(str_.c_str()); feedback_ == 0 || feedback_ == -1) { std::cout << "\033[1;31m" << "Command execution failed with index = " << index_ << "." << "\033[0m"; + } std::cout << notice_ << std::endl; } else if (index_ == 10001) { // Navigation feedback @@ -49,7 +50,7 @@ end_ = seq->data().find(";", begin_); str_ = seq->data().substr(begin_ + 7, end_ - begin_ - 7); const int arrive_ = atoi(str_.c_str()); - std::cout << " I arrived node " << arrive_ << ". " << notice_ << std::endl; + std::cout << "I arrived node " << arrive_ << ". " << notice_ << std::endl; if (arrive_ == 1) { //发送暂停指令 pause_navigation(); @@ -66,19 +67,22 @@ //倒计时结束后恢复巡检 std::thread countdown_thread([this] { - std::this_thread::sleep_for(std::chrono::seconds(10)); - std::cout << "倒计时结束,恢复机械臂初始位置,恢复巡检"; - //水平朝前方向 - _tcp_service->send_command({ - 0xFE, 0xFE, 0x0F, 0x3C, - 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, - 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, - 0x14, 0xFA - }); - - recover_navigation(); + try { + std::this_thread::sleep_for(std::chrono::seconds(10)); + recover_navigation(); + std::cout << "倒计时结束,恢复机械臂初始位置,恢复巡检"; + //水平朝前方向 + _tcp_service->send_command({ + 0xFE, 0xFE, 0x0F, 0x3C, + 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, + 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, + 0x14, 0xFA + }); + } catch (const std::exception &e) { + std::cerr << "线程执行过程中发生异常: " << e.what() << std::endl; + } }); - countdown_thread.detach(); + countdown_thread.join(); } } }