feat: gate the move_base2 diagnostic logs behind config switches
Seven [move_base2][debug] lines printed unconditionally on every cycle. On a
robot running a full shift that is noise: they describe the normal path, and
constant noise buries the one line that is actually abnormal.
Three switches, grouped by what they answer, all defaulting to on so turning
them off is a deliberate act rather than something that changes behind whoever
is relying on the log:
debug/state state machine transitions, printed on change, not per cycle
debug/plan controller accepting or rejecting a plan, recovery paths
debug/skip why the controller was skipped while CONTROLLING
The abort-detail line stays unconditional and loses its [debug] tag. It is the
reason a mission failed and prints once per abort; a config that can silence it
is a config in which the robot fails silently.
The read path runs YAML debug/{state,plan,skip} into MoveBase2Config, which
carries it to ControlLoopConfig. describe() prints the resulting state at boot
so nobody has to guess why a log went quiet.
Nothing computes differently: stripping every log statement from the old and
new control_loop.cpp leaves a three-line difference, and all three are comments.
The gated arguments are pure reads.
This commit is contained in:
@@ -68,6 +68,8 @@ void readBinding(robot::NodeHandle& nh, const std::string& ns, ProfileBinding& b
|
||||
}
|
||||
|
||||
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors);
|
||||
void readDebug(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.
|
||||
@@ -234,6 +236,7 @@ void readMoveBase2Fields(robot::NodeHandle& nh, MoveBase2Config& config)
|
||||
|
||||
readSensors(nh, config.sensors);
|
||||
readSensorStore(nh, config);
|
||||
readDebug(nh, config);
|
||||
readPathMonitor(nh, config.path_monitor);
|
||||
readBool(nh, "docking_requires_marker", config.docking_requires_marker);
|
||||
|
||||
@@ -277,6 +280,15 @@ void readSensorStore(robot::NodeHandle& nh, MoveBase2Config& config)
|
||||
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);
|
||||
}
|
||||
|
||||
/// Đọc cấu hình đường vào cảm biến từ namespace con `sensors`.
|
||||
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors)
|
||||
{
|
||||
@@ -503,6 +515,9 @@ std::string MoveBase2Config::describe() const
|
||||
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();
|
||||
@@ -666,6 +681,9 @@ MoveBase2Config MoveBase2Config::load(robot::NodeHandle& root_nh)
|
||||
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 =
|
||||
|
||||
@@ -831,11 +831,14 @@ bool ControlLoop::step()
|
||||
if (output.state_changed)
|
||||
{
|
||||
last_reason_ = output.reason;
|
||||
robot::log_info("[move_base2][debug] state -> %s: %s "
|
||||
"(planner=%s controller=%s recovery=%s pose=%s active_request=%s).\n",
|
||||
toString(output.state), output.reason != nullptr ? output.reason : "",
|
||||
toString(input.planner), toString(input.controller), toString(input.recovery),
|
||||
pose_available ? "yes" : "no", has_active_request_ ? "yes" : "no");
|
||||
if (config_.debug_state)
|
||||
{
|
||||
robot::log_info("[move_base2][debug] state -> %s: %s "
|
||||
"(planner=%s controller=%s recovery=%s pose=%s active_request=%s).\n",
|
||||
toString(output.state), output.reason != nullptr ? output.reason : "",
|
||||
toString(input.planner), toString(input.controller), toString(input.recovery),
|
||||
pose_available ? "yes" : "no", has_active_request_ ? "yes" : "no");
|
||||
}
|
||||
}
|
||||
|
||||
// Cờ một-lần đã được state machine tiêu thụ xong ở lời gọi trên.
|
||||
@@ -911,13 +914,16 @@ bool ControlLoop::step()
|
||||
{
|
||||
// Controller từ chối plan: coi như lần lập plan này hỏng, để chu kỳ kiên nhẫn tiếp tục chạy.
|
||||
planner_feedback_ = PlannerFeedback::kFailed;
|
||||
robot::log_error("[move_base2][debug] controller rejected plan with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
if (config_.debug_plan)
|
||||
{
|
||||
robot::log_error("[move_base2][debug] controller rejected plan with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -926,13 +932,16 @@ bool ControlLoop::step()
|
||||
last_plan_applied_ = now;
|
||||
has_last_plan_applied_ = true;
|
||||
|
||||
robot::log_info("[move_base2][debug] controller accepted plan with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
if (config_.debug_plan)
|
||||
{
|
||||
robot::log_info("[move_base2][debug] controller accepted plan with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -989,13 +998,16 @@ bool ControlLoop::step()
|
||||
// Họ recovery sinh lại đường đi: coi kết quả như một plan mới, chờ state machine đẩy xuống.
|
||||
latest_plan_ = tick.path;
|
||||
planner_feedback_ = PlannerFeedback::kPlanReady;
|
||||
robot::log_info("[move_base2][debug] recovery produced path with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
if (config_.debug_plan)
|
||||
{
|
||||
robot::log_info("[move_base2][debug] recovery produced path with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1071,22 +1083,28 @@ bool ControlLoop::step()
|
||||
|
||||
if (output.state == NavigationState::kControlling && !pose_available)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller skipped while CONTROLLING: pose unavailable "
|
||||
"(reason=%s, controller_feedback_in=%s, recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.controller),
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
if (config_.debug_skip)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller skipped while CONTROLLING: pose unavailable "
|
||||
"(reason=%s, controller_feedback_in=%s, recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.controller),
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
}
|
||||
}
|
||||
|
||||
if (output.run_controller && costmap_stale)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller skipped while CONTROLLING: costmap stale "
|
||||
"(reason=%s, controller_feedback_in=%s, recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.controller),
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
if (config_.debug_skip)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller skipped while CONTROLLING: costmap stale "
|
||||
"(reason=%s, controller_feedback_in=%s, recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.controller),
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
}
|
||||
}
|
||||
|
||||
if (output.run_controller && !costmap_stale)
|
||||
@@ -1094,14 +1112,17 @@ bool ControlLoop::step()
|
||||
runController(candidate);
|
||||
if (controller_feedback_ == ControllerFeedback::kNoValidCommand)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller returned no valid command "
|
||||
"(reason=%s, planner_in=%s, controller_in=%s, recovery_in=%s, pose=%s, "
|
||||
"recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.planner),
|
||||
toString(input.controller), toString(input.recovery), pose_available ? "yes" : "no",
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
if (config_.debug_skip)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller returned no valid command "
|
||||
"(reason=%s, planner_in=%s, controller_in=%s, recovery_in=%s, pose=%s, "
|
||||
"recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.planner),
|
||||
toString(input.controller), toString(input.recovery), pose_available ? "yes" : "no",
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
}
|
||||
}
|
||||
// else if (controller_feedback_ == ControllerFeedback::kCommandValid)
|
||||
// {
|
||||
@@ -1182,7 +1203,10 @@ bool ControlLoop::step()
|
||||
if (output.reason != nullptr &&
|
||||
std::strcmp(output.reason, "no recovery behavior left") == 0)
|
||||
{
|
||||
robot::log_error("[move_base2][debug] abort detail: recovery route exhausted "
|
||||
// KHÔNG gắn thẻ [debug] và KHÔNG cho tắt: đây là LÝ DO mission hỏng, in đúng một lần
|
||||
// mỗi lần abort. Công tắc `debug/*` dành cho log mô tả đường đi bình thường; tắt được
|
||||
// một dòng lỗi nghĩa là có cấu hình khiến robot hỏng trong im lặng.
|
||||
robot::log_error("[move_base2] abort detail: recovery route exhausted "
|
||||
"(trigger=%s cursor=%zu size=%zu, planner_in=%s, controller_in=%s, "
|
||||
"recovery_in=%s, pose=%s, costmap_current=%s).\n",
|
||||
toString(output.recovery_trigger), output.recovery_route_cursor,
|
||||
|
||||
Reference in New Issue
Block a user