Files
pnkx_nav_core/CMAKE_BUILD_README.md
duongtd d40051df27 pnkx_nav_core 1.0 — every package is a submodule at its own pinned commit
A single commit on an orphan branch, so this is the whole tree as it should
land on a robot, with no history from the branch it grew out of.

Every package is now a git submodule - 26 of them, 15 registered here for the
first time. They were sitting in the tree as plain clones, which looks right
locally and is empty on the robot: a clone of this repository would have
carried the directory names and none of the contents. That failure reports
itself as "works on my machine, not on the robot", and it is the reason this
conversion happened at all.

Newly registered:

  src/Navigations/Packages/move_base2
  src/Algorithms/Packages/actions/dock_pattern_action
  src/Algorithms/Packages/global_planners/sbpl_lattice_planner
  src/Algorithms/Packages/local_planners/{hybrid,mppi,priest}_local_planner
  src/Libraries/{action_core,angles,depth_image_proc,dock_pattern_detector}
  src/Libraries/{mission_adapters,recovery_core,robot_line_extraction}
  src/Libraries/{robot_sensor_ports,sbpl}

.gitignore had a rule - **/[Pp]ackages/* - that hid move_base2 and
dock_pattern_action from git status entirely, so they would have been left out
without anything being said. The exception is written for those two paths only
rather than by loosening the rule.

Every submodule points at the tip of the branch it was already pinned to, not
blindly at main. costmap_2d stays on dev_cam_intel; that branch exists for a
reason, and this tree carries field calibration that does not belong to main.
The other 25 are at the tip of main.

config/ is flattened into config/runtime/, matching the layout the nav core
reads. The .zip snapshots of old package states are gone - they were manual
backups, not build inputs.
2026-08-27 10:09:25 +07:00

8.0 KiB

Hướng dẫn Build bằng CMake

Hướng dẫn chi tiết để build project pnkx_nav_core sử dụng CMake standalone (không cần Catkin workspace).

Mục lục

  1. Yêu cầu hệ thống
  2. Cài đặt Dependencies
  3. Build Project
  4. Các tùy chọn Build
  5. Install
  6. Sử dụng trong project khác
  7. Troubleshooting

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:

cmake --version
g++ --version

Cài đặt Dependencies

Linux (Ubuntu/Debian)

# Cập nhật package list
sudo apt-get update

# Cài đặt CMake và build tools
sudo apt-get install -y cmake build-essential

# Cài đặt các thư viện cần thiết
sudo apt-get install -y \
    libboost-all-dev \
    libeigen3-dev \
    libyaml-cpp-dev \
    libpcl-dev \
    libgoogle-glog-dev
sudo apt install liborocos-kdl-dev

# Optional: Cài đặt Google Test (nếu muốn build tests)
sudo apt-get install -y libgtest-dev

Lưu ý: Hướng dẫn này dành cho hệ thống Linux. Nếu sử dụng các distro khác (CentOS, Fedora, Arch, etc.), vui lòng cài đặt các packages tương ứng bằng package manager của distro đó.


Build Project

Bước 1: Clone repository

git clone https://git.pnkr.asia/HiepLM/pnkx_nav_core.git
cd pnkx_nav_core
git submodule init
git submodule update

Bước 2: Tạo thư mục build

mkdir build
cd build

Bước 3: Cấu hình với CMake

# Cấu hình cơ bản (Release mode)
cmake ..

# Hoặc chỉ định build type rõ ràng
cmake -DCMAKE_BUILD_TYPE=Release ..

# Hoặc Debug mode (để debug)
cmake -DCMAKE_BUILD_TYPE=Debug ..

Bước 4: Build

# Build tất cả targets
make

# Hoặc build với nhiều cores (nhanh hơn)
make -j$(nproc)

Bước 5: Kiểm tra build thành công

# Kiểm tra các thư viện đã được build
ls -la lib/

# Kiểm tra các executable (nếu có)
ls -la bin/

Các tùy chọn Build

Build Type

# Release mode (mặc định) - tối ưu hóa
cmake -DCMAKE_BUILD_TYPE=Release ..

# Debug mode - với debug symbols
cmake -DCMAKE_BUILD_TYPE=Debug ..

# RelWithDebInfo - Release với debug info
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..

# MinSizeRel - Tối ưu kích thước
cmake -DCMAKE_BUILD_TYPE=MinSizeRel ..

Build chỉ một target cụ thể

# Build chỉ một library
make robot_cpp_node_handle

# Build chỉ move_base
make move_base

# Build chỉ C API
make navigation_c_api

Các tùy chọn CMake khác

# Tắt warnings (đã được cấu hình sẵn trong CMakeLists.txt)
cmake -DCMAKE_CXX_FLAGS="-w" ..

# Chỉ định compiler
cmake -DCMAKE_CXX_COMPILER=g++-9 ..

# Chỉ định install prefix
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..

# Build tests (nếu có)
cmake -DBUILD_TESTS=ON ..

Install

Sau khi build thành công, bạn có thể install các thư viện và headers vào hệ thống:

# Install vào thư mục mặc định (/usr/local)
sudo make install

# Hoặc install vào thư mục tùy chỉnh
cmake -DCMAKE_INSTALL_PREFIX=/opt/pnkx_nav_core ..
make install

Cấu trúc sau khi install:

/usr/local/
├── include/
│   ├── robot/
│   ├── nav_core2/
│   ├── mkt_algorithm/
│   └── ...
├── lib/
│   ├── librobot_cpp_node_handle.so
│   ├── libmove_base.so
│   └── ...
└── lib/cmake/
    ├── robot_cpp/
    ├── move_base/
    └── ...

Sử dụng trong project khác

Sử dụng với CMake

Sau khi install, bạn có thể sử dụng trong CMakeLists.txt của project khác:

cmake_minimum_required(VERSION 3.10)
project(my_project)

# Tìm các packages
find_package(robot_cpp REQUIRED)
find_package(move_base REQUIRED)
find_package(navigation_c_api REQUIRED)

# Link libraries
add_executable(my_app main.cpp)
target_link_libraries(my_app
    PRIVATE
        robot_cpp
        move_base
        navigation_c_api
)

Sử dụng C API (cho .NET/C#)

Xem hướng dẫn chi tiết trong examples/README.md và examples/QUICK_START.md.

Tóm tắt:

# Copy shared library
cp build/src/APIs/c_api/libnavigation_c_api.so /path/to/your/project/

# Sử dụng trong C#
[DllImport("libnavigation_c_api.so")]
public static extern IntPtr create_navigation();

Troubleshooting

Lỗi: "Could not find Boost"

# Kiểm tra Boost đã được cài đặt
dpkg -l | grep libboost

# Cài đặt lại nếu thiếu
sudo apt-get install libboost-all-dev

Lỗi: "Could not find Eigen3"

# Cài đặt Eigen3
sudo apt-get install libeigen3-dev

# Hoặc chỉ định đường dẫn
cmake -DEigen3_DIR=/usr/include/eigen3 ..

Lỗi: "Could not find yaml-cpp"

# Cài đặt yaml-cpp
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)
  4. Algorithms (score_algorithm, mkt_algorithm)
  5. Main packages (move_base)

Build lại từ đầu:

cd build
rm -rf *
cmake ..
make -j$(nproc)

Lỗi: "Permission denied" khi install

# Sử dụng sudo cho system-wide install
sudo make install

# Hoặc install vào user directory
cmake -DCMAKE_INSTALL_PREFIX=$HOME/local ..
make install

Build chậm

# Sử dụng nhiều cores
make -j$(nproc)

# Chỉ build target cần thiết
make robot_cpp_node_handle  # Thay vì make all

Clean build

# Xóa toàn bộ build directory
cd build
rm -rf *

# Hoặc xóa chỉ các file object
make clean

Cấu trúc Build Output

Sau khi build, cấu trúc thư mục build/ sẽ như sau:

build/
├── CMakeCache.txt
├── CMakeFiles/
├── cmake_install.cmake
├── Makefile
├── lib/
│   ├── librobot_cpp_console.so
│   ├── librobot_cpp_node_handle.so
│   ├── libmove_base.so
│   ├── libnavigation_c_api.so
│   └── ...
├── src/
│   ├── Libraries/
│   │   ├── robot_cpp/
│   │   └── ...
│   ├── Navigations/
│   │   └── ...
│   └── Algorithms/
│       └── ...
└── bin/  # (nếu có executables)

Environment Variables

Một số biến môi trường hữu ích:

# Chỉ định config directory cho NodeHandle
export PNKX_NAV_CORE_CONFIG_DIR=/path/to/config

# Chỉ định workspace directory
export PNKX_NAV_CORE_DIR=/path/to/pnkx_nav_core

# LD_LIBRARY_PATH (nếu không install)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/pnkx_nav_core/build/lib

Quick Reference

Build nhanh (một lệnh)

mkdir -p build && cd build && cmake .. && make -j$(nproc)

Build và Install

mkdir -p build && cd build && cmake .. && make -j$(nproc) && sudo make install

Rebuild từ đầu

rm -rf build && mkdir build && cd build && cmake .. && make -j$(nproc)

Liên kết hữu ích


Ghi chú

  • Project này sử dụng C++17 standard
  • Warnings đã được tắt trong build configuration (-w flag)
  • Tất cả libraries được build dưới dạng shared libraries (.so)
  • Build type mặc định là Release với optimization -O3