Browse Source

fixed bug in BrakeProcessor

lookup-tables
Stephan Richter 4 years ago
parent
commit
629b30c078
  1. 2
      pom.xml
  2. 11
      src/main/java/de/srsoftware/web4rail/moving/Train.java
  3. 7
      src/main/java/de/srsoftware/web4rail/threads/BrakeProcessor.java

2
pom.xml

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

11
src/main/java/de/srsoftware/web4rail/moving/Train.java

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

7
src/main/java/de/srsoftware/web4rail/threads/BrakeProcessor.java

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

Loading…
Cancel
Save