fixed bug in BrakeProcessor

This commit is contained in:
Stephan Richter
2021-03-12 17:10:15 +01:00
parent 9effb8d337
commit 629b30c078
3 changed files with 12 additions and 8 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId> <groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId> <artifactId>web4rail</artifactId>
<version>1.3.58</version> <version>1.3.59</version>
<name>Web4Rail</name> <name>Web4Rail</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Java Model Railway Control</description> <description>Java Model Railway Control</description>

View File

@@ -402,8 +402,9 @@ public class Train extends BaseClass implements Comparable<Train> {
} }
public void endRoute(Block newBlock, Direction newDirection) { public void endRoute(Block newBlock, Direction newDirection) {
setSpeed(0); if (isSet(brakeProcessor)) {
if (isSet(brakeProcessor)) brakeProcessor.end(); brakeProcessor.end();
} else setSpeed(0);
set(newBlock); set(newBlock);
if (newBlock == destination) { if (newBlock == destination) {
destination = null; destination = null;
@@ -708,8 +709,9 @@ public class Train extends BaseClass implements Comparable<Train> {
} }
public void reserveNext() { public void reserveNext() {
// TODO LOG.debug("{}.reserveNext()",this);
} }
/** /**
* This turns the train as if it went through a loop. Example: * This turns the train as if it went through a loop. Example:
* before: CabCar→ MiddleCar→ Loco→ * before: CabCar→ MiddleCar→ Loco→
@@ -882,7 +884,8 @@ public class Train extends BaseClass implements Comparable<Train> {
public String start(boolean autopilot) { public String start(boolean autopilot) {
this.autopilot |= autopilot; this.autopilot |= autopilot;
if (isSet(route)) return t("{} already on {}!",this,route);
if (isSet(pathFinder)) return t("Pathfinder already active for {}!",this); if (isSet(pathFinder)) return t("Pathfinder already active for {}!",this);
PathFinder pathFinder = new PathFinder(this,currentBlock,direction) { PathFinder pathFinder = new PathFinder(this,currentBlock,direction) {

View File

@@ -36,16 +36,17 @@ public class BrakeProcessor extends BaseClass implements Runnable {
public void end() { public void end() {
state = State.ENDED; state = State.ENDED;
measuredDistance += train.speed * (BaseClass.timestamp() - lastTime); measuredDistance += train.speed * (BaseClass.timestamp() - lastTime);
train.setSpeed(0);
Route route = train.route(); Route route = train.route();
if (isNull(route)) return; if (isNull(route)) return;
LOG.debug("old brake time: {}, measured distance: {}", brakeTime, measuredDistance); LOG.debug("old brake time: {}, measured distance: {}", brakeTime, measuredDistance);
int step = brakeTime; int step = brakeTime;
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
long calculatedDistance = calculate(brakeTime, startSpeed); long calculatedDistance = calculate(brakeTime, startSpeed);
if (measuredDistance > calculatedDistance) brakeTime += brakeTime/2; step /= 2;
if (step < 1) step = 1;
if (measuredDistance > calculatedDistance) brakeTime += step;
if (measuredDistance < calculatedDistance) { if (measuredDistance < calculatedDistance) {
step /= 2;
if (step < 1) step = 1;
brakeTime -= step; brakeTime -= step;
} }
LOG.debug("new brake time: {}, calculated distance: {}", brakeTime, calculatedDistance); LOG.debug("new brake time: {}, calculated distance: {}", brakeTime, calculatedDistance);