40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include "types/TrafficLightTypes.h"
|
|
#include "types/VehicleCommand.h"
|
|
#include "config/IntersectionConfig.h"
|
|
#include "vehicle/ControllableVehicles.h"
|
|
#include <optional>
|
|
|
|
// 前向声明
|
|
class System;
|
|
|
|
class TrafficLightDetector {
|
|
public:
|
|
TrafficLightDetector(const IntersectionConfig& intersectionConfig,
|
|
const ControllableVehicles& controllableVehicles,
|
|
System& system);
|
|
|
|
// 处理红绿灯信号
|
|
void processSignal(const TrafficLightSignal& signal, const std::vector<Vehicle>& vehicles);
|
|
|
|
private:
|
|
// 发送车辆控制指令
|
|
void sendStopCommand(const std::string& vehicleId);
|
|
void sendContinueCommand(const std::string& vehicleId);
|
|
|
|
// 获取当前车辆的指令状态
|
|
std::optional<VehicleCommand> getCurrentCommand(const std::string& vehicleId) const;
|
|
|
|
// 检查是否可以发送绿灯继续指令
|
|
bool canSendContinueCommand(const std::string& vehicleId) const;
|
|
|
|
// 获取指令的优先级
|
|
static int getCommandPriority(const VehicleCommand& cmd);
|
|
|
|
const IntersectionConfig& intersection_config_;
|
|
const ControllableVehicles& controllable_vehicles_;
|
|
System& system_;
|
|
TrafficLightSignal current_signal_; // 当前处理的信号
|
|
};
|