红绿灯信号,增加了黄灯
This commit is contained in:
parent
6ac931e802
commit
61b50c3bc0
@ -74,7 +74,7 @@
|
||||
| vehicleID | string | 是 | 车辆 ID |
|
||||
| commandType | string | 是 | 指令类型:ALERT:告警指令,SIGNAL:信号灯指令,WARNING:预警指令,RESUME:恢复指令 |
|
||||
| commandReason | string | 是 | 指令原因:TRAFFIC_LIGHT:红绿灯控制,AIRCRAFT_CROSSING:航空器交叉,SPECIAL_VEHICLE:特勤车辆,AIRCRAFT_PUSH:航空器推出,RESUME_TRAFFIC:恢复通行 |
|
||||
| signalState | string | 否 | 信号灯状态(仅当 commandType 为 SIGNAL 时有效)RED:红灯,GREEN:绿灯 |
|
||||
| signalState | string | 否 | 信号灯状态(仅当 commandType 为 SIGNAL 时有效)RED:红灯,GREEN:绿灯,YELLOW:黄灯 |
|
||||
| intersectionId | string | 否 | 路口 ID(仅当 commandType 为 SIGNAL 时有效) |
|
||||
| latitude | double | 是 | 目标位置纬度(路口/航空器/特勤车) |
|
||||
| longitude | double | 是 | 目标位置经度(路口/航空器/特勤车) |
|
||||
|
||||
@ -30,10 +30,13 @@ void TrafficLightDetector::processSignal(const TrafficLightSignal& signal,
|
||||
// 根据信号灯状态发送指令
|
||||
switch (signal.status) {
|
||||
case SignalStatus::RED:
|
||||
sendStopCommand(vehicle.vehicleNo);
|
||||
sendSignalCommand(vehicle.vehicleNo, SignalState::RED);
|
||||
break;
|
||||
case SignalStatus::GREEN:
|
||||
sendContinueCommand(vehicle.vehicleNo);
|
||||
sendSignalCommand(vehicle.vehicleNo, SignalState::GREEN);
|
||||
break;
|
||||
case SignalStatus::YELLOW:
|
||||
sendSignalCommand(vehicle.vehicleNo, SignalState::YELLOW);
|
||||
break;
|
||||
default:
|
||||
Logger::warning("未知的信号灯状态");
|
||||
@ -43,12 +46,12 @@ void TrafficLightDetector::processSignal(const TrafficLightSignal& signal,
|
||||
}
|
||||
}
|
||||
|
||||
void TrafficLightDetector::sendStopCommand(const std::string& vehicleNo) {
|
||||
void TrafficLightDetector::sendSignalCommand(const std::string& vehicleNo, SignalState state) {
|
||||
VehicleCommand cmd;
|
||||
cmd.vehicleId = vehicleNo;
|
||||
cmd.type = CommandType::SIGNAL;
|
||||
cmd.reason = CommandReason::TRAFFIC_LIGHT;
|
||||
cmd.signalState = SignalState::RED;
|
||||
cmd.signalState = state;
|
||||
cmd.timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
@ -62,27 +65,7 @@ void TrafficLightDetector::sendStopCommand(const std::string& vehicleNo) {
|
||||
|
||||
controllable_vehicles_.sendCommand(vehicleNo, cmd);
|
||||
system_.broadcastVehicleCommand(cmd);
|
||||
Logger::debug("发送停止指令到车辆: ", vehicleNo, " 路口: ", cmd.intersectionId);
|
||||
}
|
||||
|
||||
void TrafficLightDetector::sendContinueCommand(const std::string& vehicleNo) {
|
||||
VehicleCommand cmd;
|
||||
cmd.vehicleId = vehicleNo;
|
||||
cmd.type = CommandType::SIGNAL;
|
||||
cmd.reason = CommandReason::TRAFFIC_LIGHT;
|
||||
cmd.signalState = SignalState::GREEN;
|
||||
cmd.timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
// 添加路口信息
|
||||
const Intersection* intersection = intersection_config_.findByTrafficLightId(current_signal_.trafficLightId);
|
||||
if (intersection) {
|
||||
cmd.intersectionId = intersection->id;
|
||||
cmd.latitude = intersection->position.latitude;
|
||||
cmd.longitude = intersection->position.longitude;
|
||||
}
|
||||
|
||||
controllable_vehicles_.sendCommand(vehicleNo, cmd);
|
||||
system_.broadcastVehicleCommand(cmd);
|
||||
Logger::debug("发送继续指令到车辆: ", vehicleNo, " 路口: ", cmd.intersectionId);
|
||||
Logger::debug("发送信号灯指令到车辆: ", vehicleNo,
|
||||
" 路口: ", cmd.intersectionId,
|
||||
" 状态: ", state == SignalState::RED ? "红灯" : state == SignalState::GREEN ? "绿灯" : "黄灯");
|
||||
}
|
||||
@ -1,13 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "types/TrafficLightTypes.h"
|
||||
#include "types/VehicleCommand.h"
|
||||
#include "config/IntersectionConfig.h"
|
||||
#include "vehicle/ControllableVehicles.h"
|
||||
#include <optional>
|
||||
#include "types/TrafficLightTypes.h"
|
||||
#include <vector>
|
||||
|
||||
// 前向声明
|
||||
class System;
|
||||
|
||||
class TrafficLightDetector {
|
||||
@ -16,25 +13,15 @@ public:
|
||||
const ControllableVehicles& controllableVehicles,
|
||||
System& system);
|
||||
|
||||
// 处理红绿灯信号
|
||||
void processSignal(const TrafficLightSignal& signal, const std::vector<Vehicle>& vehicles);
|
||||
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_; // 当前处理的信号
|
||||
TrafficLightSignal current_signal_;
|
||||
|
||||
// 发送信号灯指令
|
||||
void sendSignalCommand(const std::string& vehicleNo, SignalState state);
|
||||
};
|
||||
@ -6,6 +6,7 @@
|
||||
enum class SignalStatus {
|
||||
RED,
|
||||
GREEN,
|
||||
YELLOW,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
@ -20,6 +21,7 @@ struct TrafficLightSignal {
|
||||
static SignalStatus parseStatus(const std::string& status) {
|
||||
if (status == "red") return SignalStatus::RED;
|
||||
if (status == "green") return SignalStatus::GREEN;
|
||||
if (status == "yellow") return SignalStatus::YELLOW;
|
||||
return SignalStatus::UNKNOWN;
|
||||
}
|
||||
};
|
||||
@ -15,7 +15,8 @@ enum class CommandType {
|
||||
// 信号灯状态
|
||||
enum class SignalState {
|
||||
RED, // 红灯
|
||||
GREEN // 绿灯
|
||||
GREEN, // 绿灯
|
||||
YELLOW // 黄灯
|
||||
};
|
||||
|
||||
// 指令原因
|
||||
|
||||
Loading…
Reference in New Issue
Block a user