You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.1 KiB
106 lines
3.1 KiB
#ifndef DEBUG_LOGGER_HPP
|
|
#define DEBUG_LOGGER_HPP
|
|
|
|
#include "busbar_types.hpp"
|
|
#include "busbar_segment.hpp"
|
|
#include <vector>
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <chrono>
|
|
#include <mutex>
|
|
|
|
// 碰撞失败记录
|
|
struct CollisionRecord {
|
|
Point voxel; // 碰撞的体素位置
|
|
Point segment_start; // 段起点
|
|
Point segment_end; // 段终点
|
|
SegmentType segment_type; // 段类型
|
|
std::string failure_reason; // 失败原因
|
|
bool was_relaxed; // 是否使用宽松检测
|
|
bool near_start_platform; // 是否靠近起始平台
|
|
bool near_goal_platform; // 是否靠近终止平台
|
|
};
|
|
|
|
// 搜索状态记录
|
|
struct SearchStateRecord {
|
|
int iteration; // 迭代次数
|
|
Point position; // 当前位置
|
|
float g_cost; // 已知成本
|
|
float h_cost; // 启发式成本
|
|
float f_cost; // 总成本
|
|
int successors_generated; // 生成的后继数
|
|
int successors_valid; // 有效的后继数
|
|
SegmentType last_segment_type; // 上一段类型
|
|
};
|
|
|
|
class DebugLogger {
|
|
private:
|
|
bool enabled_;
|
|
std::string output_dir_;
|
|
|
|
std::vector<CollisionRecord> collision_records_;
|
|
std::vector<SearchStateRecord> search_records_;
|
|
std::vector<Point> explored_positions_;
|
|
std::vector<Point> collision_positions_;
|
|
|
|
Point start_pos_;
|
|
Point goal_pos_;
|
|
|
|
mutable std::mutex mutex_; // 线程安全锁
|
|
|
|
public:
|
|
DebugLogger(bool enabled = false, const std::string& output_dir = "debug_output")
|
|
: enabled_(enabled), output_dir_(output_dir) {}
|
|
|
|
void setEnabled(bool enabled) { enabled_ = enabled; }
|
|
bool isEnabled() const { return enabled_; }
|
|
|
|
void setStartGoal(const Point& start, const Point& goal) {
|
|
start_pos_ = start;
|
|
goal_pos_ = goal;
|
|
}
|
|
|
|
// 记录碰撞(线程安全)
|
|
void logCollision(const CollisionRecord& record) {
|
|
if (!enabled_) return;
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
collision_records_.push_back(record);
|
|
collision_positions_.push_back(record.voxel);
|
|
}
|
|
|
|
// 记录搜索状态(线程安全)
|
|
void logSearchState(const SearchStateRecord& record) {
|
|
if (!enabled_) return;
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
search_records_.push_back(record);
|
|
explored_positions_.push_back(record.position);
|
|
}
|
|
|
|
// 导出所有调试信息
|
|
void exportAll() {
|
|
if (!enabled_) return;
|
|
|
|
exportCollisionLog();
|
|
exportSearchLog();
|
|
exportVisualization();
|
|
exportSummary();
|
|
}
|
|
|
|
void clear() {
|
|
collision_records_.clear();
|
|
search_records_.clear();
|
|
explored_positions_.clear();
|
|
collision_positions_.clear();
|
|
}
|
|
|
|
private:
|
|
void exportCollisionLog();
|
|
void exportSearchLog();
|
|
void exportVisualization();
|
|
void exportSummary();
|
|
};
|
|
|
|
// 全局调试器实例
|
|
extern DebugLogger g_debug_logger;
|
|
|
|
#endif
|