车辆段逻辑

This commit is contained in:
Jade 2021-12-06 16:15:12 +08:00
parent 05e0eedb34
commit 7254a02356
9 changed files with 113 additions and 64 deletions

View File

@ -50,7 +50,7 @@ public class TrainOperateHandler {
SimulationDataRepository repository = simulation.getRepository(); SimulationDataRepository repository = simulation.getRepository();
List<VirtualRealityTrain> onlineTrainList = repository.getOnlineTrainList(); List<VirtualRealityTrain> onlineTrainList = repository.getOnlineTrainList();
VirtualRealityTrain train = repository VirtualRealityTrain train = repository
.getTrain(serviceNumber, tripNumber); .getTrain(simulation, serviceNumber, tripNumber);
for (VirtualRealityTrain online : onlineTrainList) { for (VirtualRealityTrain online : onlineTrainList) {
if (Objects.equals(train, online)) { if (Objects.equals(train, online)) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,

View File

@ -510,7 +510,10 @@ public class AtsTrainLoadService {
SimulationDataRepository repository = simulation.getRepository(); SimulationDataRepository repository = simulation.getRepository();
for (VirtualRealityTrain train : loadedList) { for (VirtualRealityTrain train : loadedList) {
// 构建监控列车信息 // 构建监控列车信息
TrainInfo trainInfo = new TrainInfo(train.getGroupNumber()); TrainInfo trainInfo = simulation.getRepository().getTrainInfoMap().get(train.getGroupNumber());
if (trainInfo == null) {
trainInfo = new TrainInfo(train.getGroupNumber());
}
TripPlan tripPlan = repository.getTripPlan(train.getServiceNumber(), train.getTripNumber()); TripPlan tripPlan = repository.getTripPlan(train.getServiceNumber(), train.getTripNumber());
trainInfo.init(tripPlan, repository.getConfig()); trainInfo.init(tripPlan, repository.getConfig());
List<StationPlan> stationPlanList = tripPlan.getPlanList(); List<StationPlan> stationPlanList = tripPlan.getPlanList();
@ -739,7 +742,7 @@ public class AtsTrainLoadService {
break; break;
} }
TripPlan tripPlan = trainLoadParam2.getTripPlan(); TripPlan tripPlan = trainLoadParam2.getTripPlan();
VirtualRealityTrain train = repository.getTrain(tripPlan.getServiceNumber(), tripPlan.getTripNumber()); VirtualRealityTrain train = repository.getTrain(simulation, tripPlan.getServiceNumber(), tripPlan.getTripNumber());
if (loadedTrainList.contains(train)) { if (loadedTrainList.contains(train)) {
throw new SimulationException(SimulationExceptionType.System_Fault, throw new SimulationException(SimulationExceptionType.System_Fault,
String.format("加载计划[%s|%s|%s]和[%s|%s|%s]使用列车重复", String.format("加载计划[%s|%s|%s]和[%s|%s|%s]使用列车重复",

View File

@ -14,15 +14,18 @@ import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO; import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO;
import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService; import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.depot.DepotLoadService; import club.joylink.rtss.simulation.cbtc.depot.DepotService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop; import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService; import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService;
import club.joylink.rtss.simulation.cbtc.event.*; import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationErrorEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationPauseEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationResumeEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationRunPlanReloadEvent;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.fault.FaultGenerator; import club.joylink.rtss.simulation.cbtc.fault.FaultGenerator;
@ -31,10 +34,6 @@ import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPLogicLoop;
import club.joylink.rtss.simulation.cbtc.onboard.TrainTargetUpdateService; import club.joylink.rtss.simulation.cbtc.onboard.TrainTargetUpdateService;
import club.joylink.rtss.simulation.cbtc.robot.RobotLogicLoop; import club.joylink.rtss.simulation.cbtc.robot.RobotLogicLoop;
import club.joylink.rtss.simulation.rt.iscs.IscsStatusPublisher; import club.joylink.rtss.simulation.rt.iscs.IscsStatusPublisher;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.ibp.IbpData;
import club.joylink.rtss.vo.client.ibp.IbpQueryVO;
import club.joylink.rtss.vo.client.ibp.IbpVO;
import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO;
import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -112,7 +111,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
private IbpService ibpService; private IbpService ibpService;
@Autowired @Autowired
private DepotLoadService depotLoadService; private DepotService depotService;
@Override @Override
public Simulation create(SimulationBuildParams params, String group) { public Simulation create(SimulationBuildParams params, String group) {
@ -126,7 +125,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
simulation.addMessagePublisher(new IscsStatusPublisher(simulation)); simulation.addMessagePublisher(new IscsStatusPublisher(simulation));
// 初始化设备状态 // 初始化设备状态
this.deviceStatusService.init(simulation); this.deviceStatusService.init(simulation);
depotLoadService.loadDepotTrain(simulation); depotService.loadDepotTrain(simulation);
// 初始化成员 // 初始化成员
this.memberManager.init(simulation); this.memberManager.init(simulation);
// 初始化语音指令 // 初始化语音指令
@ -141,6 +140,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
private void addJobs(Simulation simulation) { private void addJobs(Simulation simulation) {
atsLogicLoop.addJobs(simulation); atsLogicLoop.addJobs(simulation);
atpLogicLoop.addJobs(simulation); atpLogicLoop.addJobs(simulation);
depotService.addJobs(simulation);
trainTargetUpdateService.addJobs(simulation); trainTargetUpdateService.addJobs(simulation);
vrTrainRunningService.addJobs(simulation); vrTrainRunningService.addJobs(simulation);
this.ciLogic.addJobs(simulation); this.ciLogic.addJobs(simulation);
@ -220,7 +220,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
// } // }
// 初始化设备状态 // 初始化设备状态
this.deviceStatusService.init(simulation); this.deviceStatusService.init(simulation);
depotLoadService.loadDepotTrain(simulation); depotService.loadDepotTrain(simulation);
// Map<String, SimulationMember> oldMemberMap = simulation.getMemberMap(); // Map<String, SimulationMember> oldMemberMap = simulation.getMemberMap();
// Simulation build = SimulationBuilder.build(simulation.getBuildParams()); // Simulation build = SimulationBuilder.build(simulation.getBuildParams());
// simulation.resetFrom(build); // simulation.resetFrom(build);

View File

@ -78,9 +78,7 @@ public class SchedulingBuilder {
SchedulingTrainPlan schedulingTrainPlan = schedulingPlanList.get(i); SchedulingTrainPlan schedulingTrainPlan = schedulingPlanList.get(i);
String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber(); String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber();
VirtualRealityTrain train = serverTrainMap.get(serviceNumber); VirtualRealityTrain train = serverTrainMap.get(serviceNumber);
if (Objects.nonNull(train)) { if (Objects.isNull(train)) {
schedulingTrainPlan.setGroupNumber(train.getGroupNumber());
} else {
train = trainQueue.poll(); train = trainQueue.poll();
serverTrainMap.put(serviceNumber, train); serverTrainMap.put(serviceNumber, train);
} }

View File

@ -105,6 +105,9 @@ public interface SimulationConstants {
*/ */
int ROUTE_SETTING_TIMEOUT = 20; int ROUTE_SETTING_TIMEOUT = 20;
/** 停车场/车辆段循环逻辑频率单位ms */
int DEPOT_LOOP_RATE = 1000;
/** /**
* 获取仿真运行计划日期运营日 * 获取仿真运行计划日期运营日
* @return * @return

View File

@ -43,6 +43,8 @@ public enum SimulationModule {
DRIVE_POSITION(SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE), DRIVE_POSITION(SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE),
/** 剧本演出模块 */ /** 剧本演出模块 */
SCRIPT(SimulationConstants.SCRIPT_LOOP_RATE), SCRIPT(SimulationConstants.SCRIPT_LOOP_RATE),
/** 停车场/车辆段模块 */
DEPOT(SimulationConstants.DEPOT_LOOP_RATE),
/** 故障模块 */ /** 故障模块 */
FAULT(SimulationConstants.FAULT_GENERATE_RATE), FAULT(SimulationConstants.FAULT_GENERATE_RATE),

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.data;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.communication.vo.TrainHmiDisplay; import club.joylink.rtss.simulation.cbtc.communication.vo.TrainHmiDisplay;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; import club.joylink.rtss.simulation.cbtc.data.plan.RealRun;
@ -586,12 +587,13 @@ public class SimulationDataRepository {
return this.serviceTripsMap.get(serviceNumber); return this.serviceTripsMap.get(serviceNumber);
} }
public VirtualRealityTrain getTrain(String serviceNumber, String tripNumber) { public VirtualRealityTrain getTrain(Simulation simulation, String serviceNumber, String tripNumber) {
VirtualRealityTrain train = this.queryTrain(serviceNumber, tripNumber); VirtualRealityTrain train = this.queryTrain(serviceNumber, tripNumber);
if (Objects.isNull(train)) { if (Objects.isNull(train)) {
throw new SimulationException(SimulationExceptionType.System_Fault, throw new SimulationException(SimulationExceptionType.System_Fault,
String.format("服务车次[%s|%s]找不到派班的列车", serviceNumber, tripNumber)); String.format("服务车次[%s|%s]找不到派班的列车", serviceNumber, tripNumber));
} else if (this.usedTrainMap.containsKey(train.getGroupNumber())) { } else if (!simulation.getRepository().getConfig().isHandleDepot()
&& this.usedTrainMap.containsKey(train.getGroupNumber())) {
throw new SimulationException(SimulationExceptionType.System_Fault, throw new SimulationException(SimulationExceptionType.System_Fault,
String.format("列车[%s]已经被使用", train.getGroupNumber())); String.format("列车[%s]已经被使用", train.getGroupNumber()));
} }

View File

@ -1,45 +0,0 @@
package club.joylink.rtss.simulation.cbtc.depot;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import org.springframework.stereotype.Component;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Component
public class DepotLoadService {
public void loadDepotTrain(Simulation simulation) {
if (!simulation.getRepository().getConfig().isHandleDepot()) {
return;
}
Map<Station, List<Section>> parkingTracksMap = simulation.getRepository().getParkingTracksMap();
simulation.getRepository().getAllVrTrain().stream()
.collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation))
.forEach((station, trainList) -> {
List<Section> sections = parkingTracksMap.get(station);
// 先加载内侧的停车轨
sections.sort(Comparator.comparing(section ->
Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection())));
boolean right = sections.get(sections.size() - 1).getLeftSection() == null;
for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) {
VirtualRealityTrain train = trainList.get(i);
Section section = sections.get(i);
train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right);
train.parkingAt(section);
TrainInfo trainInfo = TrainInfo.constructManualTrain(train);
trainInfo.tracking(train);
simulation.getRepository().addOnlineTrain(train);
simulation.getRepository().addTrainInfo(trainInfo);
}
});
}
}

View File

@ -0,0 +1,86 @@
package club.joylink.rtss.simulation.cbtc.depot;
import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.CommandBO;
import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan;
import club.joylink.rtss.simulation.cbtc.data.support.RoutePath;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Component
public class DepotService {
@Autowired
private CiRouteService ciRouteService;
@Autowired
private GroupSimulationService groupSimulationService;
public void loadDepotTrain(Simulation simulation) {
if (!simulation.getRepository().getConfig().isHandleDepot()) {
return;
}
Map<Station, List<Section>> parkingTracksMap = simulation.getRepository().getParkingTracksMap();
simulation.getRepository().getAllVrTrain().stream()
.collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation))
.forEach((station, trainList) -> {
List<Section> sections = parkingTracksMap.get(station);
// 先加载内侧的停车轨
sections.sort(Comparator.comparing(section ->
Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection())));
boolean right = sections.get(sections.size() - 1).getLeftSection() == null;
for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) {
VirtualRealityTrain train = trainList.get(i);
Section section = sections.get(i);
train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right);
train.parkingAt(section);
train.initAsRM();
TrainInfo trainInfo = TrainInfo.constructManualTrain(train);
trainInfo.tracking(train);
simulation.getRepository().addOnlineTrain(train);
simulation.getRepository().addTrainInfo(trainInfo);
}
});
}
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.DEPOT.name(), () -> this.run(simulation), SimulationConstants.DEPOT_LOOP_RATE);
}
private void run(Simulation simulation) {
SchedulingTrainPlan schedulingTrainPlan = simulation.getRepository().getSchedulingTrainPlanList().get(0);
LocalDateTime systemTime = simulation.getSystemTime();
if (!schedulingTrainPlan.getOutDepotTrip().getStartTime().plusMinutes(20).isAfter(systemTime.toLocalTime())) {
return;
}
String groupNumber = schedulingTrainPlan.getGroupNumber();
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class);
List<RoutePath> routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection());
RoutePath routePath = routePaths.get(0);
for (Route route : routePath.getRouteList()) {
ciRouteService.setRoute(simulation, route);
}
CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Drive_To, schedulingTrainPlan.getDriverCode(), null);
List<SimulationMember> memberList = simulation.getSimulationMembersByDevice(train);
groupSimulationService.command(simulation, commandInitiateVO, memberList.get(0));
}
}