Sensor data entered this runtime and disappeared into the costmap. At 0.05 m with inflation the costmap has destroyed ray order and object shape, so a dock detector fitting lines to find a V plate cannot reconstruct what the laser saw - two 0.2 m wings on that grid are one blob. A reinforcement-learning local planner wants the raw scan for the same reason. Neither had a route: ActionContext held only TF, and LocalPlanner::initialize takes only a costmap. NavigationServer now owns a SensorStore and feeds it from all five doors, handing a read-only port to the action registry and to the controller runner. The store gets the reading BEFORE the filter. Anything that wants filtering filters upstream; the store does not know a filter exists. With laser SOR on, the store and the costmap deliberately see different data - one wants outliers gone, the other wants the true shape - and the comment at addLaserScan now says so, because the one it replaces claimed the opposite. remove* mirrors into the store, dropping readings while keeping the topic declared. A host that has disowned data while the store still serves it means the two disagree about what the robot can currently see, and max_age only covers the tail of that. Reaching a local planner without breaking every other one: widening LocalPlanner::initialize would break hybrid, mppi, priest, stanley and deep_mpc at once for the sake of one planner. A planner that wants sensor data inherits SensorConsumer instead, and ControllerRunner finds out with a dynamic_cast after loading it, at all three sites that build an instance and always before initialize(). Planners that do not inherit it cast to null and nothing happens, so nothing needs rebuilding. That cast crosses a .so boundary and depends on matching RTTI, which a green build does not prove - hence the log line, and hence TestControllerSensorProbe, dlopen'd like a real plugin, to check it actually matches. sensor_store/report_period prints what the store holds every N seconds, off by default. Until a consumer exists it is the only way to see whether data arrives at all, and it is what separates a mistyped topic from a dead sensor - without it the two look identical. It reads age from the control loop's clock, not robot::Time::now(), which is the wall clock while a simulated scan is not. Config is refused at boot, not at first use: an unknown data_type, a short name two packages share, a duplicate topic, a capacity below 1, a max_age that is not positive. Declaring no sensor at all is valid and leaves the store empty and silent - a runtime with no consumer of raw data holds nothing, which is an answer rather than a reason to refuse to start. robot_nav_msgs/OccupancyGrid is registered here rather than in robot_sensor_ports, which ships only its own package's types; pulling robot_nav_msgs into every translation unit that touches the store would be the cost of doing otherwise.
252 lines
12 KiB
C++
252 lines
12 KiB
C++
/*********************************************************************
|
|
*
|
|
* Software License Agreement (BSD License)
|
|
*
|
|
* move_base2 — toàn bộ tham số runtime, đọc từ YAML và validate ở một chỗ.
|
|
*
|
|
* Author: DuongTD
|
|
*********************************************************************/
|
|
#ifndef MOVE_BASE2_CONFIG_MOVE_BASE2_CONFIG_H_
|
|
#define MOVE_BASE2_CONFIG_MOVE_BASE2_CONFIG_H_
|
|
|
|
#include <string>
|
|
|
|
#include <robot/node_handle.h>
|
|
#include <robot_sensor_ports/sensor_store_config.h>
|
|
|
|
#include <move_base2/control_loop.h>
|
|
#include <move_base2/io/sensor_gateway.h>
|
|
|
|
namespace move_base2
|
|
{
|
|
|
|
/**
|
|
* @struct MoveBase2Config
|
|
* @brief Cấu hình đầy đủ của navigation runtime.
|
|
*
|
|
* Ba tính chất bắt buộc, áp cho **mọi** tham số ở đây:
|
|
* 1. có default ngay tại khai báo (không có magic number rải trong code);
|
|
* 2. có đơn vị ghi tại chỗ khai báo khi tham số mang đơn vị;
|
|
* 3. đi qua @ref validate — sai miền giá trị thì runtime **không khởi động**, thay vì chạy tiếp
|
|
* với một giá trị vô nghĩa.
|
|
*
|
|
* Điểm (3) là khác biệt có chủ đích so với bản cũ: nó đọc param không kiểm miền, và có chỗ đọc
|
|
* `max_planning_retries` vào `double` rồi gán sang `int32_t` — một giá trị âm hoặc quá lớn đi thẳng
|
|
* vào vòng điều khiển mà không ai biết.
|
|
*/
|
|
struct MoveBase2Config
|
|
{
|
|
// --- Nhịp chạy -------------------------------------------------------------------------------
|
|
|
|
/// [Hz] Nhịp control loop. Đây cũng là nhịp tick recovery và action.
|
|
double controller_frequency = 20.0;
|
|
|
|
/// [Hz] Nhịp lập plan lại khi đang bám plan. 0 = chỉ lập khi cần (theo yêu cầu của state machine).
|
|
double planner_frequency = 0.0;
|
|
|
|
/// [s] Trần thời gian chờ một lần lập plan trước khi coi là hỏng. <= 0 = không giới hạn.
|
|
double planner_timeout = 5.0;
|
|
|
|
// --- Telemetry --------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* [s] Chu kỳ in bảng thông số runtime (CPU theo thread, chi phí từng đoạn công việc, RSS) ra
|
|
* terminal. `0` = tắt hẳn: không đo, không in, không tốn gì.
|
|
*
|
|
* Mặc định tắt vì đây là công cụ chẩn đoán, không phải thứ chạy trên robot sản xuất — bảng in ở
|
|
* nhịp vài giây vẫn là log trong tiến trình điều khiển. Bật bằng `runtime_stats_period: 5.0`
|
|
* trong `move_base_common_params.yaml`.
|
|
*/
|
|
double runtime_stats_period = 0.0;
|
|
|
|
// --- Hành vi chuyển state --------------------------------------------------------------------
|
|
|
|
StateMachineConfig state_machine;
|
|
|
|
// --- Hàng rào vận tốc cuối cùng ---------------------------------------------------------------
|
|
|
|
VelocityLimits velocity;
|
|
|
|
// --- Đường vào cảm biến -----------------------------------------------------------------------
|
|
|
|
/// Đọc từ namespace con `sensors`. Xem @ref SensorGatewayConfig::laser_sor_enabled về lý do
|
|
/// bộ lọc laser mặc định tắt.
|
|
SensorGatewayConfig sensors;
|
|
|
|
/**
|
|
* Kho cảm biến **thô** dùng chung, đọc từ namespace con `sensor_store`.
|
|
*
|
|
* Khác @ref sensors ở chỗ nó không nằm trên đường vào costmap: costmap nhận bản đã qua
|
|
* `prepareLaserScan`, kho nhận bản THÔ. Bật lọc SOR là hai bên cố ý nhìn hai bản khác nhau —
|
|
* costmap muốn bớt điểm nhiễu, bộ dò muốn hình dạng thật.
|
|
*
|
|
* Không khai sensor nào là hợp lệ: runtime không có consumer nào của dữ liệu thô thì giữ rỗng.
|
|
*/
|
|
robot_sensor_ports::SensorStoreConfig sensor_store;
|
|
|
|
/// Lỗi schema của `sensor_store`, giữ lại để @ref validate chặn boot thay vì chạy với kho rỗng.
|
|
std::string sensor_store_error;
|
|
|
|
/**
|
|
* [s] Chu kỳ in tình trạng kho cảm biến ra terminal. `0` = tắt.
|
|
*
|
|
* Đọc từ `sensor_store/report_period`. Mặc định tắt vì đây là công cụ chẩn đoán, không phải thứ
|
|
* chạy trên robot sản xuất.
|
|
*
|
|
* Việc thật của nó: khi chưa có consumer nào đọc kho, đây là cách DUY NHẤT nhìn thấy dữ liệu có
|
|
* thật sự vào tới nơi hay không. Không có nó thì gõ sai `topic` và cảm biến chết cho cùng một
|
|
* triệu chứng — im lặng.
|
|
*/
|
|
double sensor_store_report_period = 0.0;
|
|
|
|
// --- Ánh xạ profile -> planner ----------------------------------------------------------------
|
|
|
|
ProfileBinding position;
|
|
ProfileBinding docking;
|
|
ProfileBinding go_straight;
|
|
ProfileBinding rotate;
|
|
|
|
/// Alias global planner dự phòng, thử một lần sau khi planner profile active trả failure/plan rỗng.
|
|
std::string backup_global_planner_name;
|
|
|
|
/**
|
|
* Override global/local planner của docking theo marker, đọc từ root
|
|
* `docking_marker_profiles` trong maker_sources.yaml. Marker rỗng hoặc không có entry dùng
|
|
* cặp @ref docking mặc định; mỗi entry phải khai đủ cả hai planner.
|
|
*/
|
|
DockingMarkerProfiles docking_marker_profiles;
|
|
|
|
/// Lỗi schema của `docking_marker_profiles`, giữ lại để @ref validate chặn boot an toàn.
|
|
std::string docking_marker_profiles_error;
|
|
|
|
/// Giữ marker cho docking planner legacy; false cho profile docking dựa hoàn toàn vào goal_frame.
|
|
bool docking_requires_marker = true;
|
|
|
|
// --- Giám sát tuyến ---------------------------------------------------------------------------
|
|
|
|
/// Đọc từ namespace con `path_monitor`. Tắt mặc định — bật bằng config, không bật ngầm.
|
|
ControlLoopConfig::PathMonitorConfig path_monitor;
|
|
|
|
// --- Namespace cho các thành phần nạp plugin ---------------------------------------------------
|
|
|
|
/// Namespace chứa danh sách recovery behavior (`<ns>/behaviors`) trong YAML.
|
|
std::string recovery_namespace = "recovery";
|
|
|
|
/// Namespace chứa danh sách action handler (`<ns>/handlers`) trong YAML.
|
|
std::string action_namespace = "actions";
|
|
|
|
/// Namespace chứa cấu hình mission layer.
|
|
std::string mission_namespace = "mission_adapters";
|
|
|
|
/**
|
|
* Dựng mission layer (`mission_adapters`) hay không.
|
|
*
|
|
* `true` (mặc định): VDA5050 Order đi qua mission layer — order được cắt thành từng chặng tại
|
|
* mỗi node có action, chỉ phần `released` được chạy, `orderUpdateId` nối tiếp thay vì chạy lại,
|
|
* và có `mission_timeout` làm lưới cuối.
|
|
*
|
|
* `false`: order đi thẳng xuống navigation như MỘT goal duy nhất (hành vi của move_base gen-1).
|
|
* Đây là đường lùi khi mission layer gây vấn đề trên hiện trường — đổi một khoá YAML, không phải
|
|
* build lại.
|
|
*
|
|
* @note Bật mà không nạp được nguồn nào thì runtime tự quay về đường trực tiếp **kèm log cảnh
|
|
* báo**: thiếu plugin không được phép biến thành robot đứng im không rõ lý do.
|
|
*/
|
|
bool mission_layer_enabled = true;
|
|
|
|
// --- Frame ------------------------------------------------------------------------------------
|
|
|
|
/// Frame mà goal được quy về trước khi lập plan.
|
|
std::string global_frame = "map";
|
|
|
|
/// Frame gắn với thân robot.
|
|
std::string robot_base_frame = "base_link";
|
|
|
|
/**
|
|
* Chặn điều khiển bánh xe khi observation buffer của costmap điều khiển đã quá hạn.
|
|
*
|
|
* Default `true` = parity với move_base thế hệ 1 (`move_base.cpp:2720`). Xem
|
|
* @ref ControlLoopConfig::require_current_costmap về hệ quả khi tắt.
|
|
*/
|
|
bool require_current_costmap = true;
|
|
|
|
/**
|
|
* @brief Đọc toàn bộ tham số từ @p nh.
|
|
*
|
|
* Khoá thiếu thì giữ default và **log rõ khoá nào** — im lặng dùng default là cách một tham số
|
|
* quan trọng biến mất mà không ai phát hiện. Hàm này không validate; gọi @ref validate sau.
|
|
*
|
|
* @param nh NodeHandle đã scope vào namespace của runtime.
|
|
*/
|
|
void fromNodeHandle(robot::NodeHandle& nh);
|
|
|
|
/**
|
|
* @brief Đọc schema runtime ở root với từng cặp planner độc lập:
|
|
*
|
|
* @code{.yaml}
|
|
* position:
|
|
* global_planner: CustomPlanner
|
|
* local_planner: HybridLocalPlanner
|
|
* @endcode
|
|
*
|
|
* Khác schema gen-1, `local_planner` là plugin `robot_nav_core2::LocalPlanner` thật; không đi
|
|
* qua `LocalPlannerAdapter`. Các tham số runtime chung vẫn nằm ở root cùng cấp với profile.
|
|
*/
|
|
void fromRootProfileNodeHandle(robot::NodeHandle& nh);
|
|
|
|
/**
|
|
* @brief Đọc theo schema move_base gen-1 (`move_base_common_params.yaml`, khoá ở root).
|
|
*
|
|
* Cho phép chuyển sang move_base2 mà KHÔNG phải viết lại cây config đang chạy. Ánh xạ:
|
|
* - `position/docking/go_straight/rotate_planner_name` -> `<profile>.local_planner_name`;
|
|
* - `<TênPlanner>: base_global_planner` -> `<profile>.global_planner_name`, thiếu thì rơi về
|
|
* `base_global_planner` ở root;
|
|
* - `base_local_planner` (LocalPlannerAdapter) bị BỎ QUA có log: adapter là cầu nhúng planner
|
|
* gen-2 vào move_base gen-1, move_base2 gọi thẳng interface gen-2 qua ControllerPort;
|
|
* - tolerance không thuộc move_base2: mỗi local planner tự đọc tolerance từ YAML riêng của nó.
|
|
*
|
|
* Hai khác biệt NGỮ NGHĨA được dịch tường minh (có log cảnh báo khi kích hoạt):
|
|
* 1. patience = 0: gen-1 nghĩa là "fail -> recovery NGAY" (mốc + 0 luôn ở quá khứ), gen-2 nghĩa
|
|
* là "tắt đồng hồ". Giá trị <= 0 được dịch thành đúng MỘT chu kỳ điều khiển — gen-1 cũng chỉ
|
|
* phản ứng được ở độ phân giải cycle nên hành vi giữ nguyên.
|
|
* 2. default của gen-1 khác gen-2: `robot_base_frame` = "base_footprint" (gen-2: "base_link"),
|
|
* tolerance = 0.2 (gen-2: 0.15/0.10). Chế độ legacy giữ default gen-1.
|
|
*
|
|
* @param nh NodeHandle nhìn thấy các khoá gen-1 (thường là root "~").
|
|
*/
|
|
void fromLegacyNodeHandle(robot::NodeHandle& nh);
|
|
|
|
/**
|
|
* @brief Tự nhận diện schema rồi đọc, theo thứ tự: namespace `move_base2`, profile ở root
|
|
* (`position/local_planner`), rồi schema gen-1. Khi một schema đã được chọn, các khoá
|
|
* của schema khác bị bỏ qua toàn bộ — KHÔNG trộn từng khoá giữa chúng.
|
|
*
|
|
* Không trộn per-key là chủ đích: hai nguồn cùng có hiệu lực cho một tham số là đúng kiểu lỗi
|
|
* "sửa config mãi không ăn" đã ghi nhận với hai cây config trùng tên của workspace.
|
|
*/
|
|
static MoveBase2Config load(robot::NodeHandle& root_nh);
|
|
|
|
/**
|
|
* @brief Kiểm miền giá trị của mọi tham số, gồm cả các struct con.
|
|
* @param[out] error Mô tả tham số sai đầu tiên gặp phải; chỉ ghi khi hàm trả false.
|
|
*
|
|
* @warning **Ràng buộc thứ tự khởi tạo:** `state_machine.recovery_behavior_count` không đến từ
|
|
* YAML mà là số behavior `RecoveryRunner` nạp được **thật**. Trình tự đúng là:
|
|
* `fromNodeHandle()` → `RecoveryRunner::configure()` → gán
|
|
* `state_machine.recovery_behavior_count = runner.behaviorCount()` → `validate()`.
|
|
* Đọc con số này từ YAML thì một behavior hỏng vẫn khiến state machine tin là còn đường
|
|
* phục hồi, và lỗi đầu tiên sẽ dẫn thẳng tới ABORTED mà không ai hiểu vì sao.
|
|
*/
|
|
bool validate(std::string& error) const;
|
|
|
|
/// @brief Kết xuất thành text nhiều dòng, để log đúng một lần lúc khởi tạo.
|
|
std::string describe() const;
|
|
|
|
/// @brief Phần cấu hình mà @ref ControlLoop cần, trích ra từ bản đầy đủ này.
|
|
ControlLoopConfig toControlLoopConfig() const;
|
|
};
|
|
|
|
} // namespace move_base2
|
|
|
|
#endif // MOVE_BASE2_CONFIG_MOVE_BASE2_CONFIG_H_
|