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

# Conflicts:
#	src/main/java/club/joylink/rtss/simulation/cbtc/robot/SimulationRobotService.java
This commit is contained in:
joylink_zhangsai 2023-06-07 17:56:08 +08:00
commit 9001cb5df9
6 changed files with 88 additions and 48 deletions

View File

@ -403,7 +403,7 @@ public class OrgUserService implements IOrgUserService {
Map<Long, List<UserSimulationRecord>> userRecordMap = records.stream()
.collect(Collectors.groupingBy(UserSimulationRecord::getUserId));
vos.forEach(vo -> {
List<UserSimulationRecord> recordList = userRecordMap.get(vo.getUserId());
List<UserSimulationRecord> recordList = userRecordMap.getOrDefault(vo.getUserId(), List.of());
long simDuration = recordList.stream().filter(record -> UserSimulationRecordManager.SimulationUseInfo.SIMULATION.equals(record.getType()))
.mapToLong(UserSimulationRecord::getDuration)
.sum();

View File

@ -433,22 +433,13 @@ 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);
if (distance == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "无法到达的位置");
}
tempTargetPosition = new SectionPosition(section, section.getStopPointByDirection(right));
} else {
VirtualRealityTrain targetTrain = repository.getVRByCode(targetDeviceCode, VirtualRealityTrain.class);
SectionPosition targetTrainTailPosition = targetTrain.calculateTailPosition();
@ -503,8 +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);
}
/**

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
@Component
public class CiSwitchControlService {
@ -97,21 +98,27 @@ public class CiSwitchControlService {
*/
public boolean turn(Simulation simulation, Switch aSwitch) {
VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch();
boolean isRP;
if (vrSwitch.getCommand() != null) {
switch (vrSwitch.getCommand()) {
case NP:
return this.turn2ReversePosition(simulation, aSwitch);
case RP:
return this.turn2NormalPosition(simulation, aSwitch);
}
isRP = vrSwitch.getCommand().equals(VirtualRealitySwitch.Operation.RP);
} else {
if (vrSwitch.isPosN()) {
return this.turn2ReversePosition(simulation, aSwitch);
} else if (vrSwitch.isPosR()) {
return this.turn2NormalPosition(simulation, aSwitch);
isRP = vrSwitch.isPosR();
}
if (simulation.getRepository().getConfig().isSwitchNRTurnChain()) {
Switch linkedSwitch = aSwitch.queryLinkedSwitch();
if (Objects.nonNull(linkedSwitch)) {
if (isRP) {
this.turn2NormalPosition(simulation, linkedSwitch);
} else {
this.turn2ReversePosition(simulation, linkedSwitch);
}
}
}
return this.turn2NormalPosition(simulation, aSwitch);
if (isRP) {
return this.turn2NormalPosition(simulation, aSwitch);
} else {
return this.turn2ReversePosition(simulation, aSwitch);
}
}
/**

View File

@ -552,11 +552,11 @@ public class ATPService {
public void inbound(Simulation simulation, String groupNumber) {
VirtualRealityTrain train = simulation.getRepository().getOnlineTrainBy(groupNumber);
Section headSection = train.getHeadPosition().getSection();
if (headSection.isTurnBackTrack() && train.isStop()) { //列车停在折返
if (headSection.isTransferTrack() && train.isStop()) { //列车停在转换
SimulationDataRepository repository = simulation.getRepository();
TrainInfo trainInfo = repository.getSupervisedTrainByGroup(train.getGroupNumber());
List<RoutePath> routePathList = repository.queryRoutePathsByEnd(headSection);
if (routePathList.get(0).isRight() == trainInfo.getRight()) { //准备回库
if (routePathList.stream().anyMatch(routePath -> routePath.isRight() == trainInfo.getRight())) { //准备回库
trainInfo.finishPlanPrepareInbound();
}
}

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) {

View File

@ -133,4 +133,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;
}
}