【连挂车停位BUG】

This commit is contained in:
weizhihong 2023-06-07 16:02:59 +08:00
parent 389f393a7d
commit bf7f8510be
3 changed files with 62 additions and 40 deletions

View File

@ -433,22 +433,6 @@ public class AtsTrainService {
throw new SimulationException(SimulationExceptionType.System_Fault, "只能选列车或区段");
}
Section section = (Section) element;
// VirtualRealityTrain linkTrain = train.getLinkTrain();
// if (linkTrain != null) {
// Section linkTrainTargetSection = section.getNextRunningSectionOf(right);
// if (linkTrainTargetSection.isStandTrack()) {
// SectionPosition linkTrainTargetPosition = new SectionPosition(linkTrainTargetSection, linkTrainTargetSection.getStopPointByDirection(right));
// Float distance = CalculateService.calculateDistance(linkTrain.getHeadPosition(), linkTrainTargetPosition, right, false);
// if (distance == null) {
// throw new SimulationException(SimulationExceptionType.Illegal_Argument, "无法到达的位置");
// }
// tempTargetPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, right, distance, false);
// } else {
// tempTargetPosition = new SectionPosition(section, section.getStopPointByDirection(right));
// }
// } else {
// tempTargetPosition = new SectionPosition(section, section.getStopPointByDirection(right));
// }
Section targetSection = section.getNextRunningSectionOf(right);
SectionPosition trainTargetPosition = new SectionPosition(targetSection, targetSection.getStopPointByDirection(right));
Float distance = CalculateService.calculateDistance(train.getHeadPosition(), trainTargetPosition, right, false);
@ -510,11 +494,23 @@ public class AtsTrainService {
param.setThroughSignal(null);
param.setThroughSignalAspect(null);
}
VirtualRealityTrain linkTrain = train.getLinkTrain();
if (linkTrain != null) {
DriveParamVO linkParamVO = param.cloneParamVO();
if (targetPosition != null) {
Section targetSection = targetPosition.getSection();
float offset = targetSection.getStopPointByDirection(train.isRight());
SectionPosition linkTargetSectionPosition = new SectionPosition(targetSection, offset);
linkParamVO.setTargetPosition(linkTargetSectionPosition);
Float distance = CalculateService.calculateDistance(headPosition, linkTrain.calculateTailPosition(), right, false);
float len = linkTrain.getLen() + (distance == null ? 0 : distance);
targetPosition = new SectionPosition(targetSection, offset + (len * (right ? -1 : 1)));
}
linkTrain.setRobotDriveParam(linkParamVO);
}
param.setTargetPosition(targetPosition);
train.setRobotDriveParam(param);
if (train.getLinkTrain() != null) {
train.getLinkTrain().setRobotDriveParam(param);
}
}
/**

View File

@ -196,10 +196,15 @@ public class SimulationRobotService {
doBreakMax(simulation, train);
}
} else if (train.isRobotNeedRun() && (train.isRMMode()
|| train.isNRMMode())) { //CM应当根据推荐速度驾驶待实现
Optional<SectionPosition> targetPositionOptional = calculateTargetPosition(simulation,
train);
targetPositionOptional.ifPresent(tp -> robotDrive(simulation, driver, train, tp));
|| train.isNRMMode())) { //CM应当根据推荐速度驾驶待实现
VirtualRealityTrain linkTrain = train.getLinkTrain();
if (linkTrain == null) {
Optional<SectionPosition> targetPositionOptional = calculateTargetPosition(simulation,
train);
targetPositionOptional.ifPresent(tp -> robotDrive(simulation, driver, train, tp));
} else {
robotDrive(simulation, driver, train, train.getRobotTargetPosition());
}
}
}
}
@ -250,40 +255,40 @@ public class SimulationRobotService {
Signal throughSignal = robotDriveParam.getThroughSignal();
SignalAspect throughAspect = robotDriveParam.getThroughSignalAspect();
Section section = headPosition.getSection();
if (throughSignal != null && !Objects.equals(section,
throughSignal.getSection())) { //当车头与要越过的信号机不在同一区段
if (throughSignal != null && !Objects.equals(section, throughSignal.getSection())) { //当车头与要越过的信号机不在同一区段
throughSignal = null;
throughAspect = null;
robotDriveParam.setThrough(DriveParamVO.NO);
}
SectionPosition selectedPosition = robotDriveParam.getTargetPosition(); //用户选择的位置
SectionPosition targetPosition = null;
for (int i = 0; i < 10; i++) {
// 车头在正常的站台上
if (section.isNormalStandTrack() && !section.equals(train.getParkSection())) { //正常站台轨且未在此处停过车
if (CollectionUtils.isEmpty(plannedParkingSections) || plannedParkingSections.contains(
section)) {
// 如果计划停车区段为空或者计划停车区段中有包含当前区段
if (CollectionUtils.isEmpty(plannedParkingSections) || plannedParkingSections.contains(section)) {
SectionPosition stopPosition = section.buildStopPointPosition(right);
if (targetPosition == null || stopPosition.isAheadOf(targetPosition, right)) {
if (headPosition.getOffset() < (section.getStopPointByDirection(right)
+ SimulationConstants.PARK_POINT_MAX_OFFSET)) { //防止意外开过站后无法发车
// 如果头部位置偏移小于停车点位置偏移目标点为当前停车点
if (headPosition.getOffset() < (section.getStopPointByDirection(right) + SimulationConstants.PARK_POINT_MAX_OFFSET)) { //防止意外开过站后无法发车
targetPosition = stopPosition;
}
}
}
}
// 取禁止信号前停车位置与当前目标停车位置中更近的一个
Signal signal = section.getSignalOf(right);
if (signal != null && !signal.isShunting()) {
if (signal != null && !signal.isShunting()) { // 信号机不为调车信号机
VirtualRealitySignal vrSignal = signal.getVirtualSignal();
SectionPosition signalPosition = signal.getPosition();
if (vrSignal != null && (i != 0 || signalPosition.isAheadOf(headPosition,
right))) { //有实体信号机且列车未越过信号机
if (vrSignal != null && (i != 0 || signalPosition.isAheadOf(headPosition, right))) { //有实体信号机且列车未越过信号机
if (Objects.equals(vrSignal.getAspect(), signal.getDefaultAspect()) //禁止信号
|| Objects.equals(vrSignal.getAspect(), signal.getGuideAspect())) { //引导信号
if (!Objects.equals(signal, throughSignal) || !Objects.equals(vrSignal.getAspect(),
throughAspect)) {
SectionPosition noPassPosition = CalculateService
.calculateNextPositionByStartAndLen(signalPosition, !right, 2, true);
if (!Objects.equals(signal, throughSignal) || !Objects.equals(vrSignal.getAspect(), throughAspect)) {
SectionPosition noPassPosition = CalculateService.calculateNextPositionByStartAndLen(signalPosition, !right, 2, true);
if (targetPosition == null || noPassPosition.isAheadOf(targetPosition, right)) {
targetPosition = noPassPosition;
}
@ -293,8 +298,7 @@ public class SimulationRobotService {
}
if (targetPosition == null) {
if (selectedPosition != null && section.equals(
selectedPosition.getSection())) { //不会有比选定位置更靠前的停车点了
if (selectedPosition != null && section.equals(selectedPosition.getSection())) { //不会有比选定位置更靠前的停车点了
targetPosition = selectedPosition;
} else {
Section tempSection = section.findNextRunningSectionBaseRealSwitch(right);
@ -305,8 +309,17 @@ public class SimulationRobotService {
}
}
} else {
if (selectedPosition != null) {
if (selectedPosition.isAheadOf(targetPosition, right)) {
targetPosition = selectedPosition;
} else {
break;
}
}
if (selectedPosition != null && selectedPosition.isAheadOf(targetPosition, right)) {
targetPosition = selectedPosition;
} else {
}
}
if (targetPosition != null) {
@ -343,8 +356,7 @@ public class SimulationRobotService {
/**
* 机器人驾驶
*/
private void robotDrive(Simulation simulation, SimulationMember driver, VirtualRealityTrain train,
SectionPosition targetPosition) {
private void robotDrive(Simulation simulation, SimulationMember driver, VirtualRealityTrain train, SectionPosition targetPosition) {
train.getRobotDriveParam().setStopPosition(targetPosition);
if (!train.isInTheGear(VirtualRealityTrain.Handwheel.MANUAL)) { //确保当前在手动档位
return;

View File

@ -139,4 +139,18 @@ public class DriveParamVO {
public boolean isRouteBlockDriver() {
return DRIVER_ROUTE_BLOCK == through;
}
public DriveParamVO cloneParamVO() {
DriveParamVO paramVO = new DriveParamVO();
paramVO.setSpeedLimit(speedLimit);
paramVO.setStop(this.stop);
paramVO.setRun(this.run);
paramVO.setTargetDeviceCode(targetDeviceCode);
paramVO.setTargetPosition(this.targetPosition);
paramVO.setThrough(this.through);
paramVO.setThroughSignal(this.throughSignal);
paramVO.setThroughSignalAspect(this.throughSignalAspect);
paramVO.setReleaseEB(this.releaseEB);
return paramVO;
}
}