【仿真背景加载列车逻辑修改】【站台跳停时,列车不开门】【calculateStationRatio方法返回值空指针处理】

This commit is contained in:
weizhihong 2023-11-28 17:53:16 +08:00
parent d39f9dbdbb
commit bdfa4d2992
5 changed files with 1181 additions and 1007 deletions

View File

@ -9,82 +9,97 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
/**
* 车辆运行中
*/
@Slf4j
public class RuningService implements CalculateDiagram{
public class RuningService implements CalculateDiagram {
@Override
public Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){
String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack();
if(StringUtils.isEmpty(d)){
StationDiagram sd = new StationDiagram(train);
Station nextStation = diagramStation.findNext(train.getNextStation(),train.isRight());
sd.setStartStation(train.getNextStation());
sd.setEndStation(nextStation);
return Optional.of(sd);
}
Section leaveStandTrack = simulation.getRepository().getByCode(d,Section.class);
Station endStation = diagramStation.findLastNotDepotStation(train.isRight());
if(Objects.equals(leaveStandTrack.getStation().getCode(),endStation.getCode())){
//列车即将驶离终点站
StationDiagram sd = new StationDiagram(train,true,1F,true);
Station preStation = diagramStation.findPre(leaveStandTrack.getStation(),train.isRight());
sd.setStartStation(preStation);
sd.setEndStation(endStation);
return Optional.of(sd);
}else{
Station targetStation = diagramStation.findNext(leaveStandTrack.getStation(),train.isRight());
Section targetStand = targetStation.getStandOf(train.isRight()).get(0).getSection();
Float complateDis = this.calculateStationRatio(simulation,leaveStandTrack,targetStand,train);
if(Objects.isNull(complateDis)){
return Optional.empty();
}
StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,false);
stationDiagram.setStartStation(leaveStandTrack.getStation());
stationDiagram.setEndStation(targetStand.getStation());
return Optional.of(stationDiagram);
}
@Override
public Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo,
VirtualRealityTrain train, SortDiagramStation diagramStation) {
String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack())
? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack();
if (StringUtils.isEmpty(d)) {
StationDiagram sd = new StationDiagram(train);
Station nextStation = diagramStation.findNext(train.getNextStation(), train.isRight());
sd.setStartStation(train.getNextStation());
sd.setEndStation(nextStation);
return Optional.of(sd);
}
private Float calculateStationRatio(Simulation simulation,Section begin,Section end,VirtualRealityTrain train){
Long mapId = simulation.getBuildParams().getMap().getId();
LocalDateTime simulationDateTime = simulation.getCorrectSystemTime();
try{
Float totalDis = CalculateService.calculateDistance(begin,end,train.isRight());
Float runOffset = 0F;
float stationCompleteRatio = 1F;
if(totalDis != 0F){
float off = begin.getStopPointByDirection(train.isRight());
runOffset = CalculateService.calculateDistanceIgnoreSwitchFromStationToTrainHead(new SectionPosition(begin,off),train.getHeadPosition(),train.isRight());
if(runOffset != 1F){
stationCompleteRatio = new BigDecimal(runOffset / totalDis).setScale(3, RoundingMode.HALF_UP).floatValue();
if(stationCompleteRatio >= 1F){
stationCompleteRatio = 1F;
}
}
}
log.debug("线路id:{} 仿真时间:{} 车次[{}] 方向[{}] 车头区段[{}] 车头位置[{}] 车尾区段[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 已行驶[{}] 行驶完成度[{}]"
,mapId,simulationDateTime
,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode(),train.getHeadPosition().getOffset()
,train.getTailPosition().getSection().getCode(), begin.getCode(),end.getCode() , totalDis ,(totalDis - runOffset),runOffset ,stationCompleteRatio);
return Math.abs(stationCompleteRatio);
}catch (Exception e){
log.error("计算失败 线路id:{} 仿真时间:{} groupNum:{},isRight:{},begin:{},end:{}, 错误信息:{}",mapId,simulationDateTime
,train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,e.getMessage(),e);
return null;
}
Section leaveStandTrack = simulation.getRepository().getByCode(d, Section.class);
Station endStation = diagramStation.findLastNotDepotStation(train.isRight());
if (Objects.equals(leaveStandTrack.getStation().getCode(), endStation.getCode())) {
//列车即将驶离终点站
StationDiagram sd = new StationDiagram(train, true, 1F, true);
Station preStation = diagramStation.findPre(leaveStandTrack.getStation(), train.isRight());
sd.setStartStation(preStation);
sd.setEndStation(endStation);
return Optional.of(sd);
} else {
Station targetStation = diagramStation.findNext(leaveStandTrack.getStation(),
train.isRight());
Section targetStand = targetStation.getStandOf(train.isRight()).get(0).getSection();
Float complateDis = this.calculateStationRatio(simulation, leaveStandTrack, targetStand,
train);
if (Objects.isNull(complateDis)) {
return Optional.empty();
}
StationDiagram stationDiagram = new StationDiagram(train, true, complateDis, false);
stationDiagram.setStartStation(leaveStandTrack.getStation());
stationDiagram.setEndStation(targetStand.getStation());
return Optional.of(stationDiagram);
}
}
private Float calculateStationRatio(Simulation simulation, Section begin, Section end,
VirtualRealityTrain train) {
Long mapId = simulation.getBuildParams().getMap().getId();
LocalDateTime simulationDateTime = simulation.getCorrectSystemTime();
try {
Float totalDis = CalculateService.calculateDistance(begin, end, train.isRight());
Float runOffset = 0F;
float stationCompleteRatio = 1F;
if (totalDis != 0F) {
float off = begin.getStopPointByDirection(train.isRight());
runOffset = CalculateService.calculateDistanceIgnoreSwitchFromStationToTrainHead(
new SectionPosition(begin, off), train.getHeadPosition(), train.isRight());
if (runOffset == null) {
return 1F;
}
if (runOffset != 1F) {
stationCompleteRatio = new BigDecimal(runOffset / totalDis).setScale(3,
RoundingMode.HALF_UP).floatValue();
if (stationCompleteRatio >= 1F) {
stationCompleteRatio = 1F;
}
}
}
log.debug(
"线路id:{} 仿真时间:{} 车次[{}] 方向[{}] 车头区段[{}] 车头位置[{}] 车尾区段[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 已行驶[{}] 行驶完成度[{}]"
, mapId, simulationDateTime
, train.getGroupNumber(), train.isRight(), train.getHeadPosition().getSection().getCode(),
train.getHeadPosition().getOffset()
, train.getTailPosition().getSection().getCode(), begin.getCode(), end.getCode(),
totalDis, (totalDis - runOffset), runOffset, stationCompleteRatio);
return Math.abs(stationCompleteRatio);
} catch (Exception e) {
log.error(
"计算失败 线路id:{} 仿真时间:{} groupNum:{},isRight:{},begin:{},end:{}, 错误信息:{}",
mapId, simulationDateTime
, train.getGroupNumber(), train.isRight(), begin.getCode(), end.getCode(), e.getMessage(),
e);
return null;
}
}
}

View File

@ -14,299 +14,331 @@ import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageMovementAut
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageSectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vr.StandParkedTrainActivity;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.*;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.ConfirmationMessage;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.DoorMode;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.DoorSelection;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.Fault;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.Handwheel;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.PreselectionMode;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.RunType;
import java.util.LinkedHashSet;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import java.util.LinkedHashSet;
@Getter
@Setter
@NoArgsConstructor
public class StorageVirtualRealityTrain extends StorageVirtualRealityDevice {
private String groupNumber;
private boolean noCommunicateDevice;
private boolean communication;
private RunLevel runLevel;
private DriveMode driveMode;
private PreselectionMode tempPreselectionMode;
private PreselectionMode preselectionMode;
private String serviceNumber;
private String tripNumber;
private String destinationCode;
private String nextStationCode;
private boolean beAbout2Arrive;
private String targetCode;
private int parkTime;
private int parkRemainTime;
private String parkSectionCode;
private boolean departure;
private boolean breaking;
private String terminalStationCode;
private StorageSectionPosition headPosition;
private StorageSectionPosition tailPosition;
private boolean right;
private StorageMovementAuthority ma;
private StorageMa ma2;
private int cbtcMaMissDuration;
private Handwheel gear;
private float speed;
private float locationKM;
private float targetDistance;
private float atoSpeedMax;
private float atoSpeed;
private float atpSpeed;
private boolean signalEB;
private boolean circuitEB;
private StandParkedTrainActivity standParkedTrainActivity;
private boolean nextParking;
private boolean jump;
private boolean hold;
private boolean trainHold;
private boolean dtro;
private boolean changeEnds;
private int changeEndsRemainTime;
private boolean atoOn;
private boolean atpOn;
private boolean priorityRouteSet;
private StorageDoor door1;
private StorageDoor door2;
private DoorMode doorMode;
private DoorSelection doorSelection;
private float fk;
private float fb;
private TrainTBControl tbControl;
private float leverPosition;
private Fault fault;
private boolean backUp;
private int delayTime;
private boolean powerOn;
private boolean pantograph1Up;
private boolean pantograph2Up;
private String linkTrainCode;
private RunType runType;
private boolean orderStop;
private boolean needDepartureCommand;
private boolean positioned;
private int runningTime;
private boolean released;
private LinkedHashSet<ConfirmationMessage> confirmationMessages;
private boolean atoCanOpen;
// private String vrAudioCode;
private StorageDriveParamVO robotDriveParam;
private String groupNumber;
public StorageVirtualRealityTrain(VirtualRealityTrain virtualRealityTrain) {
super(virtualRealityTrain);
groupNumber = virtualRealityTrain.getGroupNumber();
private boolean noCommunicateDevice;
private boolean communication;
private RunLevel runLevel;
private DriveMode driveMode;
private PreselectionMode tempPreselectionMode;
private PreselectionMode preselectionMode;
private String serviceNumber;
private String tripNumber;
private String destinationCode;
private String nextStationCode;
private boolean beAbout2Arrive;
private String targetCode;
private int parkTime;
private int parkRemainTime;
private String parkSectionCode;
private boolean departure;
private boolean breaking;
private String terminalStationCode;
private StorageSectionPosition headPosition;
private StorageSectionPosition tailPosition;
private boolean right;
private StorageMovementAuthority ma;
private StorageMa ma2;
private int cbtcMaMissDuration;
private Handwheel gear;
private float speed;
private float locationKM;
private float targetDistance;
private float atoSpeedMax;
private float atoSpeed;
private float atpSpeed;
private boolean signalEB;
private boolean circuitEB;
private StandParkedTrainActivity standParkedTrainActivity;
private boolean nextParking;
private boolean jump;
private boolean hold;
private boolean trainHold;
private boolean dtro;
private boolean changeEnds;
private int changeEndsRemainTime;
private boolean atoOn;
private boolean atpOn;
private boolean priorityRouteSet;
private StorageDoor door1;
private StorageDoor door2;
private DoorMode doorMode;
private DoorSelection doorSelection;
private float fk;
private float fb;
private TrainTBControl tbControl;
private float leverPosition;
private Fault fault;
private boolean backUp;
private int delayTime;
private boolean powerOn;
private boolean pantograph1Up;
private boolean pantograph2Up;
private String linkTrainCode;
private RunType runType;
private boolean orderStop;
private boolean needDepartureCommand;
private boolean positioned;
private int runningTime;
private boolean released;
private LinkedHashSet<ConfirmationMessage> confirmationMessages;
private boolean atoCanOpen;
// private String vrAudioCode;
private StorageDriveParamVO robotDriveParam;
public StorageVirtualRealityTrain(VirtualRealityTrain virtualRealityTrain) {
super(virtualRealityTrain);
groupNumber = virtualRealityTrain.getGroupNumber();
}
public static StorageVirtualRealityTrain convert2Storage(
VirtualRealityTrain virtualRealityTrain) {
StorageVirtualRealityTrain storageVirtualRealityTrain = new StorageVirtualRealityTrain(
virtualRealityTrain);
storageVirtualRealityTrain.setNoCommunicateDevice(virtualRealityTrain.isNoCommunicateDevice());
storageVirtualRealityTrain.setCommunication(virtualRealityTrain.isCommunication());
storageVirtualRealityTrain.setRunLevel(virtualRealityTrain.getRunLevel());
storageVirtualRealityTrain.setDriveMode(virtualRealityTrain.getDriveMode());
storageVirtualRealityTrain.setTempPreselectionMode(
virtualRealityTrain.getTempPreselectionMode());
storageVirtualRealityTrain.setPreselectionMode(virtualRealityTrain.getPreselectionMode());
storageVirtualRealityTrain.setServiceNumber(virtualRealityTrain.getServiceNumber());
storageVirtualRealityTrain.setTripNumber(virtualRealityTrain.getTripNumber());
storageVirtualRealityTrain.setDestinationCode(virtualRealityTrain.getDestinationCode());
if (virtualRealityTrain.getNextStation() != null) {
storageVirtualRealityTrain.setNextStationCode(virtualRealityTrain.getNextStation().getCode());
}
public static StorageVirtualRealityTrain convert2Storage(VirtualRealityTrain virtualRealityTrain) {
StorageVirtualRealityTrain storageVirtualRealityTrain = new StorageVirtualRealityTrain(virtualRealityTrain);
storageVirtualRealityTrain.setNoCommunicateDevice(virtualRealityTrain.isNoCommunicateDevice());
storageVirtualRealityTrain.setCommunication(virtualRealityTrain.isCommunication());
storageVirtualRealityTrain.setRunLevel(virtualRealityTrain.getRunLevel());
storageVirtualRealityTrain.setDriveMode(virtualRealityTrain.getDriveMode());
storageVirtualRealityTrain.setTempPreselectionMode(virtualRealityTrain.getTempPreselectionMode());
storageVirtualRealityTrain.setPreselectionMode(virtualRealityTrain.getPreselectionMode());
storageVirtualRealityTrain.setServiceNumber(virtualRealityTrain.getServiceNumber());
storageVirtualRealityTrain.setTripNumber(virtualRealityTrain.getTripNumber());
storageVirtualRealityTrain.setDestinationCode(virtualRealityTrain.getDestinationCode());
if (virtualRealityTrain.getNextStation() != null) {
storageVirtualRealityTrain.setNextStationCode(virtualRealityTrain.getNextStation().getCode());
}
storageVirtualRealityTrain.setBeAbout2Arrive(virtualRealityTrain.isBeAbout2Arrive());
if (virtualRealityTrain.getTarget() != null) {
storageVirtualRealityTrain.setTargetCode(virtualRealityTrain.getTarget().getCode());
}
storageVirtualRealityTrain.setParkTime(virtualRealityTrain.getParkTime());
storageVirtualRealityTrain.setParkRemainTime(virtualRealityTrain.getParkRemainTime());
if (virtualRealityTrain.getParkSection() != null) {
storageVirtualRealityTrain.setParkSectionCode(virtualRealityTrain.getParkSection().getCode());
}
storageVirtualRealityTrain.setDeparture(virtualRealityTrain.isDeparture());
storageVirtualRealityTrain.setBreaking(virtualRealityTrain.isBreaking());
if (virtualRealityTrain.getTerminalStation() != null) {
storageVirtualRealityTrain.setTerminalStationCode(virtualRealityTrain.getTerminalStation().getCode());
}
if (virtualRealityTrain.getHeadPosition() != null) {
storageVirtualRealityTrain.setHeadPosition(new StorageSectionPosition(virtualRealityTrain.getHeadPosition()));
}
if (virtualRealityTrain.getTailPosition() != null) {
storageVirtualRealityTrain.setTailPosition(new StorageSectionPosition(virtualRealityTrain.getTailPosition()));
}
storageVirtualRealityTrain.setRight(virtualRealityTrain.isRight());
if (virtualRealityTrain.getMa() != null) {
storageVirtualRealityTrain.setMa(new StorageMovementAuthority(virtualRealityTrain.getMa()));
}
if (virtualRealityTrain.getMa2() != null) {
storageVirtualRealityTrain.setMa2(new StorageMa(virtualRealityTrain.getMa2()));
}
storageVirtualRealityTrain.setCbtcMaMissDuration(virtualRealityTrain.getCbtcMaMissDuration());
storageVirtualRealityTrain.setGear(virtualRealityTrain.getGear());
storageVirtualRealityTrain.setSpeed(virtualRealityTrain.getSpeed());
storageVirtualRealityTrain.setLocationKM(virtualRealityTrain.getLocationKM());
storageVirtualRealityTrain.setTargetDistance(virtualRealityTrain.getTargetDistance());
storageVirtualRealityTrain.setAtoSpeedMax(virtualRealityTrain.getAtoSpeedMax());
storageVirtualRealityTrain.setAtoSpeed(virtualRealityTrain.getAtoSpeed());
storageVirtualRealityTrain.setAtpSpeed(virtualRealityTrain.getAtpSpeed());
storageVirtualRealityTrain.setSignalEB(virtualRealityTrain.isSignalEB());
storageVirtualRealityTrain.setCircuitEB(virtualRealityTrain.isCircuitEB());
storageVirtualRealityTrain.setStandParkedTrainActivity(virtualRealityTrain.getStandParkedTrainActivity());
storageVirtualRealityTrain.setNextParking(virtualRealityTrain.isNextParking());
storageVirtualRealityTrain.setJump(virtualRealityTrain.isJump());
storageVirtualRealityTrain.setHold(virtualRealityTrain.isHold());
storageVirtualRealityTrain.setTrainHold(virtualRealityTrain.isTrainHold());
storageVirtualRealityTrain.setDtro(virtualRealityTrain.isDtro());
storageVirtualRealityTrain.setChangeEnds(virtualRealityTrain.isChangeEnds());
storageVirtualRealityTrain.setChangeEndsRemainTime(virtualRealityTrain.getChangeEndsRemainTime());
storageVirtualRealityTrain.setAtoOn(virtualRealityTrain.isAtoOn());
storageVirtualRealityTrain.setAtpOn(virtualRealityTrain.isAtpOn());
storageVirtualRealityTrain.setPriorityRouteSet(virtualRealityTrain.isPriorityRouteSet());
if (virtualRealityTrain.getDoor1() != null) {
storageVirtualRealityTrain.setDoor1(new StorageDoor(virtualRealityTrain.getDoor1()));
}
if (virtualRealityTrain.getDoor2() != null) {
storageVirtualRealityTrain.setDoor2(new StorageDoor(virtualRealityTrain.getDoor2()));
}
storageVirtualRealityTrain.setDoorMode(virtualRealityTrain.getDoorMode());
storageVirtualRealityTrain.setDoorSelection(virtualRealityTrain.getDoorSelection());
storageVirtualRealityTrain.setFk(virtualRealityTrain.getFk());
storageVirtualRealityTrain.setFb(virtualRealityTrain.getFb());
storageVirtualRealityTrain.setTbControl(virtualRealityTrain.getTbControl());
storageVirtualRealityTrain.setLeverPosition(virtualRealityTrain.getLeverPosition());
storageVirtualRealityTrain.setFault(virtualRealityTrain.getFault());
storageVirtualRealityTrain.setBackUp(virtualRealityTrain.isBackUp());
storageVirtualRealityTrain.setDelayTime(virtualRealityTrain.getDelayTime());
storageVirtualRealityTrain.setPowerOn(virtualRealityTrain.isPowerOn());
storageVirtualRealityTrain.setPantograph1Up(virtualRealityTrain.isPantograph1Up());
storageVirtualRealityTrain.setPantograph2Up(virtualRealityTrain.isPantograph2Up());
if (virtualRealityTrain.getLinkTrain() != null) {
storageVirtualRealityTrain.setLinkTrainCode(virtualRealityTrain.getLinkTrain().getCode());
}
storageVirtualRealityTrain.setRunType(virtualRealityTrain.getRunType());
storageVirtualRealityTrain.setOrderStop(virtualRealityTrain.isOrderStop());
storageVirtualRealityTrain.setNeedDepartureCommand(virtualRealityTrain.isNeedDepartureCommand());
storageVirtualRealityTrain.setPositioned(virtualRealityTrain.isPositioned());
storageVirtualRealityTrain.setRunningTime(virtualRealityTrain.getRunningTime());
storageVirtualRealityTrain.setReleased(virtualRealityTrain.isReleased());
storageVirtualRealityTrain.setConfirmationMessages(virtualRealityTrain.getConfirmationMessages());
storageVirtualRealityTrain.setAtoCanOpen(virtualRealityTrain.isAtoCanOpen());
storageVirtualRealityTrain.setBeAbout2Arrive(virtualRealityTrain.isBeAbout2Arrive());
if (virtualRealityTrain.getTarget() != null) {
storageVirtualRealityTrain.setTargetCode(virtualRealityTrain.getTarget().getCode());
}
storageVirtualRealityTrain.setParkTime(virtualRealityTrain.getParkTime());
storageVirtualRealityTrain.setParkRemainTime(virtualRealityTrain.getParkRemainTime());
if (virtualRealityTrain.getParkSection() != null) {
storageVirtualRealityTrain.setParkSectionCode(virtualRealityTrain.getParkSection().getCode());
}
storageVirtualRealityTrain.setDeparture(virtualRealityTrain.isDeparture());
storageVirtualRealityTrain.setBreaking(virtualRealityTrain.isBreaking());
if (virtualRealityTrain.getTerminalStation() != null) {
storageVirtualRealityTrain.setTerminalStationCode(
virtualRealityTrain.getTerminalStation().getCode());
}
if (virtualRealityTrain.getHeadPosition() != null) {
storageVirtualRealityTrain.setHeadPosition(
new StorageSectionPosition(virtualRealityTrain.getHeadPosition()));
}
if (virtualRealityTrain.getTailPosition() != null) {
storageVirtualRealityTrain.setTailPosition(
new StorageSectionPosition(virtualRealityTrain.getTailPosition()));
}
storageVirtualRealityTrain.setRight(virtualRealityTrain.isRight());
if (virtualRealityTrain.getMa() != null) {
storageVirtualRealityTrain.setMa(new StorageMovementAuthority(virtualRealityTrain.getMa()));
}
if (virtualRealityTrain.getMa2() != null) {
storageVirtualRealityTrain.setMa2(new StorageMa(virtualRealityTrain.getMa2()));
}
storageVirtualRealityTrain.setCbtcMaMissDuration(virtualRealityTrain.getCbtcMaMissDuration());
storageVirtualRealityTrain.setGear(virtualRealityTrain.getGear());
storageVirtualRealityTrain.setSpeed(virtualRealityTrain.getSpeed());
storageVirtualRealityTrain.setLocationKM(virtualRealityTrain.getLocationKM());
storageVirtualRealityTrain.setTargetDistance(virtualRealityTrain.getTargetDistance());
storageVirtualRealityTrain.setAtoSpeedMax(virtualRealityTrain.getAtoSpeedMax());
storageVirtualRealityTrain.setAtoSpeed(virtualRealityTrain.getAtoSpeed());
storageVirtualRealityTrain.setAtpSpeed(virtualRealityTrain.getAtpSpeed());
storageVirtualRealityTrain.setSignalEB(virtualRealityTrain.isSignalEB());
storageVirtualRealityTrain.setCircuitEB(virtualRealityTrain.isCircuitEB());
storageVirtualRealityTrain.setStandParkedTrainActivity(
virtualRealityTrain.getStandParkedTrainActivity());
storageVirtualRealityTrain.setNextParking(virtualRealityTrain.isNextParking());
storageVirtualRealityTrain.setJump(virtualRealityTrain.isJump());
storageVirtualRealityTrain.setHold(virtualRealityTrain.isHold());
storageVirtualRealityTrain.setTrainHold(virtualRealityTrain.isTrainHold());
storageVirtualRealityTrain.setDtro(virtualRealityTrain.isDtro());
storageVirtualRealityTrain.setChangeEnds(virtualRealityTrain.isChangeEnds());
storageVirtualRealityTrain.setChangeEndsRemainTime(
virtualRealityTrain.getChangeEndsRemainTime());
storageVirtualRealityTrain.setAtoOn(virtualRealityTrain.isAtoOn());
storageVirtualRealityTrain.setAtpOn(virtualRealityTrain.isAtpOn());
storageVirtualRealityTrain.setPriorityRouteSet(virtualRealityTrain.isPriorityRouteSet());
if (virtualRealityTrain.getDoor1() != null) {
storageVirtualRealityTrain.setDoor1(new StorageDoor(virtualRealityTrain.getDoor1()));
}
if (virtualRealityTrain.getDoor2() != null) {
storageVirtualRealityTrain.setDoor2(new StorageDoor(virtualRealityTrain.getDoor2()));
}
storageVirtualRealityTrain.setDoorMode(virtualRealityTrain.getDoorMode());
storageVirtualRealityTrain.setDoorSelection(virtualRealityTrain.getDoorSelection());
storageVirtualRealityTrain.setFk(virtualRealityTrain.getFk());
storageVirtualRealityTrain.setFb(virtualRealityTrain.getFb());
storageVirtualRealityTrain.setTbControl(virtualRealityTrain.getTbControl());
storageVirtualRealityTrain.setLeverPosition(virtualRealityTrain.getLeverPosition());
storageVirtualRealityTrain.setFault(virtualRealityTrain.getFault());
storageVirtualRealityTrain.setBackUp(virtualRealityTrain.isBackUp());
storageVirtualRealityTrain.setDelayTime(virtualRealityTrain.getDelayTime());
storageVirtualRealityTrain.setPowerOn(virtualRealityTrain.isPowerOn());
storageVirtualRealityTrain.setPantograph1Up(virtualRealityTrain.isPantograph1Up());
storageVirtualRealityTrain.setPantograph2Up(virtualRealityTrain.isPantograph2Up());
if (virtualRealityTrain.getLinkTrain() != null) {
storageVirtualRealityTrain.setLinkTrainCode(virtualRealityTrain.getLinkTrain().getCode());
}
storageVirtualRealityTrain.setRunType(virtualRealityTrain.getRunType());
storageVirtualRealityTrain.setOrderStop(virtualRealityTrain.isOrderStop());
storageVirtualRealityTrain.setNeedDepartureCommand(
virtualRealityTrain.isNeedDepartureCommand());
storageVirtualRealityTrain.setPositioned(virtualRealityTrain.isPositioned());
storageVirtualRealityTrain.setRunningTime(virtualRealityTrain.getRunningTime());
storageVirtualRealityTrain.setReleased(virtualRealityTrain.isReleased());
storageVirtualRealityTrain.setConfirmationMessages(
virtualRealityTrain.getConfirmationMessages());
storageVirtualRealityTrain.setAtoCanOpen(virtualRealityTrain.isAtoCanOpen());
// if (virtualRealityTrain.getVrAudio() != null) {
// storageVirtualRealityTrain.setVrAudioCode(virtualRealityTrain.getVrAudio().getCode());
// }
if (virtualRealityTrain.getRobotDriveParam() != null) {
storageVirtualRealityTrain.setRobotDriveParam(new StorageDriveParamVO(virtualRealityTrain.getRobotDriveParam()));
}
return storageVirtualRealityTrain;
if (virtualRealityTrain.getRobotDriveParam() != null) {
storageVirtualRealityTrain.setRobotDriveParam(
new StorageDriveParamVO(virtualRealityTrain.getRobotDriveParam()));
}
return storageVirtualRealityTrain;
}
@Override
public boolean convert(MapElement element) {
return true;
@Override
public boolean convert(MapElement element) {
return true;
}
/**
* 列车的基础信息
*/
@Override
public void recover2Simulation(MapElement element, Simulation simulation,
SimulationDataRepository repository) {
VirtualRealityTrain virtualRealityTrain = (VirtualRealityTrain) element;
virtualRealityTrain.setNoCommunicateDevice(noCommunicateDevice);
virtualRealityTrain.setCommunication(communication);
virtualRealityTrain.setRunLevel(runLevel);
virtualRealityTrain.setDriveMode(driveMode);
virtualRealityTrain.setTempPreselectionMode(tempPreselectionMode);
virtualRealityTrain.setPreselectionMode(preselectionMode);
virtualRealityTrain.setServiceNumber(serviceNumber);
virtualRealityTrain.setTripNumber(tripNumber);
virtualRealityTrain.setDestinationCode(destinationCode);
if (nextStationCode != null) {
virtualRealityTrain.setNextStation(repository.getByCode(nextStationCode, Station.class));
}
virtualRealityTrain.setBeAbout2Arrive(beAbout2Arrive);
if (targetCode != null) {
virtualRealityTrain.setTarget(repository.getByCode(targetCode, Section.class));
}
virtualRealityTrain.setParkTime(parkTime);
virtualRealityTrain.setParkRemainTime(parkRemainTime);
if (parkSectionCode != null) {
virtualRealityTrain.setParkSection(repository.getByCode(parkSectionCode, Section.class));
}
virtualRealityTrain.setDeparture(departure);
virtualRealityTrain.setBreaking(breaking);
if (terminalStationCode != null) {
virtualRealityTrain.setTerminalStation(
repository.getByCode(terminalStationCode, Station.class));
}
if (headPosition != null) {
virtualRealityTrain.setHeadPosition(headPosition.convert2SimulationObj(repository));
}
if (tailPosition != null) {
virtualRealityTrain.setTailPosition(tailPosition.convert2SimulationObj(repository));
}
virtualRealityTrain.setRight(right);
virtualRealityTrain.setCbtcMaMissDuration(cbtcMaMissDuration);
virtualRealityTrain.setGear(gear);
virtualRealityTrain.setSpeed(speed);
virtualRealityTrain.setLocationKM(locationKM);
virtualRealityTrain.setTargetDistance(targetDistance);
virtualRealityTrain.setAtoSpeedMax(atoSpeedMax);
virtualRealityTrain.setAtoSpeed(atoSpeed);
virtualRealityTrain.setAtpSpeed(atpSpeed);
virtualRealityTrain.setSignalEB(signalEB);
virtualRealityTrain.setCircuitEB(circuitEB);
virtualRealityTrain.setStandParkedTrainActivity(standParkedTrainActivity);
virtualRealityTrain.setNextParking(nextParking);
virtualRealityTrain.setJump(jump);
virtualRealityTrain.setHold(hold);
virtualRealityTrain.setTrainHold(trainHold);
virtualRealityTrain.setDtro(dtro);
virtualRealityTrain.setChangeEnds(changeEnds);
virtualRealityTrain.setChangeEndsRemainTime(changeEndsRemainTime);
virtualRealityTrain.setAtoOn(atoOn);
virtualRealityTrain.setAtpOn(atpOn);
virtualRealityTrain.setPriorityRouteSet(priorityRouteSet);
virtualRealityTrain.setDoorMode(doorMode);
virtualRealityTrain.setDoorSelection(doorSelection);
virtualRealityTrain.setFk(fk);
virtualRealityTrain.setFb(fb);
virtualRealityTrain.setTbControl(tbControl);
virtualRealityTrain.setLeverPosition(leverPosition);
virtualRealityTrain.setFault(fault);
virtualRealityTrain.setBackUp(backUp);
virtualRealityTrain.setDelayTime(delayTime);
virtualRealityTrain.setPowerOn(powerOn);
virtualRealityTrain.setPantograph1Up(pantograph1Up);
virtualRealityTrain.setPantograph2Up(pantograph2Up);
virtualRealityTrain.setRunType(runType);
virtualRealityTrain.setOrderStop(orderStop);
virtualRealityTrain.setNeedDepartureCommand(needDepartureCommand);
virtualRealityTrain.setPositioned(positioned);
virtualRealityTrain.setRunningTime(runningTime);
virtualRealityTrain.setReleased(released);
@Override
public void recover2Simulation(MapElement element, Simulation simulation, SimulationDataRepository repository) {
VirtualRealityTrain virtualRealityTrain = (VirtualRealityTrain) element;
virtualRealityTrain.setNoCommunicateDevice(noCommunicateDevice);
virtualRealityTrain.setCommunication(communication);
virtualRealityTrain.setRunLevel(runLevel);
virtualRealityTrain.setDriveMode(driveMode);
virtualRealityTrain.setTempPreselectionMode(tempPreselectionMode);
virtualRealityTrain.setPreselectionMode(preselectionMode);
virtualRealityTrain.setServiceNumber(serviceNumber);
virtualRealityTrain.setTripNumber(tripNumber);
virtualRealityTrain.setDestinationCode(destinationCode);
if (nextStationCode != null) {
virtualRealityTrain.setNextStation(repository.getByCode(nextStationCode, Station.class));
}
virtualRealityTrain.setBeAbout2Arrive(beAbout2Arrive);
if (targetCode != null) {
virtualRealityTrain.setTarget(repository.getByCode(targetCode, Section.class));
}
virtualRealityTrain.setParkTime(parkTime);
virtualRealityTrain.setParkRemainTime(parkRemainTime);
if (parkSectionCode != null) {
virtualRealityTrain.setParkSection(repository.getByCode(parkSectionCode, Section.class));
}
virtualRealityTrain.setDeparture(departure);
virtualRealityTrain.setBreaking(breaking);
if (terminalStationCode != null) {
virtualRealityTrain.setTerminalStation(repository.getByCode(terminalStationCode, Station.class));
}
if (headPosition != null) {
virtualRealityTrain.setHeadPosition(headPosition.convert2SimulationObj(repository));
}
if (tailPosition != null) {
virtualRealityTrain.setTailPosition(tailPosition.convert2SimulationObj(repository));
}
virtualRealityTrain.setRight(right);
if (ma != null) {
virtualRealityTrain.setMa(ma.convert2SimulationObj(repository));
}
if (ma2 != null) {
virtualRealityTrain.setMa2(ma2.convert2SimulationObj(repository));
}
virtualRealityTrain.setCbtcMaMissDuration(cbtcMaMissDuration);
virtualRealityTrain.setGear(gear);
virtualRealityTrain.setSpeed(speed);
virtualRealityTrain.setLocationKM(locationKM);
virtualRealityTrain.setTargetDistance(targetDistance);
virtualRealityTrain.setAtoSpeedMax(atoSpeedMax);
virtualRealityTrain.setAtoSpeed(atoSpeed);
virtualRealityTrain.setAtpSpeed(atpSpeed);
virtualRealityTrain.setSignalEB(signalEB);
virtualRealityTrain.setCircuitEB(circuitEB);
virtualRealityTrain.setStandParkedTrainActivity(standParkedTrainActivity);
virtualRealityTrain.setNextParking(nextParking);
virtualRealityTrain.setJump(jump);
virtualRealityTrain.setHold(hold);
virtualRealityTrain.setTrainHold(trainHold);
virtualRealityTrain.setDtro(dtro);
virtualRealityTrain.setChangeEnds(changeEnds);
virtualRealityTrain.setChangeEndsRemainTime(changeEndsRemainTime);
virtualRealityTrain.setAtoOn(atoOn);
virtualRealityTrain.setAtpOn(atpOn);
virtualRealityTrain.setPriorityRouteSet(priorityRouteSet);
if (door1 != null) {
door1.recover2Simulation(virtualRealityTrain.getDoor1());
}
if (door2 != null) {
door2.recover2Simulation(virtualRealityTrain.getDoor2());
}
virtualRealityTrain.setDoorMode(doorMode);
virtualRealityTrain.setDoorSelection(doorSelection);
virtualRealityTrain.setFk(fk);
virtualRealityTrain.setFb(fb);
virtualRealityTrain.setTbControl(tbControl);
virtualRealityTrain.setLeverPosition(leverPosition);
virtualRealityTrain.setFault(fault);
virtualRealityTrain.setBackUp(backUp);
virtualRealityTrain.setDelayTime(delayTime);
virtualRealityTrain.setPowerOn(powerOn);
virtualRealityTrain.setPantograph1Up(pantograph1Up);
virtualRealityTrain.setPantograph2Up(pantograph2Up);
if (linkTrainCode != null) {
virtualRealityTrain.setLinkTrain(repository.getByCode(linkTrainCode, VirtualRealityTrain.class));
}
virtualRealityTrain.setRunType(runType);
virtualRealityTrain.setOrderStop(orderStop);
virtualRealityTrain.setNeedDepartureCommand(needDepartureCommand);
virtualRealityTrain.setPositioned(positioned);
virtualRealityTrain.setRunningTime(runningTime);
virtualRealityTrain.setReleased(released);
if (!CollectionUtils.isEmpty(confirmationMessages)) {
confirmationMessages.forEach(virtualRealityTrain::addMessage);
}
virtualRealityTrain.setAtoCanOpen(atoCanOpen);
}
/**
* 构建关联关系信息
*/
public void recover2RelationSimulation(MapElement element, Simulation simulation,
SimulationDataRepository repository) {
VirtualRealityTrain virtualRealityTrain = (VirtualRealityTrain) element;
if (ma != null) {
virtualRealityTrain.setMa(ma.convert2SimulationObj(repository));
}
if (ma2 != null) {
virtualRealityTrain.setMa2(ma2.convert2SimulationObj(repository));
}
if (door1 != null) {
door1.recover2Simulation(virtualRealityTrain.getDoor1());
}
if (door2 != null) {
door2.recover2Simulation(virtualRealityTrain.getDoor2());
}
if (linkTrainCode != null) {
virtualRealityTrain.setLinkTrain(
repository.getByCode(linkTrainCode, VirtualRealityTrain.class));
}
if (!CollectionUtils.isEmpty(confirmationMessages)) {
confirmationMessages.forEach(virtualRealityTrain::addMessage);
}
virtualRealityTrain.setAtoCanOpen(atoCanOpen);
// if (vrAudioCode != null) {
// virtualRealityTrain.setVrAudio(repository.getByCode(vrAudioCode, VirtualRealityAudio.class));
// }
if (robotDriveParam != null) {
virtualRealityTrain.setRobotDriveParam(robotDriveParam.convert2SimulationObj(repository));
}
if (robotDriveParam != null) {
virtualRealityTrain.setRobotDriveParam(robotDriveParam.convert2SimulationObj(repository));
}
}
}

View File

@ -14,15 +14,14 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.virtual.VirtualRealityDeviceService;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService;
import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
/**
* 速度控制服务
*/
@ -30,266 +29,301 @@ import java.util.Objects;
@Slf4j
public class ATOService {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private VirtualRealityDeviceService virtualRealityDeviceService;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private VirtualRealityDeviceService virtualRealityDeviceService;
@Autowired
private CiApiService ciApiService;
@Autowired
private CiApiService ciApiService;
@Autowired
private OnboardAtpApiService onboardAtpApiService;
@Autowired
private OnboardAtpApiService onboardAtpApiService;
public void ato2(VirtualRealityTrain train) {
if (!train.isPowerOn() || !train.isAtoOn()) {
return;
}
//下令停车
if (train.isOrderStop()) {
this.doBreakMax(train);
return;
}
// 是否EB
if (train.isEB()) { // EB中不控制
return;
}
// 站台是否扣车
if (
public void ato2(VirtualRealityTrain train) {
if (!train.isPowerOn() || !train.isAtoOn()) {
return;
}
//下令停车
if (train.isOrderStop()) {
this.doBreakMax(train);
return;
}
// 是否EB
if (train.isEB()) { // EB中不控制
return;
}
// 站台是否扣车
if (
// train.isHold() &&
train.isParkingAt() &&
train.getHeadPosition().getSection().isStandHoldTrain()) {
return;
}
// 是否停车制动
if (train.isBreaking()) { // 站台持续停车制动中输出持续制动
doBreakMax(train);
return;
}
if (train.getTarget() == null)
return;
if (train.isReleased()) { // 列车释放以低速行驶
SpeedCurve.SpeedCalculator limitSpeedCalculator = SpeedCurve.getLimitSpeedCalculator(SpeedCurve.Release_Limit_Speed);
train.setAtoSpeed(limitSpeedCalculator.getVt());
this.doControlBySpeedCalculator(train, limitSpeedCalculator, limitSpeedCalculator.getVt());
return;
}
MaService.Ma ma = train.getMa2();
if (ma == null) {
return;
}
SpeedCurve speedCurve = ma.getAtoStopCurve();
if (speedCurve == null) {
return;
}
// 更新目标距离
train.setTargetDistance(speedCurve.getTotalDistance());
this.doControlBySpeedCurve(train, speedCurve, speedCurve.getTotalDistance());
train.isParkingAt() &&
train.getHeadPosition().getSection().isStandHoldTrain()) {
return;
}
public static Float calculateDistanceOfMa(SectionPosition headPosition, boolean right, MovementAuthority ma) {
Objects.requireNonNull(ma);
// ATP安全防护最远可达到位置
SectionPosition endPosition = ma.getEnd().getEndPosition();
return CalculateService.calculateDistance(headPosition, endPosition, right, false);
// 是否停车制动
if (train.isBreaking()) { // 站台持续停车制动中输出持续制动
doBreakMax(train);
return;
}
public void doControlBySpeedCurve(VirtualRealityTrain train, SpeedCurve speedCurve, float remainDistance) {
doControlBySpeedCurve(train, speedCurve, remainDistance, train.getAtoSpeed());
if (train.getTarget() == null) {
return;
}
public void doControlBySpeedCurve(VirtualRealityTrain train, SpeedCurve speedCurve, float remainDistance, float atoSpeed) {
if (speedCurve.equals(SpeedCurve.ZERO)) {
this.doBreakMax(train);
return;
}
SpeedCurve.SpeedCalculator calculator = speedCurve.getCalculatorOf(remainDistance);
if (calculator.getVt() == 0 && remainDistance <= SimulationConstants.PARK_POINT_MAX_OFFSET) { //末速度为0且当前距终点距离在停车误差内
this.doBreakMax(train);
return;
}
float speed = train.getSpeed();
if (speed == 0) {
this.doStart(train);
return;
}
this.doControlBySpeedCalculator(train, calculator, atoSpeed);
if (train.isReleased()) { // 列车释放以低速行驶
SpeedCurve.SpeedCalculator limitSpeedCalculator = SpeedCurve.getLimitSpeedCalculator(
SpeedCurve.Release_Limit_Speed);
train.setAtoSpeed(limitSpeedCalculator.getVt());
this.doControlBySpeedCalculator(train, limitSpeedCalculator, limitSpeedCalculator.getVt());
return;
}
public void doControlBySpeedCalculator(VirtualRealityTrain train, SpeedCurve.SpeedCalculator calculator,
float suggestSpeed) {
float speed = train.getSpeed();
float acceleration = calculator.getAcceleration();
float diff = speed - suggestSpeed;
if (acceleration == 0) { //匀速段
if (diff <= -0.1) { //当前速度远小于目标速度
this.doAccelerateMax(train);
} else if (diff < 0) { //当前速度略小于目标速度
this.doAccelerate(train, 0.1f);
} else if (0 == diff) {
this.doIdle(train);
} else if (diff < 0.1) { //当前速度略大于目标速度
this.doBreak(train, 0.1f);
} else {
this.doBreakMax(train); //当前速度远大于目标速度
}
} else { //减速段
if (diff <= -0.1) { //当前速度远小于目标速度
this.doAccelerateMax(train);
} else if (diff < 0) { //当前速度略小于目标速度
this.doBreak(train, Math.abs(acceleration) - 0.1f);
} else if (0 == diff) {
this.doBreak(train, Math.abs(acceleration));
} else if (diff < 0.1) { //当前速度略大于目标速度
this.doBreak(train, Math.abs(acceleration) + 0.1f);
} else {
this.doBreakMax(train); //当前速度远大于目标速度
}
}
MaService.Ma ma = train.getMa2();
if (ma == null) {
return;
}
/**
* 列车启动
*
* @param train
*/
private void doStart(VirtualRealityTrain train) {
train.updateTBForce(350, 0);
SpeedCurve speedCurve = ma.getAtoStopCurve();
if (speedCurve == null) {
return;
}
// 更新目标距离
train.setTargetDistance(speedCurve.getTotalDistance());
this.doControlBySpeedCurve(train, speedCurve, speedCurve.getTotalDistance());
}
/**
* 惰行不牵引不制动
*
* @param train
*/
private void doIdle(VirtualRealityTrain train) {
train.updateTBForce(0, 0);
public static Float calculateDistanceOfMa(SectionPosition headPosition, boolean right,
MovementAuthority ma) {
Objects.requireNonNull(ma);
// ATP安全防护最远可达到位置
SectionPosition endPosition = ma.getEnd().getEndPosition();
return CalculateService.calculateDistance(headPosition, endPosition, right, false);
}
public void doControlBySpeedCurve(VirtualRealityTrain train, SpeedCurve speedCurve,
float remainDistance) {
doControlBySpeedCurve(train, speedCurve, remainDistance, train.getAtoSpeed());
}
public void doControlBySpeedCurve(VirtualRealityTrain train, SpeedCurve speedCurve,
float remainDistance, float atoSpeed) {
if (speedCurve.equals(SpeedCurve.ZERO)) {
this.doBreakMax(train);
return;
}
private void doAccelerateMax(VirtualRealityTrain train) {
this.doAccelerate(train, VirtualRealityTrain.Stable_Acceleration);
SpeedCurve.SpeedCalculator calculator = speedCurve.getCalculatorOf(remainDistance);
if (calculator.getVt() == 0
&& remainDistance <= SimulationConstants.PARK_POINT_MAX_OFFSET) { //末速度为0且当前距终点距离在停车误差内
this.doBreakMax(train);
return;
}
/**
* 列车加速
*
* @param train
* @param a
*/
private void doAccelerate(VirtualRealityTrain train, float a) {
float fk = train.getMass() * a;
float fkMax = train.getCurrentFkMax();
if (fk > fkMax) {
fk = fkMax;
}
train.updateTBForce(fk, 0);
float speed = train.getSpeed();
if (speed == 0) {
this.doStart(train);
return;
}
this.doControlBySpeedCalculator(train, calculator, atoSpeed);
}
public void doBreakMax(VirtualRealityTrain train) {
float fbMax = train.getCurrentFbMax();
train.updateTBForce(0, fbMax);
public void doControlBySpeedCalculator(VirtualRealityTrain train,
SpeedCurve.SpeedCalculator calculator,
float suggestSpeed) {
float speed = train.getSpeed();
float acceleration = calculator.getAcceleration();
float diff = speed - suggestSpeed;
if (acceleration == 0) { //匀速段
if (diff <= -0.1) { //当前速度远小于目标速度
this.doAccelerateMax(train);
} else if (diff < 0) { //当前速度略小于目标速度
this.doAccelerate(train, 0.1f);
} else if (0 == diff) {
this.doIdle(train);
} else if (diff < 0.1) { //当前速度略大于目标速度
this.doBreak(train, 0.1f);
} else {
this.doBreakMax(train); //当前速度远大于目标速度
}
} else { //减速段
if (diff <= -0.1) { //当前速度远小于目标速度
this.doAccelerateMax(train);
} else if (diff < 0) { //当前速度略小于目标速度
this.doBreak(train, Math.abs(acceleration) - 0.1f);
} else if (0 == diff) {
this.doBreak(train, Math.abs(acceleration));
} else if (diff < 0.1) { //当前速度略大于目标速度
this.doBreak(train, Math.abs(acceleration) + 0.1f);
} else {
this.doBreakMax(train); //当前速度远大于目标速度
}
}
}
/**
* 列车制动
*
* @param train
* @param a
*/
private void doBreak(VirtualRealityTrain train, float a) {
float fb = train.getMass() * a;
float fbMax = train.getCurrentFbMax();
if (fb > fbMax) {
fb = fbMax;
}
train.updateTBForce(0, fb);
/**
* 列车启动
*
* @param train
*/
private void doStart(VirtualRealityTrain train) {
train.updateTBForce(350, 0);
}
/**
* 惰行不牵引不制动
*
* @param train
*/
private void doIdle(VirtualRealityTrain train) {
train.updateTBForce(0, 0);
}
private void doAccelerateMax(VirtualRealityTrain train) {
this.doAccelerate(train, VirtualRealityTrain.Stable_Acceleration);
}
/**
* 列车加速
*
* @param train
* @param a
*/
private void doAccelerate(VirtualRealityTrain train, float a) {
float fk = train.getMass() * a;
float fkMax = train.getCurrentFkMax();
if (fk > fkMax) {
fk = fkMax;
}
train.updateTBForce(fk, 0);
}
public void openBreaking(VirtualRealityTrain train) {
public void doBreakMax(VirtualRealityTrain train) {
float fbMax = train.getCurrentFbMax();
train.updateTBForce(0, fbMax);
}
/**
* 列车制动
*
* @param train
* @param a
*/
private void doBreak(VirtualRealityTrain train, float a) {
float fb = train.getMass() * a;
float fbMax = train.getCurrentFbMax();
if (fb > fbMax) {
fb = fbMax;
}
train.updateTBForce(0, fb);
}
public void openBreaking(VirtualRealityTrain train) {
// log.debug(String.format("列车[%s-%s|%s|%s]制动",
// train.getGroupNumber(), train.getServiceNumber(), train.getTripNumber(), train.getDestinationCode()));
train.setBreaking(true);
this.doBreakMax(train);
}
train.setBreaking(true);
this.doBreakMax(train);
}
public void closeBreaking(VirtualRealityTrain train) {
public void closeBreaking(VirtualRealityTrain train) {
// log.debug(String.format("列车[%s-%s|%s|%s]取消制动",
// train.getGroupNumber(), train.getServiceNumber(), train.getTripNumber(), train.getDestinationCode()));
train.setBreaking(false);
}
train.setBreaking(false);
}
/**
* 开启车门和站台屏蔽门
*
* @param simulation
* @param train
*/
public void syncOpenDoor(Simulation simulation, VirtualRealityTrain train) {
Section section = train.getHeadPosition().getSection();
if (!section.isNormalStandTrack()) { // 非正常站台轨不开门
return;
}
List<Stand> standList = section.getStandList();
if (!CollectionUtils.isEmpty(standList) && standList.size() == 1 && standList.get(0).isSmall()) {
// 小站台停车不用开门
return;
}
// 根据站台方向位置和列车方向同步开屏蔽门车门
for (Stand stand : standList) {
if (stand.isInside() && stand.isRight()) { // 内测右站台开1门
this.openTrainDoor(simulation, train, train.getDoor1());
} else if (stand.isInside() && !stand.isRight()) { // 内测左站台开2门
this.openTrainDoor(simulation, train, train.getDoor2());
} else if (!stand.isInside() && stand.isRight()) { //外侧右站台开2门
this.openTrainDoor(simulation, train, train.getDoor2());
} else {
this.openTrainDoor(simulation, train, train.getDoor1());
}
this.ciApiService.openScreenDoor(simulation, stand.getCode(), CiStandService.PsdCommandSource.SIG);
}
/**
* 开启车门和站台屏蔽门
*
* @param simulation
* @param train
*/
public void syncOpenDoor(Simulation simulation, VirtualRealityTrain train) {
Section section = train.getHeadPosition().getSection();
if (!section.isNormalStandTrack()) { // 非正常站台轨不开门
return;
}
List<Stand> standList = section.getStandList();
if (!CollectionUtils.isEmpty(standList) && standList.size() == 1 && standList.get(0)
.isSmall()) {
// 小站台停车不用开门
return;
}
// 根据站台方向位置和列车方向同步开屏蔽门车门
for (Stand stand : standList) {
if (stand.isInside() && stand.isRight()) { // 内测右站台开1门
this.openTrainDoor(simulation, train, train.getDoor1());
} else if (stand.isInside() && !stand.isRight()) { // 内测左站台开2门
this.openTrainDoor(simulation, train, train.getDoor2());
} else if (!stand.isInside() && stand.isRight()) { //外侧右站台开2门
this.openTrainDoor(simulation, train, train.getDoor2());
} else {
this.openTrainDoor(simulation, train, train.getDoor1());
}
this.ciApiService.openScreenDoor(simulation, stand.getCode(),
CiStandService.PsdCommandSource.SIG);
}
}
/**
* 关闭车门和站台屏蔽门
*/
public void syncCloseDoor(Simulation simulation, VirtualRealityTrain train) {
List<Stand> standList = train.getHeadPosition().getSection().getStandList();
if (!CollectionUtils.isEmpty(standList) && standList.size() == 1 && standList.get(0).isSmall()) {
// 小站台停车不用关门
return;
}
// 关闭站台屏蔽门
if (!train.getDoor1().isCloseAndLock()) {
this.closeTrainDoor(simulation, train, train.getDoor1());
}
if (!train.getDoor2().isCloseAndLock()) {
this.closeTrainDoor(simulation, train, train.getDoor2());
}
for (Stand stand : standList) {
this.ciApiService.closeScreenDoor(simulation, stand.getCode(), CiStandService.PsdCommandSource.SIG);
}
// 站台跳停全部跳停或者站台列车在此站台跳停不开门
public boolean isTrainSkipStand(Simulation simulation, VirtualRealityTrain train) {
Section section = train.getHeadPosition().getSection();
if (!section.isNormalStandTrack()) { // 非正常站台轨不开门
return false;
}
List<Stand> standList = section.getStandList();
if (!CollectionUtils.isEmpty(standList) && standList.size() == 1 && standList.get(0)
.isSmall()) {
// 小站台停车不用开门
return false;
}
for (Stand stand : standList) {
if (stand.isAllSkip() || stand.getSkipSet().contains(train.getGroupNumber())) {
return true;
}
}
return false;
}
public void openTrainDoor(Simulation simulation, VirtualRealityTrain train, VirtualRealityTrain.Door door) {
if (door.isOpening() || door.isOpen()) {
return;
}
this.virtualRealityDeviceService.control(simulation, door, VirtualRealityTrain.Door.Operation.K);
log.debug(String.format("列车[%s-%s|%s|%s]开门[%s]",
train.getGroupNumber(), train.getServiceNumber(),
train.getTripNumber(), train.getDestinationCode(),
door.getCode()));
/**
* 关闭车门和站台屏蔽门
*/
public void syncCloseDoor(Simulation simulation, VirtualRealityTrain train) {
List<Stand> standList = train.getHeadPosition().getSection().getStandList();
if (!CollectionUtils.isEmpty(standList) && standList.size() == 1 && standList.get(0)
.isSmall()) {
// 小站台停车不用关门
return;
}
// 关闭站台屏蔽门
if (!train.getDoor1().isCloseAndLock()) {
this.closeTrainDoor(simulation, train, train.getDoor1());
}
if (!train.getDoor2().isCloseAndLock()) {
this.closeTrainDoor(simulation, train, train.getDoor2());
}
for (Stand stand : standList) {
this.ciApiService.closeScreenDoor(simulation, stand.getCode(),
CiStandService.PsdCommandSource.SIG);
}
}
public void closeTrainDoor(Simulation simulation, VirtualRealityTrain train, VirtualRealityTrain.Door door) {
if (door.isClosing() || door.isClose()) {
return;
}
this.virtualRealityDeviceService.control(simulation, door, VirtualRealityTrain.Door.Operation.G);
log.debug(String.format("列车[%s-%s|%s|%s]关门[%s]",
train.getGroupNumber(), train.getServiceNumber(),
train.getTripNumber(), train.getDestinationCode(),
door.getCode()));
public void openTrainDoor(Simulation simulation, VirtualRealityTrain train,
VirtualRealityTrain.Door door) {
if (door.isOpening() || door.isOpen()) {
return;
}
this.virtualRealityDeviceService.control(simulation, door,
VirtualRealityTrain.Door.Operation.K);
log.debug(String.format("列车[%s-%s|%s|%s]开门[%s]",
train.getGroupNumber(), train.getServiceNumber(),
train.getTripNumber(), train.getDestinationCode(),
door.getCode()));
}
public void closeTrainDoor(Simulation simulation, VirtualRealityTrain train,
VirtualRealityTrain.Door door) {
if (door.isClosing() || door.isClose()) {
return;
}
this.virtualRealityDeviceService.control(simulation, door,
VirtualRealityTrain.Door.Operation.G);
log.debug(String.format("列车[%s-%s|%s|%s]关门[%s]",
train.getGroupNumber(), train.getServiceNumber(),
train.getTripNumber(), train.getDestinationCode(),
door.getCode()));
}
}

View File

@ -233,6 +233,10 @@ public class ATPLogicLoop {
}
break;
case OPEN_DOOR: // 开门
if (this.atoService.isTrainSkipStand(simulation, train)) {
train.nextParkedTrainActivity();
break;
}
if (train.isAutoOpenDoor()) {
this.atoService.syncOpenDoor(simulation, train);
}
@ -281,6 +285,7 @@ public class ATPLogicLoop {
List<Stand> standList = section.getStandList();
if (!CollectionUtils.isEmpty(standList)) {
for (Stand stand : standList) {
boolean trainDoorOpen = false;
if (stand.isInside() && stand.isRight()) { // 内测右站台开1门
trainDoorOpen = train.getDoor1().isOpen();