From c30178a688e651f6e8208b0417ca0e75a84f0855 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Mon, 23 Aug 2021 18:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9F=E5=BA=A6=E6=9B=B2=E7=BA=BF=E9=99=90?= =?UTF-8?q?=E9=80=9F=E9=80=BB=E8=BE=91=E9=87=8D=E5=86=99=EF=BC=88=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATS/service/AtsTrainService.java | 4 +- .../cbtc/data/CalculateService.java | 18 --- .../simulation/cbtc/data/map/Section.java | 2 + .../rtss/simulation/cbtc/data/map/Switch.java | 11 -- .../cbtc/data/support/SectionPosition.java | 14 ++ .../cbtc/onboard/ATO/SpeedCurve.java | 122 ++++++++++++------ 6 files changed, 97 insertions(+), 74 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index b612f7100..1161b1ecb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -1,6 +1,5 @@ package club.joylink.rtss.simulation.cbtc.ATS.service; -import club.joylink.rtss.entity.PlanRouting; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.ATS.service.stage.AtsHeadTrainStageService; import club.joylink.rtss.simulation.cbtc.ATS.service.stage.AtsPlanTrainStageService; @@ -30,7 +29,6 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalTime; -import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; @@ -783,7 +781,7 @@ public class AtsTrainService { boolean targetIsRight = targetTrain.isRight(); targetPosition = CalculateService.calculateNextPositionByStartAndLen(targetTrainTailPosition, !targetIsRight, 2); } - SectionPosition physicalPosition = CalculateService.calculatePositionOfPhysical(targetPosition); + SectionPosition physicalPosition = targetPosition.convert2PhysicalSectionPosition(); train.setRobotTargetPosition(physicalPosition); } 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 950f81194..8f0d6e59b 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 @@ -1238,22 +1238,4 @@ public class CalculateService { } return acceleratedDistance + varyingAcceleratedDistance; } - - /** - * 计算该位置对应的物理区段位置 - */ - public static SectionPosition calculatePositionOfPhysical(SectionPosition sectionPosition) { - Section section = sectionPosition.getSection(); - if (section.isPhysical()) { - return sectionPosition; - } else { - Section parent = section.getParent(); - if (parent != null) { - return new SectionPosition(parent, section.getMinOffset() + sectionPosition.getOffset()); - } else { - return null; - } - } - } - } 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 429dd09ee..ecd3ffabc 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 @@ -976,6 +976,8 @@ public class Section extends MayOutOfOrderDevice { return this.getSpeedUpLimit() / 3.6f; } else if (this.isSwitchTrack() && this.getRelSwitch().isReversePosition()) { return 30 / 3.6f; + } else if (this.getParent() != null) { + return this.getParent().getNeedLimitSpeed(); } return null; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java index fe267068c..2ab252cf8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java @@ -258,17 +258,6 @@ public class Switch extends MayOutOfOrderDevice { // } } - /** - * 设置道岔区段上限速度 - * - * @param upLimitSpeed - */ - public void setSpeedUpperLimit(int upLimitSpeed) { - this.a.setSpeedUpLimit(upLimitSpeed); - this.b.setSpeedUpLimit(upLimitSpeed); - this.c.setSpeedUpLimit(upLimitSpeed); - } - public void routeLock(Route route) { this.routeLock = true; this.route = route; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java index d708658c3..f8ecd2f8d 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java @@ -100,6 +100,20 @@ public class SectionPosition { } } + public SectionPosition convert2PhysicalSectionPosition() { + Section section = this.getSection(); + if (section.isPhysical()) { + return this; + } else { + Section parent = section.getParent(); + if (parent != null) { + return new SectionPosition(parent, section.getMinOffset() + this.getOffset()); + } else { + return null; + } + } + } + /** * 该位置位于对应区段的停车范围内 */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATO/SpeedCurve.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATO/SpeedCurve.java index 9b581fe82..7ca7519eb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATO/SpeedCurve.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATO/SpeedCurve.java @@ -45,7 +45,6 @@ public class SpeedCurve { } /** - * * @param simulation * @param train * @param ma @@ -132,6 +131,7 @@ public class SpeedCurve { public static final Map LimitSpeedCalMap = new HashMap<>(); public static final float Release_Limit_Speed = 5; // 释放功能限制速度,单位m/s + public static SpeedCalculator getLimitSpeedCalculator(float limitSpeed) { SpeedCalculator speedCalculator = LimitSpeedCalMap.get(limitSpeed); if (speedCalculator == null) { @@ -296,54 +296,23 @@ public class SpeedCurve { if (totalLen <= 0) { return SpeedCurve.ZERO; } + Section tailLogic = tailPosition.getLogicSection(); Section base = tailPosition.getSection(); Section headSection = headPosition.getSection(); float limitSpeed = recommendedSpeedMax; - boolean limit = false; - if (Objects.nonNull(tailPosition.getSection().getNeedLimitSpeed())) { - limitSpeed = Math.min(limitSpeed, tailPosition.getSection().getNeedLimitSpeed() * 0.9f); - limit = true; - } else if (Objects.nonNull(headPosition.getSection().getNeedLimitSpeed())) { - limitSpeed = Math.min(limitSpeed, headPosition.getSection().getNeedLimitSpeed() * 0.9f); - limit = true; - } SectionPosition endPosition = null; boolean ahead = false; float vt = 0; - int count = 0; - if (!limit) { - // 无限速,找前方限速 - while (Objects.nonNull(base) && count < 20) { - ++count; - Float limitSpeed1 = base.getNeedLimitSpeed(); - if (limitSpeed1 == null && !CollectionUtils.isEmpty(base.getLogicList())) { //兼容逻辑区段设置限速 - float distanceBetweenLogicAndPhysical = 0; //逻辑区段距物理区段端点的距离(同向端点) - for (Section section : base.getLogicList()) { - limitSpeed1 = section.getNeedLimitSpeed(); - if (limitSpeed1 != null) { - float offsetOfLogicSectionOnPhysicalSection = distanceBetweenLogicAndPhysical + (right ? section.getLen() : 0); //逻辑区段的端点在物理区段上的偏移量 - SectionPosition logicSectionPosition = new SectionPosition(base, offsetOfLogicSectionOnPhysicalSection); - if (logicSectionPosition.isAheadOf(tailPosition, right)) { - break; - } - } - distanceBetweenLogicAndPhysical += section.getLen(); - } + for (int i = 0; i < 20; i++) { + List
logicSections = base.getLogicList(); + if (logicSections == null) { + logicSections = Collections.singletonList(base); + } + for (Section logic : logicSections) { + Float needLimitSpeed = logic.getNeedLimitSpeed(); + if (needLimitSpeed != null) { + endPosition = new SectionPosition(base, logic.getEndOffsetByDirection(right)); } - if (Objects.nonNull(limitSpeed1)) { - if (ahead) { - // 车头前方 - vt = Math.min(limitSpeed, limitSpeed1 * 0.9f); - endPosition = new SectionPosition(base, right ? 0 : base.getLen()); - break; - } else { - limitSpeed = Math.min(limitSpeed, limitSpeed1 * 0.9f); - } - } - if (Objects.equals(base, headSection)) { - ahead = true; - } - base = base.getNextRunningSectionOf(right); } } SpeedCurve normalSpeedCurve = buildTargetSpeedCurve(totalLen, v0, 0, limitSpeed); @@ -359,6 +328,75 @@ public class SpeedCurve { return normalSpeedCurve; } +// public static SpeedCurve buildTargetSpeedCurve(SectionPosition headPosition, +// SectionPosition tailPosition, boolean right, +// float totalLen, float v0, float recommendedSpeedMax) { +// if (totalLen <= 0) { +// return SpeedCurve.ZERO; +// } +// Section base = tailPosition.getSection(); +// Section headSection = headPosition.getSection(); +// float limitSpeed = recommendedSpeedMax; +// boolean limit = false; +// if (Objects.nonNull(tailPosition.getSection().getNeedLimitSpeed())) { +// limitSpeed = Math.min(limitSpeed, tailPosition.getSection().getNeedLimitSpeed() * 0.9f); +// limit = true; +// } else if (Objects.nonNull(headPosition.getSection().getNeedLimitSpeed())) { +// limitSpeed = Math.min(limitSpeed, headPosition.getSection().getNeedLimitSpeed() * 0.9f); +// limit = true; +// } +// SectionPosition endPosition = null; +// boolean ahead = false; +// float vt = 0; +// int count = 0; +// if (!limit) { +// // 无限速,找前方限速 +// while (Objects.nonNull(base) && count < 20) { +// ++count; +// Float limitSpeed1 = base.getNeedLimitSpeed(); +// if (limitSpeed1 == null && !CollectionUtils.isEmpty(base.getLogicList())) { //兼容逻辑区段设置限速 +// float distanceBetweenLogicAndPhysical = 0; //逻辑区段距物理区段端点的距离(同向端点) +// for (Section section : base.getLogicList()) { +// limitSpeed1 = section.getNeedLimitSpeed(); +// if (limitSpeed1 != null) { +// float offsetOfLogicSectionOnPhysicalSection = distanceBetweenLogicAndPhysical + (right ? section.getLen() : 0); //逻辑区段的端点在物理区段上的偏移量 +// SectionPosition logicSectionPosition = new SectionPosition(base, offsetOfLogicSectionOnPhysicalSection); +// if (logicSectionPosition.isAheadOf(tailPosition, right)) { +// break; +// } +// } +// distanceBetweenLogicAndPhysical += section.getLen(); +// } +// } +// if (Objects.nonNull(limitSpeed1)) { +// if (ahead) { +// // 车头前方 +// vt = Math.min(limitSpeed, limitSpeed1 * 0.9f); +// endPosition = new SectionPosition(base, right ? 0 : base.getLen()); +// break; +// } else { +// limitSpeed = Math.min(limitSpeed, limitSpeed1 * 0.9f); +// } +// } +// if (Objects.equals(base, headSection)) { +// ahead = true; +// } +// base = base.getNextRunningSectionOf(right); +// } +// } +// SpeedCurve normalSpeedCurve = buildTargetSpeedCurve(totalLen, v0, 0, limitSpeed); +// if (endPosition != null) { +// Float distance = CalculateService.calculateDistance(headPosition, endPosition, right); +// if (distance != null && distance < totalLen) { +// SpeedCurve limitSpeedCurve = buildTargetSpeedCurve(distance, v0, vt, limitSpeed); +// float normalStartSpeed = normalSpeedCurve.getSpeedOf(normalSpeedCurve.getTotalDistance()); +// float limitStartSpeed = limitSpeedCurve.getSpeedOf(limitSpeedCurve.getTotalDistance()); +// return normalStartSpeed < limitStartSpeed ? normalSpeedCurve : limitSpeedCurve; +// } +// } +// return normalSpeedCurve; +// } + /** * 构建目标速度曲线 *