This commit is contained in:
DU 2021-03-10 17:58:39 +08:00
commit 0a126f41a6
6 changed files with 51 additions and 18 deletions

View File

@ -0,0 +1,7 @@
package club.joylink.rtss.simulation;
public interface Debug {
String debugStr();
}

View File

@ -415,11 +415,19 @@ public class AtsTrainLoadService {
for (int i = 1; i < stationPlanList.size(); i++) { for (int i = 1; i < stationPlanList.size(); i++) {
StationPlan startStationPlan = stationPlanList.get(i - 1); StationPlan startStationPlan = stationPlanList.get(i - 1);
StationPlan endStationPlan = stationPlanList.get(i); StationPlan endStationPlan = stationPlanList.get(i);
if (this.isOnSectionStopPoint(headPosition, startStationPlan.getSection(), right)) { Section startSection = startStationPlan.getSection();
// 在计划停车点 if (this.isOnSectionStopPoint(headPosition, startSection, right)) {
trainInfo.updatePlanInfo(startStationPlan); if (startSection.isTransferTrack()) {
trainInfo.updateEstimatedArriveInfo(startStationPlan.getSection(), startStationPlan.getArriveTime()); // 列车出库
train.updateNextStationPlan(startStationPlan.getStation(), startStationPlan.getSection(), tripPlan.isPlanParking(startStationPlan)); trainInfo.updatePlanInfo(endStationPlan);
trainInfo.updateEstimatedArriveInfo(endStationPlan.getSection(), endStationPlan.getArriveTime());
train.updateNextStationPlan(endStationPlan.getStation(), endStationPlan.getSection(), tripPlan.isPlanParking(endStationPlan));
} else {
// 在计划停车点
trainInfo.updatePlanInfo(startStationPlan);
trainInfo.updateEstimatedArriveInfo(startSection, startStationPlan.getArriveTime());
train.updateNextStationPlan(startStationPlan.getStation(), startSection, tripPlan.isPlanParking(startStationPlan));
}
break; break;
} else if (this.isOnSectionStopPoint(headPosition, endStationPlan.getSection(), right)) { } else if (this.isOnSectionStopPoint(headPosition, endStationPlan.getSection(), right)) {
trainInfo.updatePlanInfo(endStationPlan); trainInfo.updatePlanInfo(endStationPlan);
@ -427,7 +435,7 @@ public class AtsTrainLoadService {
train.updateNextStationPlan(endStationPlan.getStation(), endStationPlan.getSection(), tripPlan.isPlanParking(endStationPlan)); train.updateNextStationPlan(endStationPlan.getStation(), endStationPlan.getSection(), tripPlan.isPlanParking(endStationPlan));
break; break;
} else { } else {
RoutePath routePath = this.selectDefaultRoutePath(repository, startStationPlan.getSection(), endStationPlan.getSection()); RoutePath routePath = this.selectDefaultRoutePath(repository, startSection, endStationPlan.getSection());
if (routePath.containsPosition(headPosition)) { if (routePath.containsPosition(headPosition)) {
// 站间运行 // 站间运行
train.setSpeed(0.1f); train.setSpeed(0.1f);

View File

@ -4,10 +4,12 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.srd.bo.*; import club.joylink.rtss.simulation.rt.srd.bo.*;
import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.map.MapVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@Slf4j
@Component @Component
public class SrdService { public class SrdService {
public static final int TRAIN_RUN_RATE = 20; public static final int TRAIN_RUN_RATE = 20;
@ -29,8 +31,7 @@ public class SrdService {
if (!srTrain.isUsing()) { if (!srTrain.isUsing()) {
continue; continue;
} }
TrackPosition position = srTrain.getPosition(); TrackPosition position = srTrain.getHeadPosition();
long speed = srTrain.getSpeed();
boolean right = srTrain.isRight(); boolean right = srTrain.isRight();
int cv = this.calculateSpeed(srTrain); int cv = this.calculateSpeed(srTrain);
int s = this.calculateLen(cv, TRAIN_RUN_RATE); int s = this.calculateLen(cv, TRAIN_RUN_RATE);
@ -77,7 +78,8 @@ public class SrdService {
SrTrack base = track; SrTrack base = track;
while (offset < 0 || offset > base.getLen()) { while (offset < 0 || offset > base.getLen()) {
SrTrack nextTrack = base.queryNextTrack(right); SrTrack nextTrack = base.queryNextTrack(right);
if (nextTrack == null) { if (nextTrack == null) { // 下一区段为空到达尽头或道岔失表处
log.debug(String.format("区段[%s][%s]区段不存在",base.debugStr(), right?"右向":"左向"));
if (offset < 0) { if (offset < 0) {
offset = 0; offset = 0;
} else { } else {
@ -86,10 +88,10 @@ public class SrdService {
break; break;
} else { } else {
if (right) { if (right) {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(offset < 0); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(offset > base.getLen());
offset -= base.getLen(); offset -= base.getLen();
} else { } else {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(offset > base.getLen()); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(offset < 0);
offset += nextTrack.getLen(); offset += nextTrack.getLen();
} }
base = nextTrack; base = nextTrack;

View File

@ -1,12 +1,13 @@
package club.joylink.rtss.simulation.rt.srd.bo; package club.joylink.rtss.simulation.rt.srd.bo;
import club.joylink.rtss.simulation.Debug;
import lombok.Getter; import lombok.Getter;
/** /**
* 虚拟真实设备抽象父类 * 虚拟真实设备抽象父类
*/ */
@Getter @Getter
public abstract class SrDevice { public abstract class SrDevice implements Debug {
String id; String id;
DeviceType deviceType; DeviceType deviceType;
@ -16,4 +17,9 @@ public abstract class SrDevice {
this.id = id; this.id = id;
this.deviceType = deviceType; this.deviceType = deviceType;
} }
@Override
public String debugStr() {
return String.format("%s:%s", this.deviceType, this.id);
}
} }

View File

@ -1,13 +1,15 @@
package club.joylink.rtss.simulation.rt.srd.bo; package club.joylink.rtss.simulation.rt.srd.bo;
import club.joylink.rtss.simulation.Debug;
import lombok.Getter; import lombok.Getter;
/** /**
* 虚拟真实轨道区段 * 虚拟真实轨道区段
*/ */
@Getter @Getter
public class SrTrack extends SrDevice { public class SrTrack extends SrDevice implements Debug {
String name;
/** /**
* 轨道长度单位mm * 轨道长度单位mm
*/ */
@ -101,4 +103,9 @@ public class SrTrack extends SrDevice {
} }
return null; return null;
} }
@Override
public String debugStr() {
return String.format("%s(%s)", this.name, this.id);
}
} }

View File

@ -56,11 +56,14 @@ public class SrTrain extends SrDevice {
public static final int FORWARD = 1; //前进挡 public static final int FORWARD = 1; //前进挡
public static final int REVERSE = -1; //后退档 public static final int REVERSE = -1; //后退档
/** /**
* 列车位置 * 列车位置
*/ */
TrackPosition position; TrackPosition headPosition;
/**
public SrTrain(String id, int len) { * 列车尾位置
*/
TrackPosition tailPosition;
public SrTrain(String id, int len) {
super(id, DeviceType.TRAIN); super(id, DeviceType.TRAIN);
this.len = len; this.len = len;
} }
@ -70,7 +73,7 @@ public class SrTrain extends SrDevice {
} }
public void updatePositionAndSpeed(TrackPosition position, int v) { public void updatePositionAndSpeed(TrackPosition position, int v) {
this.position = position; this.headPosition = position;
this.speed = v; this.speed = v;
} }
} }