增强兼容性
This commit is contained in:
parent
f708628c22
commit
6676a48c4b
@ -18,7 +18,7 @@ void SystemConfig::load(const std::string& filename) {
|
||||
airport.icao = j["airport"]["icao"];
|
||||
airport.reference_point.latitude = j["airport"]["reference_point"]["latitude"];
|
||||
airport.reference_point.longitude = j["airport"]["reference_point"]["longitude"];
|
||||
airport.coordinate_points = j["airport"]["coordinate_points"].get<std::vector<SystemConfig::Airport::CoordinatePoint>>();
|
||||
airport.coordinate_points = j["airport"]["coordinate_points"].get<std::vector<CoordinatePoint>>();
|
||||
|
||||
// 加载数据源配置
|
||||
data_source.host = j["data_source"]["host"];
|
||||
@ -40,7 +40,7 @@ void SystemConfig::load(const std::string& filename) {
|
||||
// 加载碰撞检测配置
|
||||
collision_detection.update_interval_ms = j["collision_detection"]["update_interval_ms"];
|
||||
|
||||
// 加载碰撞预测配置
|
||||
// 加<EFBFBD><EFBFBD><EFBFBD>碰撞预测配置
|
||||
collision_detection.prediction.time_window = j["collision_detection"]["prediction"]["time_window"];
|
||||
collision_detection.prediction.vehicle_size = j["collision_detection"]["prediction"]["vehicle_size"];
|
||||
collision_detection.prediction.aircraft_size = j["collision_detection"]["prediction"]["aircraft_size"];
|
||||
|
||||
@ -5,6 +5,13 @@
|
||||
|
||||
class System; // 前向声明
|
||||
|
||||
// 前向声明所有需要序列化的结构体
|
||||
struct CoordinatePoint {
|
||||
std::string point;
|
||||
double latitude;
|
||||
double longitude;
|
||||
};
|
||||
|
||||
class SystemConfig {
|
||||
public:
|
||||
// 获取单例实例
|
||||
@ -24,18 +31,12 @@ public:
|
||||
std::string name;
|
||||
std::string iata;
|
||||
std::string icao;
|
||||
struct {
|
||||
struct ReferencePoint {
|
||||
double latitude;
|
||||
double longitude;
|
||||
} reference_point;
|
||||
|
||||
// 定义坐标点结构体
|
||||
struct CoordinatePoint {
|
||||
std::string point;
|
||||
double latitude;
|
||||
double longitude;
|
||||
};
|
||||
|
||||
// 使用前向声明的坐标点结构体
|
||||
std::vector<CoordinatePoint> coordinate_points;
|
||||
} airport;
|
||||
|
||||
@ -96,4 +97,57 @@ private:
|
||||
};
|
||||
|
||||
// JSON 序列化支持
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport::CoordinatePoint, point, latitude, longitude)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CoordinatePoint, point, latitude, longitude);
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport::ReferencePoint, latitude, longitude);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::Airport,
|
||||
name, iata, icao, reference_point, coordinate_points
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::DataSource,
|
||||
host, port, aircraft_path, vehicle_path, traffic_light_path,
|
||||
refresh_interval_ms, timeout_ms, read_timeout_ms
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::WebSocket::PositionUpdate,
|
||||
aircraft_interval_ms, vehicle_interval_ms, traffic_light_interval_ms
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::WebSocket,
|
||||
port, max_connections, ping_interval_ms, position_update
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::CollisionDetection::Prediction,
|
||||
time_window, vehicle_size, aircraft_size, min_unmanned_speed
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::CollisionDetection,
|
||||
update_interval_ms, prediction
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::Logging,
|
||||
level, file, max_size_mb, max_files, console_output
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::Debug,
|
||||
enable_mock_data, save_raw_data, profile_performance
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig::Warning,
|
||||
warning_interval_ms, log_interval_ms
|
||||
);
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
SystemConfig,
|
||||
airport, data_source, websocket, collision_detection,
|
||||
logging, debug, warning
|
||||
);
|
||||
@ -5,6 +5,8 @@
|
||||
#include <cmath>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace collision;
|
||||
|
||||
CollisionDetector::CollisionDetector(const AirportBounds& bounds, const ControllableVehicles& controllableVehicles)
|
||||
: airportBounds_(bounds)
|
||||
, vehicleTree_(bounds.getAirportBounds(), 8) // 使用机场总边界初始化四叉树
|
||||
@ -603,7 +605,7 @@ collision::CollisionResult CollisionDetector::predictCircleBasedCollision(
|
||||
// 3. 相对速度很小(说明速度接近)
|
||||
if (angle_diff < 30.0) {
|
||||
// 计算垂直于运动方向的向距离
|
||||
// 航向角转换为学坐标系中的旋转角度(逆时针为正)
|
||||
// 航向角转换为学坐标系中的<EFBFBD><EFBFBD><EFBFBD>转角度(逆时针为正)
|
||||
double rotation_angle = (90.0 - heading1) * M_PI / 180.0;
|
||||
|
||||
// 使用标准的二维坐标旋转式
|
||||
@ -634,7 +636,7 @@ collision::CollisionResult CollisionDetector::predictCircleBasedCollision(
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 在时间窗口内预测碰撞
|
||||
// 5. <EFBFBD><EFBFBD><EFBFBD>时间窗口内预测碰撞
|
||||
const int STEPS = 120; // 增加采样点数以提高精度
|
||||
double dt = timeWindow / STEPS; // 时间步长
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace collision;
|
||||
|
||||
// 碰撞风险等级
|
||||
enum class RiskLevel {
|
||||
NONE = 0, // 无风险
|
||||
@ -65,7 +67,7 @@ public:
|
||||
std::vector<CollisionRisk> detectCollisions();
|
||||
|
||||
// 统一的碰撞检测函数
|
||||
collision::CollisionResult checkCollision(
|
||||
CollisionResult checkCollision(
|
||||
const MovingObject& obj1,
|
||||
const MovingObject& obj2,
|
||||
double timeWindow = 30.0) const;
|
||||
@ -102,7 +104,7 @@ private:
|
||||
|
||||
// 统一的风险评估函数
|
||||
std::pair<RiskLevel, WarningZoneType> evaluateRisk(
|
||||
const collision::CollisionResult& collisionResult,
|
||||
const CollisionResult& collisionResult,
|
||||
const Vector2D& position,
|
||||
MovingObjectType type1,
|
||||
MovingObjectType type2) const;
|
||||
@ -144,7 +146,7 @@ private:
|
||||
}
|
||||
|
||||
// 基于圆形的碰撞检测核心函数
|
||||
collision::CollisionResult predictCircleBasedCollision(
|
||||
CollisionResult predictCircleBasedCollision(
|
||||
const Vector2D& pos1, double radius1, double speed1, double heading1,
|
||||
const Vector2D& pos2, double radius2, double speed2, double heading2,
|
||||
double timeWindow) const;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
#include "types/BasicTypes.h"
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
namespace collision {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user