From 46acce3f6b79aeb3b0b0968e3dfc85158d9e81f2 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Fri, 10 Dec 2021 11:20:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=A6=8F=E5=B7=9E=E7=BA=BF?= =?UTF-8?q?=E5=88=97=E8=BD=A6=E5=9C=A8=E4=BA=8C=E5=8D=81=E4=B8=80=E7=AB=99?= =?UTF-8?q?=E5=B7=A6=E4=BE=A7=E6=8A=98=E8=BF=94=E8=BD=A8=E5=81=9C=E8=BD=A6?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E6=8F=90=E5=89=8D=E6=9B=B4=E6=8D=A2?= =?UTF-8?q?=E8=BD=A6=E6=AC=A1=E9=97=AE=E9=A2=98=EF=BC=9B=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E9=A9=BE=E9=A9=B6=E5=A2=9E=E5=8A=A0=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA=E5=8A=9F=E8=83=BD=EF=BC=9B=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=BD=A6=E8=BE=86=E6=AE=B5=E7=9A=84=E5=88=97=E8=BD=A6?= =?UTF-8?q?=E4=BB=A5=E5=A4=87=E7=94=A8=E8=BD=A6=E6=96=B9=E5=BC=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=88=B0=E6=AD=A3=E7=BA=BF=E4=B8=8A=E6=97=B6=E5=9B=A0?= =?UTF-8?q?ctc=E7=A7=BB=E5=8A=A8=E6=8E=88=E6=9D=83=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E5=BC=95=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/controller/LoginController.java | 31 ++++-- .../controller/ProjectServerController.java | 12 ++- .../stage/AtsPlanTrainStageService.java | 4 +- .../rtss/simulation/cbtc/data/map/Signal.java | 7 ++ .../cbtc/data/vr/VirtualRealityTrain.java | 1 + .../simulation/cbtc/robot/RobotLogicLoop.java | 95 ++++++++++++------- 6 files changed, 103 insertions(+), 47 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/LoginController.java b/src/main/java/club/joylink/rtss/controller/LoginController.java index 8ca201d68..7b82106f5 100644 --- a/src/main/java/club/joylink/rtss/controller/LoginController.java +++ b/src/main/java/club/joylink/rtss/controller/LoginController.java @@ -1,6 +1,8 @@ package club.joylink.rtss.controller; import club.joylink.rtss.constants.Project; +import club.joylink.rtss.exception.BaseException; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.auth.IAuthenticateService; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; @@ -27,16 +29,23 @@ public class LoginController { } /** - *获取微信小程序登陆二维码 + * 获取微信小程序登陆二维码 */ @GetMapping(path = "/wmurl") public LoginStatusVO getWmLoginUrl(@NotBlank String clientId, @NotBlank String secret, - Project project, @RequestParam(required = false) String deviceCode) { - return this.iAuthenticateService.getWmLoginUrl(clientId, secret, project, deviceCode); + String project, @RequestParam(required = false) String deviceCode) { + try { + Project pro = Project.valueOf(project); + return this.iAuthenticateService.getWmLoginUrl(clientId, secret, pro, deviceCode); + } catch (BaseException e) { + throw e; + } catch (Exception e) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("获取登录二维码失败"); + } } /** - *用户微信小程序扫登陆二维码 + * 用户微信小程序扫登陆二维码 */ @GetMapping(path = "/scan/wmLoginUrl") public AccountVO scanWmLoginQrCode(String code, String state) { @@ -44,7 +53,7 @@ public class LoginController { } /** - *微信小程序确认登陆接口 + * 微信小程序确认登陆接口 */ @PostMapping(path = "/wm") public void wmConfirmLogin(String code, String state) { @@ -61,18 +70,19 @@ public class LoginController { this.iAuthenticateService.preLogout(token); } - @GetMapping(path="/logout") + @GetMapping(path = "/logout") public void logout(String token) { this.iAuthenticateService.logout(token); } - @GetMapping(path="/checkStatus") + @GetMapping(path = "/checkStatus") public LoginStatusVO checkStatus(@NotBlank String sessionId) { return iAuthenticateService.checkStatus(sessionId); } /** * 获取用户信息 - 通过token + * * @param token * @return */ @@ -84,6 +94,7 @@ public class LoginController { /** * 获取用户登录信息(包含登录的项目/客户端等) + * * @param token * @return */ @@ -93,7 +104,7 @@ public class LoginController { } /** - *<玖琏科技>微信小程序code换取token + * <玖琏科技>微信小程序code换取token */ @GetMapping(path = "/wm/token") public String getTokenByWmCode(String code) { @@ -102,6 +113,7 @@ public class LoginController { /** * 到那儿了小程序code换token + * * @param code * @return */ @@ -112,6 +124,7 @@ public class LoginController { /** * 郑州共赢小程序code换token + * * @param code * @return */ @@ -121,7 +134,7 @@ public class LoginController { } /** - *token是否过期 + * token是否过期 */ @GetMapping(path = "/{token}/isExpired") public boolean isTokenExpired(@PathVariable String token) { diff --git a/src/main/java/club/joylink/rtss/controller/ProjectServerController.java b/src/main/java/club/joylink/rtss/controller/ProjectServerController.java index 36230833d..891cadfa6 100644 --- a/src/main/java/club/joylink/rtss/controller/ProjectServerController.java +++ b/src/main/java/club/joylink/rtss/controller/ProjectServerController.java @@ -4,6 +4,8 @@ import club.joylink.rtss.constants.Project; import club.joylink.rtss.constants.RoleEnum; import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.controller.advice.Role; +import club.joylink.rtss.exception.BaseException; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.project.ServerService; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; @@ -25,8 +27,14 @@ public class ProjectServerController { private ServerService serverService; @GetMapping("/project/{project}") - public ProjectServerVO getByProject(@PathVariable Project project) { - return this.serverService.getByProject(project); + public ProjectServerVO getByProject(@PathVariable String project) { + try { + return this.serverService.getByProject(Project.valueOf(project)); + } catch (BaseException e) { + throw e; + } catch (Exception e) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(); + } } @Role(RoleEnum.SuperAdmin) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java index a5edae484..892aede56 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java @@ -234,8 +234,8 @@ public class AtsPlanTrainStageService implements AtsStageService { SimulationDataRepository repository = simulation.getRepository(); LocalDateTime systemTime = simulation.getSystemTime(); TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); - if (tripPlan.getEndSection().equals(parkSection) || - tripPlan.getEndSection().getStation().equals(parkSection.getStation())) { + if (tripPlan.getEndSection().equals(parkSection) + /*|| tripPlan.getEndSection().getStation().equals(parkSection.getStation())*/) { // 计划终端折返轨或和计划终端折返轨同站的折返轨,根据车次类型处理 TripPlan nextTripPlan = repository.queryNextTripPlanOf(tripPlan); if (nextTripPlan == null) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java index 306319837..73a0e4ccb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java @@ -627,6 +627,13 @@ public class Signal extends DelayUnlockDevice { replaceSignals.add(signal); } + /** + * 获取信号机在区段上的位置 + */ + public SectionPosition getPosition() { + return new SectionPosition(section, offset); + } + public enum LightColor { RED, YELLOW, 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 e0ff0b3f0..f5ac1bb4d 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 @@ -668,6 +668,7 @@ public class VirtualRealityTrain extends VirtualRealityDevice { this.nextParking = true; this.gear = Handwheel.ATO; this.confirmationMessages.clear(); + this.cbtcMaMissDuration = 0; } public void setTarget(Section target) { 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 3600e8f26..a0e0153a2 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 @@ -5,21 +5,15 @@ import club.joylink.rtss.simulation.cbtc.ATP.ground.MaService; import club.joylink.rtss.simulation.cbtc.ATS.operation.handler.DriverOperateHandler; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStationService; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.command.CommandBO; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; -import club.joylink.rtss.simulation.cbtc.data.map.PSD; -import club.joylink.rtss.simulation.cbtc.data.map.Section; -import club.joylink.rtss.simulation.cbtc.data.map.Stand; -import club.joylink.rtss.simulation.cbtc.data.map.Station; +import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vo.ControlTransferReplyVO; -import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; -import club.joylink.rtss.simulation.cbtc.data.vr.StandParkedTrainActivity; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityPsl; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import club.joylink.rtss.simulation.cbtc.data.vr.*; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve; import club.joylink.rtss.simulation.cbtc.onboard.ATO.service.ATOService; @@ -152,18 +146,65 @@ public class RobotLogicLoop { continue; } robotOpenATO(simulation, train); - robotDrive(simulation, train); + robotDrive(simulation, driver, train); } } /** * 机器人驾驶 */ - private void robotDrive(Simulation simulation, VirtualRealityTrain train) { - SimulationDataRepository repository = simulation.getRepository(); + private void robotDrive(Simulation simulation, SimulationMember driver, VirtualRealityTrain train) { SectionPosition targetPosition = train.getRobotTargetPosition(); if (targetPosition == null) return; + SectionPosition headPosition = train.getHeadPosition(); + boolean right = train.isRight(); + //检查是否已到达/越过目的地 + Float distance = CalculateService.calculateDistanceDoubleDirection(headPosition, targetPosition, right); + if (distance != null && distance < SimulationConstants.PARK_POINT_MAX_OFFSET) { + atoService.doBreakMax(train); + train.setRobotTargetPosition(null); + return; + } + + CommandBO command = driver.getCommand(); + CommandBO.CommandType commandType = null; + if (command != null) { + commandType = command.getCommandType(); + } + if (!CommandBO.CommandType.Drive_Through_The_Guide_Signal.equals(commandType) + && !CommandBO.CommandType.Drive_Through_The_Red_Light.equals(commandType)) { //非越红灯、越引导指令时,考虑信号机状态 + //判断前方信号机正常开放以控制目标位置 + Section nextSection = headPosition.getSection(); + for (int i = 0; i < 3; i++) { + if (nextSection.equals(targetPosition.getSection())) //当前区段就是目标区段,则不需要考虑区段末端的信号机了 + break; + Signal signal = nextSection.getSignalOf(right); + if (signal != null && !Signal.SignalType.SHUNTING.equals(signal.getType())) { + VirtualRealitySignal vrSignal = signal.getVirtualSignal(); + if (vrSignal != null && (signal.isGuideAspect() || signal.isDefaultAspect())) { //真实信号机不为null且信号机显示是引导或默认 + //目标位置修改为信号机前5米 + SectionPosition signalPosition = signal.getPosition(); + targetPosition = CalculateService.calculateNextPositionByStartAndLen(signalPosition, !right, 5, true); + } + } + nextSection = nextSection.getNextRunningSectionBaseRealSwitch(right); + if (nextSection == null) + break; + } + } + + robotDrive(simulation, train, targetPosition); + } + + /** + * 机器人驾驶 + * @param simulation + * @param train + * @param targetPosition + */ + private void robotDrive(Simulation simulation, VirtualRealityTrain train, SectionPosition targetPosition) { + SimulationDataRepository repository = simulation.getRepository(); if (!train.getDoor1().isCloseAndLock() || !train.getDoor2().isCloseAndLock()) { //如果车门没关 return; } @@ -171,37 +212,23 @@ public class RobotLogicLoop { boolean right = train.isRight(); float speed = train.getSpeed(); -// if (train.isAtoOn()) { //为国赛剧本,暂时注掉 -// train.setRobotTargetPosition(null); -// continue; -// } Float distance = CalculateService.calculateDistance(headPosition, targetPosition, right); if (distance == null || distance <= SimulationConstants.PARK_POINT_MAX_OFFSET) { //如果列车已经抵达或越过目标位置 -// this.doBreakMax(simulation, train); atoService.doBreakMax(train); - train.setRobotTargetPosition(null); -// TrainInfo trainInfo = repository.getSupervisedTrainByGroup(train.getGroupNumber()); -// if (trainInfo.isManual()) { -// train.setTarget(null); -// } return; } -// if (train.isEB()) { -// Map operationParams = new HashMap<>(); -// operationParams.put("groupNumber", train.getGroupNumber()); -// operationParams.put("percent", 0); -// atsOperationDispatcher.execute(simulation, driver, Operation.Type.Driver_Force_Change.name(), operationParams); -// } + SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), true); SpeedCurve speedCurve = null; switch (train.getDriveMode()) { case AM: //AM模式下不需要司机驾驶 - TrainInfo trainInfo = repository.getSupervisedTrainByGroup(train.getGroupNumber()); - if (trainInfo.isManualTrain()) { - train.setTarget(train.getRobotTargetPosition().getSection()); - train.setRobotTargetPosition(null); - } - break; + return; +// TrainInfo trainInfo = repository.getSupervisedTrainByGroup(train.getGroupNumber()); +// if (trainInfo.isManualTrain()) { +// train.setTarget(train.getRobotTargetPosition().getSection()); +// train.setRobotTargetPosition(null); +// } +// break; case CM: MaService.Ma ma = train.getMa2(); if (ma != null) {