Merge remote-tracking branch 'origin/test' into ats-restruct

This commit is contained in:
walker-sheng 2021-07-13 15:05:17 +08:00
commit cea1f6de3b
3 changed files with 50 additions and 44 deletions

View File

@ -175,6 +175,8 @@ public class ZCLogicLoop {
MovementAuthority.End end = checkSwitch(section, right);
if (end != null)
endList.add(end);
//前方列车
MovementAuthority.End trainEnd = checkSectionOccupied(section);
// 轨道尽头/问题道岔
Section temp = section.getNextRunningSectionOf(right);
if (Objects.isNull(temp)) { // 到尽头
@ -198,22 +200,31 @@ public class ZCLogicLoop {
section = temp;
}
// 前方列车
VirtualRealityTrain frontTrain = this.queryFrontTrain(train, trainList);
if (Objects.nonNull(frontTrain)) {
Section baseSection;
if (Objects.equals(frontTrain.isRight(), train.isRight())) {
baseSection = frontTrain.calculateTailPosition().getSection();
} else {
baseSection = frontTrain.getHeadPosition().getSection();
}
endList.add(new MovementAuthority.End(frontTrain,
MovementAuthority.EndType.FRONT_TRAIN,
baseSection));
}
// // 前方列车
// VirtualRealityTrain frontTrain = this.queryFrontTrain(train, trainList);
// if (Objects.nonNull(frontTrain)) {
// Section baseSection;
// if (Objects.equals(frontTrain.isRight(), train.isRight())) {
// baseSection = frontTrain.calculateTailPosition().getSection();
// } else {
// baseSection = frontTrain.getHeadPosition().getSection();
// }
// endList.add(new MovementAuthority.End(frontTrain,
// MovementAuthority.EndType.FRONT_TRAIN,
// baseSection));
// }
return endList;
}
private MovementAuthority.End checkSectionOccupied(Section section) {
for (Section logic : section.getLogicList()) {
if (logic.isCtOccupied()) {
return new MovementAuthority.End(section, MovementAuthority.EndType.FRONT_TRAIN, null);
}
}
return null;
}
private MovementAuthority.End checkSwitch(Section tailSection, Section headSection, boolean right) {
Section section = tailSection;
for (int i = 0; i < 10; i++) {

View File

@ -1251,18 +1251,9 @@ public class CalculateService {
if (section.isPhysical()) {
return sectionPosition;
} else {
int offset = 0;
Section parent = section.getParent();
if (parent != null) {
for (Section logicSection : parent.getLogicList()) {
if (!logicSection.equals(section)) {
offset += logicSection.getLen();
} else {
offset += sectionPosition.getOffset();
break;
}
}
return new SectionPosition(parent, offset);
return new SectionPosition(parent, section.getMinOffset() + sectionPosition.getOffset());
} else {
return null;
}

View File

@ -109,26 +109,30 @@ public class MovementAuthority {
return new SectionPosition(section, offset);
}
case FRONT_TRAIN: {
VirtualRealityTrain train = (VirtualRealityTrain) this.device;
boolean trainRight = train.isRight();
SectionPosition headPosition = train.getHeadPosition();
SectionPosition tailPosition = CalculateService
.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen());
float offset;
if (Objects.equals(trainRight, right)) { // 同向取车尾
offset = right
?
tailPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE
:
tailPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE;
} else { // 方向相反取车头
offset = right
?
headPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE
:
headPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE;
}
return new SectionPosition(this.baseSection, offset);
Section section = (Section) this.device;
return new SectionPosition(section.getParent(), right ? section.getMinOffset() : section.getMaxOffset());
// VirtualRealityTrain train = (VirtualRealityTrain) this.device;
// boolean trainRight = train.isRight();
// SectionPosition headPosition = train.getHeadPosition();
// SectionPosition tailPosition = CalculateService
// .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen());
// float offset;
// if (Objects.equals(trainRight, right)) { // 同向取车尾
// offset = right
// ?
// tailPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE
// :
// tailPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE;
// } else { // 方向相反取车头
// offset = right
// ?
// headPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE
// :
// headPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE;
// }
// return new SectionPosition(this.baseSection, offset);
}
case END_TRACK: {
Section section = (Section) this.device;
@ -138,7 +142,7 @@ public class MovementAuthority {
case UNLOCKED_OVERLAP:
case FAULT_SWITCH: {
Section section = (Section) this.device;
float offset = right ? 0 : section.getLen();
float offset = right ? section.getLen() : 0;
SectionPosition stopPosition = new SectionPosition(section, offset);
return CalculateService.calculateNextPositionByStartAndLen(stopPosition, !right, 100);
}