Bộ giám sát mới trong ControlLoop (core/env_monitor, core/grid_analysis, ports/environment_port, io/env_logger), thay bốn phép đo của PathMonitor (code cũ còn, tắt bằng path_monitor/enabled: false): - kContact: dò tiếp xúc dọc quỹ đạo local planner (thay cung v/omega), bao tốc độ sqrt(2a(d - margin)) có dư, phanh chỉ khi vượt bao, cờ collision khi kề mũi tĩnh 1 s; cổng xoay tại chỗ theo lệnh controller muốn; hysteresis + xác nhận khi nhả; đứng ra sau detour không dịch robot (nhường controller); giữ phanh khi route khoá thì báo no valid command để controller_patience leo thang. - kStall: cost_to_go = geodesic tới điểm thoát 2 m dọc plan + phần plan còn lại, index plan bám cửa sổ, bộ lọc lật liên thông; cờ no_progress chỉ khi cổng dịch chuyển thực mở (robot không đi được đâu trong 12 s dù lệnh >= 1,5 m) — thay ngân sách replan cho stall. - kUnreachable: liên thông tới điểm thoát, đang ở action log. - EnvLogger ghi JSONL mỗi tick nặng; config/runtime/env_monitor_params.yaml đủ khoá, comment tiếng Việt; ControllerPort::measuredVelocity; FakeEnvironmentPort cho test. Sim 5–6/9: hết churn detour, khe 1,25 m đi qua 0,5 m/s, lượt 6/9 10:15 2 detour/142 s không oan. Test: grid_analysis 31, env_monitor 43, plan_inspector 37, walking_skeleton 87, các bộ khác pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xXjFjr2DQ6rhmhHSW4fk4
982 lines
41 KiB
C++
982 lines
41 KiB
C++
/*********************************************************************
|
|
* move_base2 — đọc và validate cấu hình runtime.
|
|
*
|
|
* Author: DuongTD
|
|
*********************************************************************/
|
|
#include <move_base2/config/move_base2_config.h>
|
|
|
|
#include <cmath>
|
|
#include <sstream>
|
|
|
|
#include <robot/robot.h>
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
namespace move_base2
|
|
{
|
|
namespace
|
|
{
|
|
|
|
/// Đọc một khoá double; thiếu khoá thì giữ nguyên default và nói rõ khoá nào bị thiếu.
|
|
void readDouble(robot::NodeHandle& nh, const std::string& key, double& value)
|
|
{
|
|
if (!nh.hasParam(key))
|
|
{
|
|
robot::log_warning("[move_base2] missing param '%s', using default %.4f", key.c_str(), value);
|
|
return;
|
|
}
|
|
nh.param(key, value, value);
|
|
}
|
|
|
|
void readInt(robot::NodeHandle& nh, const std::string& key, int& value)
|
|
{
|
|
if (!nh.hasParam(key))
|
|
{
|
|
robot::log_warning("[move_base2] missing param '%s', using default %d", key.c_str(), value);
|
|
return;
|
|
}
|
|
nh.param(key, value, value);
|
|
}
|
|
|
|
void readBool(robot::NodeHandle& nh, const std::string& key, bool& value)
|
|
{
|
|
if (!nh.hasParam(key))
|
|
{
|
|
robot::log_warning("[move_base2] missing param '%s', using default %s", key.c_str(),
|
|
value ? "true" : "false");
|
|
return;
|
|
}
|
|
nh.param(key, value, value);
|
|
}
|
|
|
|
void readString(robot::NodeHandle& nh, const std::string& key, std::string& value)
|
|
{
|
|
if (!nh.hasParam(key))
|
|
{
|
|
robot::log_warning("[move_base2] missing param '%s', using default '%s'", key.c_str(),
|
|
value.c_str());
|
|
return;
|
|
}
|
|
nh.param(key, value, value);
|
|
}
|
|
|
|
/// Đọc một binding profile từ namespace con cùng tên.
|
|
void readBinding(robot::NodeHandle& nh, const std::string& ns, ProfileBinding& binding)
|
|
{
|
|
robot::NodeHandle profile_nh(nh, ns);
|
|
readString(profile_nh, "base_global_planner", binding.global_planner_name);
|
|
readString(profile_nh, "base_local_planner", binding.local_planner_name);
|
|
}
|
|
|
|
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors);
|
|
void readDebug(robot::NodeHandle& nh, MoveBase2Config& config);
|
|
void readEnvMonitor(robot::NodeHandle& nh, MoveBase2Config& config);
|
|
|
|
void readSensorStore(robot::NodeHandle& nh, MoveBase2Config& config);
|
|
|
|
/// Đọc cặp planner runtime trực tiếp, không có adapter gen-1 ở giữa.
|
|
void readRootProfileBinding(robot::NodeHandle& nh, const std::string& ns, ProfileBinding& binding)
|
|
{
|
|
robot::NodeHandle profile_nh(nh, ns);
|
|
readString(profile_nh, "global_planner", binding.global_planner_name);
|
|
readString(profile_nh, "local_planner", binding.local_planner_name);
|
|
}
|
|
|
|
void readDockingMarkerProfiles(robot::NodeHandle& nh, DockingMarkerProfiles& profiles,
|
|
std::string& error)
|
|
{
|
|
profiles.clear();
|
|
error.clear();
|
|
|
|
if (!nh.hasParam("docking_marker_profiles"))
|
|
{
|
|
return; // Optional: the default docking binding remains authoritative.
|
|
}
|
|
const YAML::Node table = nh.getParamValue("docking_marker_profiles");
|
|
if (!table || !table.IsDefined())
|
|
{
|
|
error = "docking_marker_profiles is declared but cannot be read";
|
|
return;
|
|
}
|
|
if (!table.IsMap())
|
|
{
|
|
error = "docking_marker_profiles must be a map of marker names";
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
for (auto entry = table.begin(); entry != table.end(); ++entry)
|
|
{
|
|
const std::string marker = entry->first.as<std::string>();
|
|
const YAML::Node value = entry->second;
|
|
if (marker.empty() || !value.IsMap())
|
|
{
|
|
error = "docking_marker_profiles has an empty marker name or a non-map entry";
|
|
return;
|
|
}
|
|
if (!value["global_planner"] || !value["local_planner"] ||
|
|
!value["global_planner"].IsScalar() || !value["local_planner"].IsScalar())
|
|
{
|
|
error = "docking_marker_profiles/'" + marker +
|
|
"' must set scalar global_planner and local_planner";
|
|
return;
|
|
}
|
|
|
|
ProfileBinding binding;
|
|
binding.global_planner_name = value["global_planner"].as<std::string>();
|
|
binding.local_planner_name = value["local_planner"].as<std::string>();
|
|
if (binding.global_planner_name.empty() || binding.local_planner_name.empty())
|
|
{
|
|
error = "docking_marker_profiles/'" + marker +
|
|
"' has an empty global_planner or local_planner";
|
|
return;
|
|
}
|
|
profiles.emplace(marker, std::move(binding));
|
|
}
|
|
}
|
|
catch (const YAML::Exception& ex)
|
|
{
|
|
error = std::string("docking_marker_profiles is malformed: ") + ex.what();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Đọc khối `path_monitor`.
|
|
*
|
|
* Khối vắng mặt = giám sát tuyến TẮT, hành vi y hệt trước 2026-08-04d. Đây là đường lùi thứ nhất
|
|
* (thứ hai là route `path_blocked`/`off_path` rỗng) — hai nút độc lập, cố ý.
|
|
*/
|
|
void readPathMonitor(robot::NodeHandle& nh, ControlLoopConfig::PathMonitorConfig& monitor)
|
|
{
|
|
robot::NodeHandle monitor_nh(nh, "path_monitor");
|
|
|
|
readBool(monitor_nh, "enabled", monitor.enabled);
|
|
readBool(monitor_nh, "path_blocked_enabled", monitor.path_blocked_enabled);
|
|
readBool(monitor_nh, "off_path_enabled", monitor.off_path_enabled);
|
|
readDouble(monitor_nh, "check_period", monitor.check_period);
|
|
readDouble(monitor_nh, "confirm_time", monitor.confirm_time);
|
|
readDouble(monitor_nh, "horizon", monitor.horizon);
|
|
readDouble(monitor_nh, "min_detour_distance", monitor.min_detour_distance);
|
|
readDouble(monitor_nh, "max_cross_track", monitor.max_cross_track);
|
|
readDouble(monitor_nh, "grace_after_new_plan", monitor.grace_after_new_plan);
|
|
|
|
// Phép đo 3 (2026-09-03): thân sắp chạm vật cản THẬT trên cung lệnh. Khoá riêng, không dùng chung
|
|
// tham số nào với hai phép đo trên.
|
|
readBool(monitor_nh, "collision_enabled", monitor.collision_enabled);
|
|
readDouble(monitor_nh, "collision_lookahead", monitor.collision_lookahead);
|
|
monitor_nh.param("collision_max_samples", monitor.collision_max_samples,
|
|
monitor.collision_max_samples);
|
|
readDouble(monitor_nh, "collision_stop_distance", monitor.collision_stop_distance);
|
|
monitor_nh.param("collision_confirm_cycles", monitor.collision_confirm_cycles,
|
|
monitor.collision_confirm_cycles);
|
|
monitor_nh.param("collision_cost_threshold", monitor.collision_cost_threshold,
|
|
monitor.collision_cost_threshold);
|
|
readDouble(monitor_nh, "collision_front_offset", monitor.collision_front_offset);
|
|
readDouble(monitor_nh, "collision_rear_offset", monitor.collision_rear_offset);
|
|
readDouble(monitor_nh, "collision_side_offset", monitor.collision_side_offset);
|
|
readDouble(monitor_nh, "collision_footprint_padding", monitor.collision_footprint_padding);
|
|
readBool(monitor_nh, "collision_exclude_baseline", monitor.collision_exclude_baseline);
|
|
readDouble(monitor_nh, "collision_min_speed", monitor.collision_min_speed);
|
|
readDouble(monitor_nh, "collision_stop_time", monitor.collision_stop_time);
|
|
readDouble(monitor_nh, "collision_stop_angle", monitor.collision_stop_angle);
|
|
readDouble(monitor_nh, "collision_lookahead_angle", monitor.collision_lookahead_angle);
|
|
readDouble(monitor_nh, "collision_brake_decel", monitor.collision_brake_decel);
|
|
|
|
// Phép đo 4 (2026-09-04): planner đòi đi mà robot không tiến.
|
|
readBool(monitor_nh, "progress_enabled", monitor.progress_enabled);
|
|
readString(monitor_nh, "progress_action", monitor.progress_action);
|
|
readDouble(monitor_nh, "progress_window", monitor.progress_window);
|
|
readDouble(monitor_nh, "progress_min_commanded", monitor.progress_min_commanded);
|
|
readDouble(monitor_nh, "progress_min_efficiency", monitor.progress_min_efficiency);
|
|
readDouble(monitor_nh, "progress_clear_efficiency", monitor.progress_clear_efficiency);
|
|
readDouble(monitor_nh, "progress_confirm_time", monitor.progress_confirm_time);
|
|
readDouble(monitor_nh, "progress_goal_zone", monitor.progress_goal_zone);
|
|
|
|
std::vector<std::string> names;
|
|
monitor_nh.param("profiles", names, std::vector<std::string>{});
|
|
if (names.empty())
|
|
{
|
|
return; // Giữ mặc định: chỉ profile position.
|
|
}
|
|
|
|
monitor.profiles.clear();
|
|
for (const std::string& name : names)
|
|
{
|
|
if (name == "position")
|
|
{
|
|
monitor.profiles.push_back(MotionProfile::kPosition);
|
|
}
|
|
else if (name == "docking")
|
|
{
|
|
monitor.profiles.push_back(MotionProfile::kDocking);
|
|
}
|
|
else if (name == "go_straight")
|
|
{
|
|
monitor.profiles.push_back(MotionProfile::kGoStraight);
|
|
}
|
|
else if (name == "rotate")
|
|
{
|
|
monitor.profiles.push_back(MotionProfile::kRotate);
|
|
}
|
|
else
|
|
{
|
|
// Không đoán: tên lạ mà im lặng bỏ qua thì người vận hành tưởng đã bật giám sát cho profile
|
|
// đó. Cảnh báo rồi bỏ — profile lạ không thể tự sinh ra hành vi nào.
|
|
robot::log_warning("[move_base2] path_monitor/profiles: unknown profile '%s', ignored.\n",
|
|
name.c_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Các tham số chung của move_base2, dùng chung cho schema namespace và schema root-profile.
|
|
void readMoveBase2Fields(robot::NodeHandle& nh, MoveBase2Config& config)
|
|
{
|
|
readDouble(nh, "controller_frequency", config.controller_frequency);
|
|
readDouble(nh, "planner_frequency", config.planner_frequency);
|
|
readDouble(nh, "planner_timeout", config.planner_timeout);
|
|
readDouble(nh, "runtime_stats_period", config.runtime_stats_period);
|
|
|
|
readDouble(nh, "planner_patience", config.state_machine.planner_patience);
|
|
readDouble(nh, "controller_patience", config.state_machine.controller_patience);
|
|
readDouble(nh, "sensor_patience", config.state_machine.sensor_patience);
|
|
readDouble(nh, "oscillation_timeout", config.state_machine.oscillation_timeout);
|
|
readDouble(nh, "oscillation_distance", config.state_machine.oscillation_distance);
|
|
readDouble(nh, "recovery_reset_min_travel", config.state_machine.recovery_reset_min_travel);
|
|
readDouble(nh, "action_patience", config.state_machine.action_patience);
|
|
readInt(nh, "max_planning_retries", config.state_machine.max_planning_retries);
|
|
readBool(nh, "recovery_behavior_enabled", config.state_machine.recovery_enabled);
|
|
|
|
// Nghĩa của Twist đi qua arbiter — quyết định đơn vị của cả cụm giới hạn bên dưới. "steering"
|
|
// (linear.x = tốc độ bánh steer, angular.z = GÓC lái) là convention của robot lái một bánh
|
|
// trong workspace; để mặc định "twist" cho robot vi sai. Giá trị lạ giữ nguyên mặc định và
|
|
// cảnh báo, không chết boot — nhưng validate() của VelocityLimits sẽ chặn tổ hợp vô nghĩa.
|
|
{
|
|
std::string semantics = toString(config.velocity.semantics);
|
|
readString(nh, "command_semantics", semantics);
|
|
if (semantics == "steering")
|
|
config.velocity.semantics = CommandSemantics::kSteering;
|
|
else if (semantics == "twist")
|
|
config.velocity.semantics = CommandSemantics::kTwist;
|
|
else
|
|
robot::log_warning("[move_base2] unknown command_semantics '%s', keeping '%s'",
|
|
semantics.c_str(), toString(config.velocity.semantics));
|
|
}
|
|
|
|
readDouble(nh, "max_vel_x", config.velocity.max_vel_x);
|
|
readDouble(nh, "min_vel_x", config.velocity.min_vel_x);
|
|
readDouble(nh, "max_vel_theta", config.velocity.max_vel_theta);
|
|
readDouble(nh, "acc_lim_x", config.velocity.max_accel_x);
|
|
readDouble(nh, "acc_lim_theta", config.velocity.max_accel_theta);
|
|
|
|
readSensors(nh, config.sensors);
|
|
readSensorStore(nh, config);
|
|
readDebug(nh, config);
|
|
readPathMonitor(nh, config.path_monitor);
|
|
readEnvMonitor(nh, config);
|
|
readBool(nh, "docking_requires_marker", config.docking_requires_marker);
|
|
|
|
readString(nh, "recovery_namespace", config.recovery_namespace);
|
|
readString(nh, "action_namespace", config.action_namespace);
|
|
readString(nh, "mission_namespace", config.mission_namespace);
|
|
readBool(nh, "mission_layer_enabled", config.mission_layer_enabled);
|
|
readString(nh, "backup_global_planner", config.backup_global_planner_name);
|
|
readString(nh, "global_frame", config.global_frame);
|
|
readString(nh, "robot_base_frame", config.robot_base_frame);
|
|
readBool(nh, "require_current_costmap", config.require_current_costmap);
|
|
}
|
|
|
|
bool validateBinding(const ProfileBinding& binding, const char* name, std::string& error)
|
|
{
|
|
(void)name;
|
|
(void)error;
|
|
if (binding.local_planner_name.empty())
|
|
{
|
|
// Không đặt là hợp lệ: deployment có thể không dùng profile đó.
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// Đọc khai báo kho cảm biến thô từ namespace con `sensor_store`.
|
|
///
|
|
/// Lỗi được CẤT chứ không ném: `fromNodeHandle` là void và được gọi trên nhiều schema khác nhau,
|
|
/// nên chỗ duy nhất chặn boot được là `validate()`. Cùng khuôn với `docking_marker_profiles_error`.
|
|
void readSensorStore(robot::NodeHandle& nh, MoveBase2Config& config)
|
|
{
|
|
config.sensor_store_error.clear();
|
|
|
|
if (!robot_sensor_ports::SensorStoreConfig::load(nh, "sensor_store", config.sensor_store,
|
|
config.sensor_store_error))
|
|
{
|
|
config.sensor_store.sensors.clear();
|
|
}
|
|
|
|
robot::NodeHandle store_nh(nh, "sensor_store");
|
|
readDouble(store_nh, "report_period", config.sensor_store_report_period);
|
|
}
|
|
|
|
/// Đọc công tắc log chẩn đoán từ namespace con `debug`.
|
|
void readDebug(robot::NodeHandle& nh, MoveBase2Config& config)
|
|
{
|
|
robot::NodeHandle debug_nh(nh, "debug");
|
|
readBool(debug_nh, "state", config.debug_state);
|
|
readBool(debug_nh, "plan", config.debug_plan);
|
|
readBool(debug_nh, "skip", config.debug_skip);
|
|
readBool(debug_nh, "env", config.debug_env);
|
|
}
|
|
|
|
/// Đọc khối `env_monitor` (xem config/runtime/env_monitor_params.yaml).
|
|
void readEnvMonitor(robot::NodeHandle& nh, MoveBase2Config& config)
|
|
{
|
|
robot::NodeHandle env_nh(nh, "env_monitor");
|
|
EnvMonitorConfig& m = config.env_monitor;
|
|
EnvSamplingConfig& s = config.env_sampling;
|
|
|
|
readBool(env_nh, "enabled", m.enabled);
|
|
readDouble(env_nh, "grace_after_new_plan", m.grace_after_new_plan);
|
|
readDouble(env_nh, "check_period", s.check_period);
|
|
|
|
robot::NodeHandle body_nh(env_nh, "body");
|
|
readDouble(body_nh, "front_offset", s.body_front);
|
|
readDouble(body_nh, "rear_offset", s.body_rear);
|
|
readDouble(body_nh, "side_offset", s.body_side);
|
|
readDouble(body_nh, "padding", s.padding);
|
|
readInt(body_nh, "lethal_threshold", s.lethal_threshold);
|
|
|
|
robot::NodeHandle geo_nh(env_nh, "geometry");
|
|
readDouble(geo_nh, "horizon", s.horizon);
|
|
readDouble(geo_nh, "corridor_margin", s.corridor_margin);
|
|
readDouble(geo_nh, "corridor_cap", s.corridor_cap);
|
|
readDouble(geo_nh, "target_backoff", s.target_backoff);
|
|
readDouble(geo_nh, "robot_snap", s.robot_snap);
|
|
readDouble(geo_nh, "track_back", s.track_back);
|
|
readDouble(geo_nh, "track_ahead", s.track_ahead);
|
|
readDouble(geo_nh, "exit_ahead", s.exit_ahead);
|
|
|
|
robot::NodeHandle stall_nh(env_nh, "stall");
|
|
readBool(stall_nh, "enabled", m.stall.enabled);
|
|
readString(stall_nh, "action", m.stall.action);
|
|
readDouble(stall_nh, "window_s", m.stall.window_s);
|
|
readDouble(stall_nh, "window_m", m.stall.window_m);
|
|
readDouble(stall_nh, "min_commanded", m.stall.min_commanded);
|
|
readDouble(stall_nh, "eff_on", m.stall.eff_on);
|
|
readDouble(stall_nh, "eff_off", m.stall.eff_off);
|
|
readDouble(stall_nh, "confirm", m.stall.confirm);
|
|
readDouble(stall_nh, "goal_zone", m.stall.goal_zone);
|
|
readDouble(stall_nh, "slip_on", m.stall.slip_on);
|
|
readDouble(stall_nh, "slip_time", m.stall.slip_time);
|
|
readDouble(stall_nh, "min_commanded_since_goal", m.stall.min_commanded_since_goal);
|
|
readDouble(stall_nh, "retry_backoff", m.stall.retry_backoff);
|
|
readDouble(stall_nh, "jump_reject", m.stall.jump_reject);
|
|
readDouble(stall_nh, "disp_window_s", m.stall.disp_window_s);
|
|
readDouble(stall_nh, "disp_min", m.stall.disp_min);
|
|
readDouble(stall_nh, "disp_min_commanded", m.stall.disp_min_commanded);
|
|
|
|
robot::NodeHandle unreach_nh(env_nh, "unreachable");
|
|
readBool(unreach_nh, "enabled", m.unreachable.enabled);
|
|
readString(unreach_nh, "action", m.unreachable.action);
|
|
readDouble(unreach_nh, "static_on", m.unreachable.static_on);
|
|
readDouble(unreach_nh, "clean_start_margin", m.unreachable.clean_start_margin);
|
|
readDouble(unreach_nh, "retry_backoff", m.unreachable.retry_backoff);
|
|
|
|
robot::NodeHandle contact_nh(env_nh, "contact");
|
|
readBool(contact_nh, "enabled", m.contact.enabled);
|
|
readString(contact_nh, "action", m.contact.action);
|
|
readBool(contact_nh, "apply_command", m.contact.apply_command);
|
|
readString(contact_nh, "use_local_plan", s.use_local_plan);
|
|
readDouble(contact_nh, "local_plan_start_tol", s.local_plan_start_tol);
|
|
readDouble(contact_nh, "lookahead", s.contact_lookahead);
|
|
readInt(contact_nh, "confirm_cycles", m.contact.confirm_cycles);
|
|
readDouble(contact_nh, "trigger_static_time", m.contact.trigger_static_time);
|
|
readDouble(contact_nh, "clean_start_margin", m.contact.clean_start_margin);
|
|
readDouble(contact_nh, "brake_decel", m.contact.brake_decel);
|
|
readDouble(contact_nh, "min_speed", m.contact.min_speed);
|
|
readDouble(contact_nh, "min_check_speed", m.contact.min_check_speed);
|
|
readDouble(contact_nh, "release_hysteresis", m.contact.release_hysteresis);
|
|
readInt(contact_nh, "release_confirm_cycles", m.contact.release_confirm_cycles);
|
|
readDouble(contact_nh, "envelope_margin", m.contact.envelope_margin);
|
|
readDouble(contact_nh, "standdown_min_travel", m.contact.standdown_min_travel);
|
|
readDouble(contact_nh, "standdown_travel", m.contact.standdown_travel);
|
|
readBool(contact_nh, "envelope", m.contact.envelope);
|
|
|
|
robot::NodeHandle budget_nh(env_nh, "replan_budget");
|
|
readDouble(budget_nh, "min_travel", m.replan.min_travel);
|
|
readDouble(budget_nh, "escalate_factor", m.replan.escalate_factor);
|
|
readDouble(budget_nh, "escalate_window_m", m.replan.escalate_window_m);
|
|
readDouble(budget_nh, "escalate_max", m.replan.escalate_max);
|
|
|
|
robot::NodeHandle logger_nh(env_nh, "logger");
|
|
readBool(logger_nh, "enabled", config.env_logger.enabled);
|
|
readString(logger_nh, "log_dir", config.env_logger.log_dir);
|
|
readDouble(logger_nh, "flush_period", config.env_logger.flush_period);
|
|
|
|
std::vector<std::string> names;
|
|
env_nh.param("profiles", names, std::vector<std::string>{});
|
|
if (!names.empty())
|
|
{
|
|
s.profiles.clear();
|
|
for (const std::string& name : names)
|
|
{
|
|
if (name == "position")
|
|
{
|
|
s.profiles.push_back(MotionProfile::kPosition);
|
|
}
|
|
else if (name == "docking")
|
|
{
|
|
s.profiles.push_back(MotionProfile::kDocking);
|
|
}
|
|
else if (name == "go_straight")
|
|
{
|
|
s.profiles.push_back(MotionProfile::kGoStraight);
|
|
}
|
|
else if (name == "rotate")
|
|
{
|
|
s.profiles.push_back(MotionProfile::kRotate);
|
|
}
|
|
else
|
|
{
|
|
robot::log_warning("[move_base2] env_monitor/profiles: unknown profile '%s', ignored.\n",
|
|
name.c_str());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Đọc cấu hình đường vào cảm biến từ namespace con `sensors`.
|
|
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors)
|
|
{
|
|
robot::NodeHandle sensors_nh(nh, "sensors");
|
|
readBool(sensors_nh, "laser_sor_enabled", sensors.laser_sor_enabled);
|
|
readInt(sensors_nh, "laser_sor_mean_k", sensors.laser_sor_mean_k);
|
|
readDouble(sensors_nh, "laser_sor_stddev_mul", sensors.laser_sor_stddev_mul);
|
|
}
|
|
|
|
void describeBinding(std::ostringstream& out, const char* name, const ProfileBinding& binding)
|
|
{
|
|
out << " " << name << ": global='" << binding.global_planner_name << "' local='"
|
|
<< binding.local_planner_name << "'\n";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void MoveBase2Config::fromNodeHandle(robot::NodeHandle& nh)
|
|
{
|
|
readMoveBase2Fields(nh, *this);
|
|
|
|
readBinding(nh, "position", position);
|
|
readBinding(nh, "docking", docking);
|
|
readBinding(nh, "go_straight", go_straight);
|
|
readBinding(nh, "rotate", rotate);
|
|
readDockingMarkerProfiles(nh, docking_marker_profiles, docking_marker_profiles_error);
|
|
|
|
// recovery_behavior_count KHÔNG đọc từ YAML: nó là số behavior thực sự nạp được, do
|
|
// RecoveryRunner báo lại sau khi configure. Đọc từ config thì một behavior hỏng sẽ khiến state
|
|
// machine tin là vẫn còn đường phục hồi.
|
|
}
|
|
|
|
void MoveBase2Config::fromRootProfileNodeHandle(robot::NodeHandle& nh)
|
|
{
|
|
readMoveBase2Fields(nh, *this);
|
|
readRootProfileBinding(nh, "position", position);
|
|
readRootProfileBinding(nh, "docking", docking);
|
|
readRootProfileBinding(nh, "go_straight", go_straight);
|
|
readRootProfileBinding(nh, "rotate", rotate);
|
|
readDockingMarkerProfiles(nh, docking_marker_profiles, docking_marker_profiles_error);
|
|
}
|
|
|
|
bool MoveBase2Config::validate(std::string& error) const
|
|
{
|
|
if (!docking_marker_profiles_error.empty())
|
|
{
|
|
error = docking_marker_profiles_error;
|
|
return false;
|
|
}
|
|
if (!std::isfinite(controller_frequency) || controller_frequency <= 0.0)
|
|
{
|
|
error = "controller_frequency must be > 0 [Hz]";
|
|
return false;
|
|
}
|
|
if (controller_frequency > 200.0)
|
|
{
|
|
error = "controller_frequency > 200 Hz — unrealistic rate for a control loop that owns a "
|
|
"costmap";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(planner_frequency) || planner_frequency < 0.0)
|
|
{
|
|
error = "planner_frequency must be >= 0 [Hz] (0 = plan only when needed)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(planner_timeout))
|
|
{
|
|
error = "planner_timeout is not finite [s]";
|
|
return false;
|
|
}
|
|
|
|
if (path_monitor.enabled)
|
|
{
|
|
// Chỉ kiểm khi BẬT: tham số vô nghĩa trong một khối đang tắt không có lý do gì để chặn boot.
|
|
if (!std::isfinite(path_monitor.check_period) || path_monitor.check_period <= 0.0)
|
|
{
|
|
error = "path_monitor/check_period must be > 0 [s]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.confirm_time) || path_monitor.confirm_time < 0.0)
|
|
{
|
|
error = "path_monitor/confirm_time must be >= 0 [s]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.horizon) || path_monitor.horizon < 0.0)
|
|
{
|
|
error = "path_monitor/horizon must be >= 0 [m] (0 = the blocked-path check is off)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.min_detour_distance) || path_monitor.min_detour_distance < 0.0)
|
|
{
|
|
error = "path_monitor/min_detour_distance must be >= 0 [m]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.max_cross_track) || path_monitor.max_cross_track < 0.0)
|
|
{
|
|
error = "path_monitor/max_cross_track must be >= 0 [m] (0 = the off-path check is off)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.grace_after_new_plan) ||
|
|
path_monitor.grace_after_new_plan < 0.0)
|
|
{
|
|
error = "path_monitor/grace_after_new_plan must be >= 0 [s]";
|
|
return false;
|
|
}
|
|
if (path_monitor.collision_enabled)
|
|
{
|
|
const auto bad = [](double v) { return !std::isfinite(v) || v < 0.0; };
|
|
if (!std::isfinite(path_monitor.collision_lookahead) || path_monitor.collision_lookahead <= 0.0)
|
|
{
|
|
error = "path_monitor/collision_lookahead must be > 0 [m]";
|
|
return false;
|
|
}
|
|
if (path_monitor.collision_max_samples < 1)
|
|
{
|
|
error = "path_monitor/collision_max_samples must be >= 1";
|
|
return false;
|
|
}
|
|
if (bad(path_monitor.collision_stop_distance) ||
|
|
path_monitor.collision_stop_distance > path_monitor.collision_lookahead)
|
|
{
|
|
error = "path_monitor/collision_stop_distance must be in [0, collision_lookahead] [m]";
|
|
return false;
|
|
}
|
|
if (path_monitor.collision_confirm_cycles < 1)
|
|
{
|
|
error = "path_monitor/collision_confirm_cycles must be >= 1";
|
|
return false;
|
|
}
|
|
if (path_monitor.collision_cost_threshold < 1 || path_monitor.collision_cost_threshold > 254)
|
|
{
|
|
error = "path_monitor/collision_cost_threshold must be in [1, 254] (254 = LETHAL only)";
|
|
return false;
|
|
}
|
|
if (bad(path_monitor.collision_front_offset) || bad(path_monitor.collision_rear_offset) ||
|
|
bad(path_monitor.collision_side_offset) || bad(path_monitor.collision_footprint_padding))
|
|
{
|
|
error = "path_monitor/collision_*_offset and collision_footprint_padding must be >= 0 [m]";
|
|
return false;
|
|
}
|
|
{
|
|
// Cả ba = 0: lấy thân từ footprint costmap lúc chạy. Khai tay thì phải đủ cả ba > 0 — mũi = 0
|
|
// là chỉ dò tâm (dừng khi tâm đã ở trong tường), hông = 0 là bỏ hai cạnh hông.
|
|
const int declared = (path_monitor.collision_front_offset > 0.0 ? 1 : 0) +
|
|
(path_monitor.collision_rear_offset > 0.0 ? 1 : 0) +
|
|
(path_monitor.collision_side_offset > 0.0 ? 1 : 0);
|
|
if (declared != 0 && declared != 3)
|
|
{
|
|
error = "path_monitor/collision_front_offset, collision_rear_offset and "
|
|
"collision_side_offset must either all be 0 (take the body from the costmap "
|
|
"footprint) or all be > 0 [m]";
|
|
return false;
|
|
}
|
|
}
|
|
if (!std::isfinite(path_monitor.collision_stop_time) || path_monitor.collision_stop_time <= 0.0)
|
|
{
|
|
error = "path_monitor/collision_stop_time must be > 0 [s]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.collision_stop_angle) || path_monitor.collision_stop_angle <= 0.0 ||
|
|
path_monitor.collision_stop_angle > M_PI)
|
|
{
|
|
error = "path_monitor/collision_stop_angle must be in (0, pi] [rad]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.collision_lookahead_angle) ||
|
|
path_monitor.collision_lookahead_angle < path_monitor.collision_stop_angle ||
|
|
path_monitor.collision_lookahead_angle > M_PI)
|
|
{
|
|
error = "path_monitor/collision_lookahead_angle must be in [collision_stop_angle, pi] [rad]";
|
|
return false;
|
|
}
|
|
if (bad(path_monitor.collision_min_speed) || bad(path_monitor.collision_brake_decel))
|
|
{
|
|
error = "path_monitor/collision_min_speed [m/s] and collision_brake_decel [m/s^2] must be >= 0";
|
|
return false;
|
|
}
|
|
}
|
|
if (path_monitor.progress_enabled)
|
|
{
|
|
if (path_monitor.progress_action != "log" && path_monitor.progress_action != "recover")
|
|
{
|
|
error = "path_monitor/progress_action must be 'log' or 'recover'";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.progress_window) || path_monitor.progress_window <= 0.0)
|
|
{
|
|
error = "path_monitor/progress_window must be > 0 [s]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.progress_min_commanded) ||
|
|
path_monitor.progress_min_commanded <= 0.0)
|
|
{
|
|
// 0 là đo cả lúc đứng yên: cmd = 0, eff = 0/0 -> mọi lần chờ hợp lệ đều thành "kẹt".
|
|
error = "path_monitor/progress_min_commanded must be > 0 [m]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.progress_min_efficiency) ||
|
|
!std::isfinite(path_monitor.progress_clear_efficiency) ||
|
|
path_monitor.progress_min_efficiency < 0.0 ||
|
|
path_monitor.progress_clear_efficiency <= path_monitor.progress_min_efficiency)
|
|
{
|
|
// clear == min là cờ nhấp nháy quanh một ngưỡng: bật, xoá, bật... mỗi lượt quét.
|
|
error = "path_monitor/progress_clear_efficiency must be > progress_min_efficiency >= 0";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(path_monitor.progress_confirm_time) ||
|
|
path_monitor.progress_confirm_time < 0.0 ||
|
|
!std::isfinite(path_monitor.progress_goal_zone) || path_monitor.progress_goal_zone < 0.0)
|
|
{
|
|
error = "path_monitor/progress_confirm_time [s] and progress_goal_zone [m] must be >= 0";
|
|
return false;
|
|
}
|
|
}
|
|
if (!(path_monitor.horizon > 0.0) && !(path_monitor.max_cross_track > 0.0) &&
|
|
!path_monitor.collision_enabled && !path_monitor.progress_enabled)
|
|
{
|
|
// Bật khối mà tắt cả bốn phép đo là mâu thuẫn: người khai tưởng giám sát đang chạy.
|
|
error = "path_monitor is enabled but all checks are off; set horizon > 0 [m], "
|
|
"max_cross_track > 0 [m], collision_enabled: true and/or progress_enabled: true, "
|
|
"or set enabled: false";
|
|
return false;
|
|
}
|
|
if (path_monitor.profiles.empty())
|
|
{
|
|
error = "path_monitor/profiles is empty; no leg would ever be monitored";
|
|
return false;
|
|
}
|
|
}
|
|
if (!std::isfinite(runtime_stats_period) || runtime_stats_period < 0.0)
|
|
{
|
|
error = "runtime_stats_period must be >= 0 [s] (0 = telemetry off)";
|
|
return false;
|
|
}
|
|
|
|
if (recovery_namespace.empty())
|
|
{
|
|
error = "recovery_namespace is empty";
|
|
return false;
|
|
}
|
|
if (mission_layer_enabled && mission_namespace.empty())
|
|
{
|
|
error = "mission_layer_enabled is true but mission_namespace is empty — there would be no "
|
|
"namespace to read `mission_sources` from";
|
|
return false;
|
|
}
|
|
if (global_frame.empty() || robot_base_frame.empty())
|
|
{
|
|
error = "global_frame and robot_base_frame must not be empty";
|
|
return false;
|
|
}
|
|
if (global_frame == robot_base_frame)
|
|
{
|
|
error = "global_frame equals robot_base_frame — the robot pose would always be the origin";
|
|
return false;
|
|
}
|
|
|
|
if (!validateBinding(position, "position", error) ||
|
|
!validateBinding(docking, "docking", error) ||
|
|
!validateBinding(go_straight, "go_straight", error) ||
|
|
!validateBinding(rotate, "rotate", error))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (position.local_planner_name.empty() && docking.local_planner_name.empty() &&
|
|
go_straight.local_planner_name.empty() && rotate.local_planner_name.empty())
|
|
{
|
|
error = "no profile has base_local_planner — the runtime would reject every request";
|
|
return false;
|
|
}
|
|
|
|
if (env_monitor.enabled)
|
|
{
|
|
if (!env_monitor.validate(error) || !env_sampling.validate(error) || !env_logger.validate(error))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!velocity.validate(error))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!sensors.validate(error))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Khai kho sai thì chặn boot, không im lặng chạy với kho rỗng: consumer nào cần dữ liệu thô sẽ
|
|
// chờ mãi không có gì, và triệu chứng giống hệt cảm biến chết.
|
|
if (!sensor_store_error.empty())
|
|
{
|
|
error = "sensor_store: " + sensor_store_error;
|
|
return false;
|
|
}
|
|
|
|
if (!std::isfinite(sensor_store_report_period) || sensor_store_report_period < 0.0)
|
|
{
|
|
error = "sensor_store/report_period must be a finite value >= 0 (0 = off)";
|
|
return false;
|
|
}
|
|
|
|
// Sau cùng: struct con. Thứ tự này có chủ đích — báo lỗi ở tầng cụ thể nhất trước, để thông báo
|
|
// nói đúng khoá YAML mà người vận hành cần sửa, chứ không phải một ràng buộc phái sinh.
|
|
//
|
|
// Lưu ý 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. Bên gọi phải điền nó trước khi gọi hàm này —
|
|
// xem @ref MoveBase2Config::validate trong header.
|
|
if (!state_machine.validate(error))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
std::string MoveBase2Config::describe() const
|
|
{
|
|
std::ostringstream out;
|
|
out << "move_base2 config:\n";
|
|
out << " controller_frequency: " << controller_frequency << " Hz\n";
|
|
out << " planner_frequency: " << planner_frequency << " Hz\n";
|
|
out << " planner_timeout: " << planner_timeout << " s\n";
|
|
out << " runtime_stats_period: " << runtime_stats_period << " s"
|
|
<< (runtime_stats_period > 0.0 ? "\n" : " (off)\n");
|
|
out << " frames: global='" << global_frame << "' base='" << robot_base_frame << "'\n";
|
|
out << " require_current_costmap: " << (require_current_costmap ? "true" : "false") << "\n";
|
|
out << " namespaces: recovery='" << recovery_namespace << "' actions='" << action_namespace
|
|
<< "' mission='" << mission_namespace << "'\n";
|
|
out << " mission_layer_enabled: " << (mission_layer_enabled ? "true" : "false")
|
|
<< (mission_layer_enabled ? " (orders are split into legs)\n"
|
|
: " (orders go straight down as one goal)\n");
|
|
describeBinding(out, "position", position);
|
|
describeBinding(out, "docking", docking);
|
|
for (const auto& entry : docking_marker_profiles)
|
|
{
|
|
describeBinding(out, ("docking marker '" + entry.first + "'").c_str(), entry.second);
|
|
}
|
|
out << " docking_requires_marker: " << (docking_requires_marker ? "true" : "false") << '\n';
|
|
describeBinding(out, "go_straight", go_straight);
|
|
describeBinding(out, "rotate", rotate);
|
|
out << " backup_global_planner: '" << backup_global_planner_name << "'"
|
|
<< (backup_global_planner_name.empty() ? " (off)\n" : "\n");
|
|
out << " debug: state=" << (debug_state ? "on" : "off")
|
|
<< " plan=" << (debug_plan ? "on" : "off")
|
|
<< " skip=" << (debug_skip ? "on" : "off") << "\n";
|
|
out << state_machine.describe();
|
|
out << velocity.describe();
|
|
out << sensors.describe();
|
|
out << " sensor_store: " << sensor_store.sensors.size() << " topic(s)"
|
|
<< (sensor_store.sensors.empty() ? " (off)" : "") << ", report_period: "
|
|
<< sensor_store_report_period << " s" << (sensor_store_report_period > 0.0 ? "\n" : " (off)\n");
|
|
for (const robot_sensor_ports::SensorEntryConfig& entry : sensor_store.sensors)
|
|
{
|
|
out << " '" << entry.topic << "' " << entry.data_type << " capacity=" << entry.capacity
|
|
<< " max_age=" << entry.max_age << " s\n";
|
|
}
|
|
return out.str();
|
|
}
|
|
|
|
|
|
// ================================================================================================
|
|
// Đọc theo schema gen-1
|
|
// ================================================================================================
|
|
|
|
void MoveBase2Config::fromLegacyNodeHandle(robot::NodeHandle& nh)
|
|
{
|
|
// Schema gen-1 dùng base_footprint; giữ frame cũ để không đổi hành vi của hệ đang chạy.
|
|
robot_base_frame = "base_footprint";
|
|
|
|
readDouble(nh, "controller_frequency", controller_frequency);
|
|
readDouble(nh, "planner_frequency", planner_frequency);
|
|
// Khoá này không có trong schema gen-1 — nó là công cụ chẩn đoán của move_base2. Vẫn đọc ở đây
|
|
// để bật được telemetry mà không phải chuyển cả cây config sang schema mới.
|
|
readDouble(nh, "runtime_stats_period", runtime_stats_period);
|
|
readDouble(nh, "planner_patience", state_machine.planner_patience);
|
|
readDouble(nh, "controller_patience", state_machine.controller_patience);
|
|
readDouble(nh, "sensor_patience", state_machine.sensor_patience);
|
|
readDouble(nh, "oscillation_timeout", state_machine.oscillation_timeout);
|
|
readDouble(nh, "oscillation_distance", state_machine.oscillation_distance);
|
|
readInt(nh, "max_planning_retries", state_machine.max_planning_retries);
|
|
readBool(nh, "recovery_behavior_enabled", state_machine.recovery_enabled);
|
|
|
|
readString(nh, "global_frame", global_frame);
|
|
readString(nh, "robot_base_frame", robot_base_frame);
|
|
// Không có trong schema gen-1 (bản cũ hard-code guard này, không cho tắt) — đọc để có đường tắt
|
|
// khi observation buffer bị cấu hình sai, mặc định vẫn là bật.
|
|
readBool(nh, "require_current_costmap", require_current_costmap);
|
|
|
|
// Cũng không có trong schema gen-1: gen-1 không có mission layer nên không có khoá tương ứng để
|
|
// dịch. Đọc ở đây để tắt/bật được ngay trên cây config đang chạy mà không phải chuyển schema —
|
|
// đây là đường lùi khi mission layer gây vấn đề trên hiện trường.
|
|
readBool(nh, "mission_layer_enabled", mission_layer_enabled);
|
|
readString(nh, "mission_namespace", mission_namespace);
|
|
readBool(nh, "docking_requires_marker", docking_requires_marker);
|
|
|
|
std::string root_global_planner;
|
|
readString(nh, "base_global_planner", root_global_planner);
|
|
|
|
if (nh.hasParam("base_local_planner"))
|
|
{
|
|
std::string adapter;
|
|
nh.param("base_local_planner", adapter, adapter);
|
|
// `LocalPlannerAdapter` 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 nên không cần cầu đó — bỏ qua CÓ LOG, để không ai tưởng
|
|
// khoá này vẫn đang có hiệu lực.
|
|
robot::log_warning("[move_base2] schema gen-1: ignoring base_local_planner='%s' — move_base2 "
|
|
"calls the local planner directly, not through an adapter.",
|
|
adapter.c_str());
|
|
}
|
|
|
|
struct LegacyProfile
|
|
{
|
|
const char* key;
|
|
ProfileBinding* binding;
|
|
};
|
|
const LegacyProfile profiles[] = {
|
|
{ "position_planner_name", &position },
|
|
{ "docking_planner_name", &docking },
|
|
{ "go_straight_planner_name", &go_straight },
|
|
{ "rotate_planner_name", &rotate },
|
|
};
|
|
|
|
for (const LegacyProfile& profile : profiles)
|
|
{
|
|
if (!nh.hasParam(profile.key))
|
|
{
|
|
robot::log_warning("[move_base2] schema gen-1: missing '%s', this profile will reject every "
|
|
"request",
|
|
profile.key);
|
|
continue;
|
|
}
|
|
|
|
std::string local_planner;
|
|
nh.param(profile.key, local_planner, local_planner);
|
|
profile.binding->local_planner_name = local_planner;
|
|
|
|
// Global planner riêng của profile nằm trong namespace mang tên chính planner đó; thiếu thì
|
|
// rơi về khoá ở root. Đúng cách bản cũ tra (`NodeHandle(private_nh_, position_planner_name_)`).
|
|
profile.binding->global_planner_name = root_global_planner;
|
|
if (!local_planner.empty())
|
|
{
|
|
robot::NodeHandle planner_nh(nh, local_planner);
|
|
if (planner_nh.hasParam("base_global_planner"))
|
|
{
|
|
std::string profile_global;
|
|
planner_nh.param("base_global_planner", profile_global, profile_global);
|
|
profile.binding->global_planner_name = profile_global;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dịch tường minh khác biệt NGỮ NGHĨA của patience. Gen-1: 0 nghĩa là "fail -> recovery NGAY"
|
|
// (mốc + 0 luôn ở quá khứ). Gen-2: 0 nghĩa là "tắt đồng hồ" — ngược hẳn. 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.
|
|
const double one_cycle = controller_frequency > 0.0 ? 1.0 / controller_frequency : 0.05; // [s]
|
|
if (state_machine.planner_patience <= 0.0)
|
|
{
|
|
robot::log_warning("[move_base2] schema gen-1: planner_patience <= 0 is translated into %.3f s "
|
|
"(one control cycle), not into 'off'.", one_cycle);
|
|
state_machine.planner_patience = one_cycle;
|
|
}
|
|
if (state_machine.controller_patience <= 0.0)
|
|
{
|
|
robot::log_warning("[move_base2] schema gen-1: controller_patience <= 0 is translated into "
|
|
"%.3f s (one control cycle), not into 'off'.", one_cycle);
|
|
state_machine.controller_patience = one_cycle;
|
|
}
|
|
}
|
|
|
|
MoveBase2Config MoveBase2Config::load(robot::NodeHandle& root_nh)
|
|
{
|
|
MoveBase2Config config;
|
|
|
|
// Nhận diện schema bằng một khoá bắt buộc phải có ở cả hai. KHÔNG trộn từng khoá giữa hai schema:
|
|
// 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" mà hai cây
|
|
// config trùng tên của workspace này đã gây ra một lần.
|
|
robot::NodeHandle modern_nh(root_nh, "move_base2");
|
|
if (modern_nh.hasParam("controller_frequency"))
|
|
{
|
|
robot::log_info("[move_base2] using the new schema (namespace 'move_base2').");
|
|
config.fromNodeHandle(modern_nh);
|
|
return config;
|
|
}
|
|
|
|
robot::NodeHandle position_nh(root_nh, "position");
|
|
if (position_nh.hasParam("local_planner"))
|
|
{
|
|
robot::log_info("[move_base2] using the root profile schema.");
|
|
config.fromRootProfileNodeHandle(root_nh);
|
|
return config;
|
|
}
|
|
|
|
if (root_nh.hasParam("controller_frequency") || root_nh.hasParam("base_global_planner"))
|
|
{
|
|
robot::log_warning("[move_base2] namespace 'move_base2' not found; reading the gen-1 schema of "
|
|
"move_base_common_params.yaml.");
|
|
config.fromLegacyNodeHandle(root_nh);
|
|
return config;
|
|
}
|
|
|
|
robot::log_error("[move_base2] no configuration found — running with all default values. Check "
|
|
"PNKX_NAV_CORE_CONFIG_DIR and that the config file exists.");
|
|
return config;
|
|
}
|
|
|
|
ControlLoopConfig MoveBase2Config::toControlLoopConfig() const
|
|
{
|
|
ControlLoopConfig config;
|
|
config.debug_state = debug_state;
|
|
config.debug_plan = debug_plan;
|
|
config.debug_skip = debug_skip;
|
|
config.state_machine = state_machine;
|
|
config.velocity = velocity;
|
|
config.nominal_control_period =
|
|
controller_frequency > 0.0 ? 1.0 / controller_frequency : 0.05; // [s]
|
|
config.planner_frequency = planner_frequency; // [Hz] replan nền khi kControlling
|
|
config.robot_base_frame = robot_base_frame;
|
|
config.require_current_costmap = require_current_costmap;
|
|
config.position = position;
|
|
config.docking = docking;
|
|
config.docking_marker_profiles = docking_marker_profiles;
|
|
config.go_straight = go_straight;
|
|
config.rotate = rotate;
|
|
config.backup_global_planner_name = backup_global_planner_name;
|
|
config.docking_requires_marker = docking_requires_marker;
|
|
config.path_monitor = path_monitor;
|
|
config.env_monitor = env_monitor;
|
|
config.env_sampling = env_sampling;
|
|
config.env_logger = env_logger;
|
|
config.debug_env = debug_env;
|
|
return config;
|
|
}
|
|
|
|
} // namespace move_base2
|