diff --git a/CMAKE_BUILD_README.md b/CMAKE_BUILD_README.md index 4361fd5..a766ae4 100644 --- a/CMAKE_BUILD_README.md +++ b/CMAKE_BUILD_README.md @@ -17,15 +17,20 @@ Hướng dẫn chi tiết để build project `pnkx_nav_core` sử dụng CMake ## Yêu cầu hệ thống ### Hệ điều hành + - Linux (Ubuntu 18.04+ hoặc tương đương) + ### Compiler + - **GCC**: phiên bản 7.0 trở lên (hỗ trợ C++17) - **Clang**: phiên bản 5.0 trở lên ### CMake + - **CMake**: phiên bản 3.10 trở lên Kiểm tra phiên bản: + ```bash cmake --version g++ --version @@ -177,6 +182,7 @@ make install ``` Cấu trúc sau khi install: + ``` /usr/local/ ├── include/ @@ -226,6 +232,7 @@ target_link_libraries(my_app Xem hướng dẫn chi tiết trong `examples/README.md` và `examples/QUICK_START.md`. Tóm tắt: + ```bash # Copy shared library cp build/src/APIs/c_api/libnavigation_c_api.so /path/to/your/project/ @@ -269,6 +276,7 @@ sudo apt-get install libyaml-cpp-dev ### Lỗi: "undefined reference" Đảm bảo tất cả dependencies đã được build theo đúng thứ tự: + 1. Core libraries (tf3, robot_time, xmlrpcpp, robot_cpp) 2. Geometry và messages (geometry2, common_msgs) 3. Navigation cores (nav_core, nav_core2) @@ -276,6 +284,7 @@ sudo apt-get install libyaml-cpp-dev 5. Main packages (move_base) Build lại từ đầu: + ```bash cd build rm -rf * diff --git a/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_docking_local_planner.cpp b/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_docking_local_planner.cpp index f09d811..420cb8c 100644 --- a/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_docking_local_planner.cpp +++ b/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_docking_local_planner.cpp @@ -53,9 +53,7 @@ void pnkx_local_planner::PNKXDockingLocalPlanner::initialize(robot::NodeHandle & info_.origin_x = costmap_->getOriginX(); info_.origin_y = costmap_->getOriginY(); - if (!costmap_robot_->isCurrent()) - throw robot_nav_core2::CostmapDataLagException("Costmap2DROBOT is out of date somehow."); - + // Costmap freshness is enforced per cycle in prepare(); layers may still be pending at load time. parent_ = parent; planner_nh_ = robot::NodeHandle(parent_, name); robot::log_info_at(__FILE__, __LINE__, "Planner namespace: %s, parent namespace: %s", planner_nh_.getNamespace().c_str(), parent_.getNamespace().c_str()); diff --git a/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_go_straight_local_planner.cpp b/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_go_straight_local_planner.cpp index 4e11876..9c29a08 100644 --- a/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_go_straight_local_planner.cpp +++ b/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_go_straight_local_planner.cpp @@ -57,9 +57,7 @@ void pnkx_local_planner::PNKXGoStraightLocalPlanner::initialize(robot::NodeHandl info_.origin_x = costmap_->getOriginX(); info_.origin_y = costmap_->getOriginY(); - if (!costmap_robot_->isCurrent()) - throw robot_nav_core2::CostmapDataLagException("Costmap2DROBOT is out of date somehow."); - + // Costmap freshness is enforced per cycle in prepare(); layers may still be pending at load time. parent_ = parent; planner_nh_ = robot::NodeHandle(parent_, name); robot::log_info_at(__FILE__, __LINE__, "Planner namespace: %s, parent namespace: %s", planner_nh_.getNamespace().c_str(), parent_.getNamespace().c_str()); diff --git a/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_local_planner.cpp b/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_local_planner.cpp index c595656..997ae1e 100644 --- a/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_local_planner.cpp +++ b/src/Algorithms/Packages/local_planners/pnkx_local_planner/src/pnkx_local_planner.cpp @@ -67,9 +67,7 @@ void pnkx_local_planner::PNKXLocalPlanner::initialize(robot::NodeHandle &parent, info_.origin_x = costmap_->getOriginX(); info_.origin_y = costmap_->getOriginY(); - if (!costmap_robot_->isCurrent()) - throw robot_nav_core2::CostmapDataLagException("Costmap2DROBOT is out of date somehow."); - + // Costmap freshness is enforced per cycle in prepare(); layers may still be pending at load time. parent_ = parent; planner_nh_ = robot::NodeHandle(parent_, name); robot::log_info_at(__FILE__, __LINE__, "Planner namespace: %s, parent namespace: %s", planner_nh_.getNamespace().c_str(), parent_.getNamespace().c_str()); diff --git a/src/Libraries/robot_cpp/include/robot/node_handle.h b/src/Libraries/robot_cpp/include/robot/node_handle.h index 9931e3f..3f468e6 100644 --- a/src/Libraries/robot_cpp/include/robot/node_handle.h +++ b/src/Libraries/robot_cpp/include/robot/node_handle.h @@ -539,6 +539,18 @@ namespace robot */ int loadYamlFilesFromDirectory(const std::string &directory_path); + /** + * @brief Replace the shared parameter tree with the YAML files of a directory. + * + * Sets the static config directory, clears the shared root tree and reloads it. + * Existing NodeHandle instances keep their previous scope; create new handles + * after reloading. Not thread-safe: callers must serialize with tree readers. + * + * @param config_dir Directory containing .yaml/.yml files. + * @return true if config_dir is a directory and was loaded. + */ + static bool reload(const std::string &config_dir); + /** * @brief Get the namespace of this NodeHandle. * diff --git a/src/Libraries/robot_cpp/src/node_handle.cpp b/src/Libraries/robot_cpp/src/node_handle.cpp index 3ee0f3f..167e870 100644 --- a/src/Libraries/robot_cpp/src/node_handle.cpp +++ b/src/Libraries/robot_cpp/src/node_handle.cpp @@ -880,6 +880,17 @@ namespace robot return loaded_count; } + bool NodeHandle::reload(const std::string &config_dir) + { + std::error_code ec; + if (!std::filesystem::is_directory(config_dir, ec)) + return false; + config_directory_ = config_dir; + root_ = YAML::Node(YAML::NodeType::Map); + NodeHandle loader("~"); // empty root_ -> constructor auto-loads config_directory_ + return true; + } + std::string NodeHandle::findConfigDirectory() { // If config directory is already set, use it