diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/Operation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/Operation.java index 69e3ec645..58e7f7ef6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/Operation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/Operation.java @@ -317,6 +317,16 @@ public class Operation { */ Signal_Set_Guide, + /** + * 点灯 + */ + Signal_Turn_On, + + /** + * 灭灯 + */ + Signal_Turn_Off, + //--------------------------- 站台操作 --------------------------- /** * 设置跳停 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/SignalOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/SignalOperateHandler.java index 92896ed1d..186547d9a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/SignalOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/SignalOperateHandler.java @@ -316,4 +316,20 @@ public class SignalOperateHandler { ciApiService.setGuide(simulation, signalCode, routeCode); } + /** + * 信号机点灯 + */ + @OperateHandlerMapping(type = Operation.Type.Signal_Turn_On) + public void signalTurnOn(Simulation simulation, String signalCode) { + ciApiService.signalTurnOn(simulation, signalCode); + } + + /** + * 信号机灭灯 + */ + @OperateHandlerMapping(type = Operation.Type.Signal_Turn_Off) + public void signalTurnOff(Simulation simulation, String signalCode) { + ciApiService.signalTurnOff(simulation, signalCode); + } + } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiService.java index 44a6f3a76..44192caf2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiService.java @@ -359,4 +359,8 @@ public interface CiApiService { void switchMasterLock(Simulation simulation, String stationCode, Station.Throat throat); void switchMasterUnlock(Simulation simulation, String stationCode, Station.Throat throat); + + void signalTurnOn(Simulation simulation, String signalCode); + + void signalTurnOff(Simulation simulation, String signalCode); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java index 88bf2126c..667161c8a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java @@ -3,9 +3,12 @@ package club.joylink.rtss.simulation.cbtc.CI; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.CI.device.*; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal; +import club.joylink.rtss.simulation.cbtc.device.virtual.VirtualRealityDeviceService; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import lombok.extern.slf4j.Slf4j; @@ -36,6 +39,9 @@ public class CiApiServiceImpl2 implements CiApiService { private CiService ciService; @Autowired private CiStandService standService; + @Autowired + private VirtualRealityDeviceService virtualRealityDeviceService; + @Override public void blockadeSection(Simulation simulation, String sectionCode) { @@ -692,6 +698,27 @@ public class CiApiServiceImpl2 implements CiApiService { } } + @Override + public void signalTurnOn(Simulation simulation, String signalCode) { + SimulationDataRepository repository = simulation.getRepository(); + Signal signal = repository.getByCode(signalCode, Signal.class); + BusinessExceptionAssertEnum.OPERATION_FAIL.assertNull(signal.getLockedRoute(), "信号机有锁闭进路,禁止点灯"); + VirtualRealitySignal vrSignal = signal.getVirtualSignal(); + BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotNull(vrSignal, signal.debugStr() + "无实体信号机"); + virtualRealityDeviceService.control(simulation, vrSignal, vrSignal.getModel().getDefaultAspect()); + } + + @Override + public void signalTurnOff(Simulation simulation, String signalCode) { + SimulationDataRepository repository = simulation.getRepository(); + Signal signal = repository.getByCode(signalCode, Signal.class); + BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotTrue(signal.isShunting(), "调车信号机无法灭灯"); + BusinessExceptionAssertEnum.OPERATION_FAIL.assertNull(signal.getLockedRoute(), "信号机有锁闭进路,禁止灭灯"); + VirtualRealitySignal vrSignal = signal.getVirtualSignal(); + BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotNull(vrSignal, signal.debugStr() + "无实体信号机"); + virtualRealityDeviceService.control(simulation, vrSignal, SignalAspect.No); + } + /** * 获取计轴器并为预复位/复位操作检查设备状态 */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiSignalControlService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiSignalControlService.java index 40b8cb4ad..e8763c58c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiSignalControlService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiSignalControlService.java @@ -68,16 +68,18 @@ public class CiSignalControlService { * @param signal */ public void controlLightOfSignal(Simulation simulation, Signal signal) { - VirtualRealitySignal vrSignal = signal.getVirtualSignal(); - if (signal.isCbtcMode() && !signal.isForcePhysical() && !signal.isLogicLight()) { - if (vrSignal != null) { - this.virtualRealityDeviceService.control(simulation, vrSignal, SignalAspect.No); - } else { - signal.setLogicLight(true); - } - } else if ((!signal.isCbtcMode() || signal.isForcePhysical()) && signal.isLogicLight()) { - if (vrSignal != null) { - this.virtualRealityDeviceService.control(simulation, vrSignal, vrSignal.getModel().getDefaultAspect()); + if (!simulation.getRepository().getConfig().isRailway()) { + VirtualRealitySignal vrSignal = signal.getVirtualSignal(); + if (signal.isCbtcMode() && !signal.isForcePhysical() && !signal.isLogicLight()) { + if (vrSignal != null) { + this.virtualRealityDeviceService.control(simulation, vrSignal, SignalAspect.No); + } else { + signal.setLogicLight(true); + } + } else if ((!signal.isCbtcMode() || signal.isForcePhysical()) && signal.isLogicLight()) { + if (vrSignal != null) { + this.virtualRealityDeviceService.control(simulation, vrSignal, vrSignal.getModel().getDefaultAspect()); + } } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/DeviceStatusServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/DeviceStatusServiceImpl.java index 883b129fe..2f0d713fb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/DeviceStatusServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/DeviceStatusServiceImpl.java @@ -22,13 +22,13 @@ public class DeviceStatusServiceImpl implements DeviceStatusService { @Override public void init(Simulation simulation) { simulation.reset(); //这个初始化现在不可或缺,有一些数据在仿真构建时没有,仅在初始化时构建 + // 虚拟真实设备初始化 + virtualRealityDeviceService.reset(simulation); // 信号机状态初始化 this.initSignal(simulation); this.buildSingleLockedSwitch(simulation); this.initRoute(simulation); this.initStationControlMode(simulation); - // 虚拟真实设备初始化 - virtualRealityDeviceService.reset(simulation); } /** @@ -54,10 +54,18 @@ public class DeviceStatusServiceImpl implements DeviceStatusService { private void initSignal(Simulation simulation) { SimulationDataRepository repository = simulation.getRepository(); - // 初始化非ctc虚拟真实信号机点红灯 List signalList = repository.getSignalList(); - for (Signal signal : signalList) { - if (!signal.isCtc()) { + if (!repository.getConfig().isRailway()) { + // 初始化非ctc虚拟真实信号机点红灯 + for (Signal signal : signalList) { + if (!signal.isCtc()) { + VirtualRealitySignal vrSignal = repository.getVRByCode(signal.getCode(), VirtualRealitySignal.class); + vrSignal.control(vrSignal.getModel().getDefaultAspect()); + vrSignal.finish(); + } + } + } else { //大铁线路暂时默认点灯 + for (Signal signal : signalList) { VirtualRealitySignal vrSignal = repository.getVRByCode(signal.getCode(), VirtualRealitySignal.class); vrSignal.control(vrSignal.getModel().getDefaultAspect()); vrSignal.finish(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java index b8b332275..a88c40195 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java @@ -621,7 +621,9 @@ public class CommandBO { command.getTargetMember().setCommand(null); return null; } - targetMember.setCommand(null); + if (train.isStop()) { + targetMember.setCommand(null); + } // 设置目标位置 return buildDriveStep(train.getHeadPosition()); } @@ -886,7 +888,8 @@ public class CommandBO { SectionPosition sectionPosition = null; for (int i = 0; i < 30; i++) { - section = section.getNextRunningSectionOf(right); + section = section.findNextRunningSectionBaseRealSwitch(right); + BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotNull(section, "引导信号前方未找到停车位置"); Signal signal = section.getSignalOf(right); if (section.isStandTrack() || section.isTurnBackTrack()) { sectionPosition = new SectionPosition(section, section.getStopPointByDirection(right)); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java index 181343dfd..c37d62cba 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java @@ -27,7 +27,7 @@ public class CalculateService { if (offset < 0) { // 向左 Section leftSection; if (baseReal) { - leftSection = baseSection.getNextRunningSectionBaseRealSwitch(false); + leftSection = baseSection.findNextRunningSectionBaseRealSwitch(false); } else { leftSection = baseSection.getNextRunningSectionOf(false); } @@ -41,7 +41,7 @@ public class CalculateService { } else { // 向右 Section rightSection; if (baseReal) { - rightSection = baseSection.getNextRunningSectionBaseRealSwitch(true); + rightSection = baseSection.findNextRunningSectionBaseRealSwitch(true); } else { rightSection = baseSection.getNextRunningSectionOf(true); } @@ -519,7 +519,7 @@ public class CalculateService { Section section = source; while (!section.getCode().equals(target.getCode()) && loop < 20) { loop++; - Section temp = section.getNextRunningSectionBaseRealSwitch(right); + Section temp = section.findNextRunningSectionBaseRealSwitch(right); if (Objects.nonNull(temp)) { // 不为空 section = temp; occupySectionList.add(section); @@ -628,7 +628,7 @@ public class CalculateService { int count = 0; while (count < 100) { ++count; - Section nextSection = temp.getNextRunningSectionBaseRealSwitch(right); + Section nextSection = temp.findNextRunningSectionBaseRealSwitch(right); if (Objects.equals(nextSection, front)) {// 找到 return true; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java index 507e03897..0192afc2c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java @@ -403,7 +403,7 @@ public class Section extends DelayUnlockDevice { /** * 基于真实道岔找下一个可运行到的区段 */ - public Section getNextRunningSectionBaseRealSwitch(boolean right) { + public Section findNextRunningSectionBaseRealSwitch(boolean right) { if (right && Objects.nonNull(this.rightSection)) { return this.rightSection; } else if (!right && Objects.nonNull(this.leftSection)) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java index cb92c3894..c2c8ad42e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java @@ -847,7 +847,7 @@ public class VirtualRealityTrain extends VirtualRealityDevice { boolean right = this.right; Section section = headPosition.getSection(); for (int i = 0; i < 100; i++) { - section = section.getNextRunningSectionOf(right); + section = section.findNextRunningSectionBaseRealSwitch(right); if (section == null) { break; } @@ -871,7 +871,7 @@ public class VirtualRealityTrain extends VirtualRealityDevice { } for (int i = 0; i < 30; i++) { - Section nextSection = section.getNextRunningSectionBaseRealSwitch(right); + Section nextSection = section.findNextRunningSectionBaseRealSwitch(right); if (nextSection == null) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, String.format("信号机[%s]前方未找到站台轨或折返轨", signal.getName())); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java index 371225033..bb772fa11 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java @@ -49,7 +49,7 @@ public class TrainTargetUpdateService { if (temp == null) break; if (!temp.isFunctionTrack()) { - temp = temp.getNextRunningSectionBaseRealSwitch(right); + temp = temp.findNextRunningSectionBaseRealSwitch(right); continue; } Signal signal = temp.getSignalOf(right); @@ -61,7 +61,7 @@ public class TrainTargetUpdateService { if (temp.isNormalStandTrack() || temp.isTransferTrack()) { if (temp.isNormalStandTrack()) { if (temp.getStandList().stream().anyMatch(stand -> stand.isJumpStop(train.getGroupNumber()))) { //该列车应在站台跳停 - temp = temp.getNextRunningSectionBaseRealSwitch(right); + temp = temp.findNextRunningSectionBaseRealSwitch(right); continue; } } @@ -80,7 +80,7 @@ public class TrainTargetUpdateService { } } } - temp = temp.getNextRunningSectionBaseRealSwitch(right); + temp = temp.findNextRunningSectionBaseRealSwitch(right); } return newTarget; } @@ -115,7 +115,7 @@ public class TrainTargetUpdateService { newTarget = section; } } - section = section.getNextRunningSectionBaseRealSwitch(right); + section = section.findNextRunningSectionBaseRealSwitch(right); if (section == null) { break; } else { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java index a1300d98f..1a4065883 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java @@ -157,7 +157,7 @@ public class RobotLogicLoop { //准备发车 robotReadyForDeparture(simulation, train); //机器人驾驶 - if (train.getRobotTargetPosition() != null) { + if (driver.getCommand() != null) { //如果有和驾驶行为不冲突的指令,这里需要做修改 robotDriveByCommand(simulation, driver, train); } else if (railway) { railRobotDrive(simulation, train); @@ -166,7 +166,7 @@ public class RobotLogicLoop { } /** - * 大铁机器人自动驾驶。 + * 大铁机器人自动驾驶。(目前的驾驶逻辑是针对RM/NRM模式驾驶) * 在确认列车自身状态正确的情况下(车门是关闭状态等),如果是没有计划的车次,则只看信号;如果是有计划的车次,还需要看计划 */ private void railRobotDrive(Simulation simulation, VirtualRealityTrain train) { @@ -208,7 +208,7 @@ public class RobotLogicLoop { } } } - Section next = nextSection.getNextRunningSectionOf(right); + Section next = nextSection.findNextRunningSectionBaseRealSwitch(right); if (next == null) { targetPosition = new SectionPosition(nextSection, right ? nextSection.getLen() - 10 : 10); //轨道尽头10m处 break; @@ -264,7 +264,7 @@ public class RobotLogicLoop { break; } } - nextSection = nextSection.getNextRunningSectionBaseRealSwitch(right); + nextSection = nextSection.findNextRunningSectionBaseRealSwitch(right); if (nextSection == null) break; }