re-implemented basic autopilot
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -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.57</version>
|
<version>1.3.58</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>
|
||||||
|
|||||||
@@ -378,11 +378,9 @@ public class Route extends BaseClass {
|
|||||||
|
|
||||||
public void finish(Train train) {
|
public void finish(Train train) {
|
||||||
LOG.debug("{}.finish()",this);
|
LOG.debug("{}.finish()",this);
|
||||||
train.endRoute();
|
train.endRoute(endBlock,endDirection);
|
||||||
free();
|
|
||||||
train.set(endBlock);
|
|
||||||
train.heading(endDirection);
|
|
||||||
train = null;
|
train = null;
|
||||||
|
free();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void free() {
|
private void free() {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class StartStopAuto extends Action {
|
|||||||
public boolean fire(Context context,Object cause) {
|
public boolean fire(Context context,Object cause) {
|
||||||
if (isNull(context.train())) return false;
|
if (isNull(context.train())) return false;
|
||||||
if (inverted) {
|
if (inverted) {
|
||||||
context.train().automatic();
|
context.train().start(true);
|
||||||
} else context.train().quitAutopilot();
|
} else context.train().quitAutopilot();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
private PathFinder pathFinder;
|
private PathFinder pathFinder;
|
||||||
|
|
||||||
|
private boolean autopilot = false;
|
||||||
|
|
||||||
public static Object action(HashMap<String, String> params, Plan plan) throws IOException {
|
public static Object action(HashMap<String, String> params, Plan plan) throws IOException {
|
||||||
String action = params.get(ACTION);
|
String action = params.get(ACTION);
|
||||||
if (isNull(action)) return t("No action passed to Train.action!");
|
if (isNull(action)) return t("No action passed to Train.action!");
|
||||||
@@ -115,7 +117,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
case ACTION_ADD:
|
case ACTION_ADD:
|
||||||
return train.addCar(params);
|
return train.addCar(params);
|
||||||
case ACTION_AUTO:
|
case ACTION_AUTO:
|
||||||
return train.automatic();
|
return train.start(true);
|
||||||
case ACTION_CONNECT:
|
case ACTION_CONNECT:
|
||||||
return train.connect(params);
|
return train.connect(params);
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
@@ -135,14 +137,13 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return train.properties();
|
return train.properties();
|
||||||
case ACTION_QUIT:
|
case ACTION_QUIT:
|
||||||
return train.quitAutopilot();
|
return train.properties(train.quitAutopilot());
|
||||||
case ACTION_REVERSE:
|
case ACTION_REVERSE:
|
||||||
return train.reverse().properties();
|
return train.reverse().properties();
|
||||||
case ACTION_SLOWER10:
|
case ACTION_SLOWER10:
|
||||||
return train.slower(10);
|
return train.slower(10);
|
||||||
case ACTION_START:
|
case ACTION_START:
|
||||||
String error = train.start();
|
return train.properties(train.start(false));
|
||||||
return train.properties(error);
|
|
||||||
case ACTION_STOP:
|
case ACTION_STOP:
|
||||||
return train.stopNow();
|
return train.stopNow();
|
||||||
case ACTION_TIMES:
|
case ACTION_TIMES:
|
||||||
@@ -177,10 +178,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean automatic() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Fieldset blockHistory() {
|
private Fieldset blockHistory() {
|
||||||
Fieldset fieldset = new Fieldset(t("Last blocks")).id("props-history");
|
Fieldset fieldset = new Fieldset(t("Last blocks")).id("props-history");
|
||||||
Tag list = new Tag("ol");
|
Tag list = new Tag("ol");
|
||||||
@@ -355,7 +352,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Block destination(){
|
public Block destination(){
|
||||||
return null; // TODO
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String destinationTag() {
|
public String destinationTag() {
|
||||||
@@ -404,14 +401,20 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
while (!trace.isEmpty()) trace.removeFirst().free();
|
while (!trace.isEmpty()) trace.removeFirst().free();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endRoute() {
|
public void endRoute(Block newBlock, Direction newDirection) {
|
||||||
setSpeed(0);
|
setSpeed(0);
|
||||||
if (isSet(brakeProcessor)) brakeProcessor.end();
|
if (isSet(brakeProcessor)) brakeProcessor.end();
|
||||||
brakeProcessor = null;
|
set(newBlock);
|
||||||
|
if (newBlock == destination) {
|
||||||
|
destination = null;
|
||||||
|
quitAutopilot();
|
||||||
|
}
|
||||||
|
heading(newDirection);
|
||||||
route = null;
|
route = null;
|
||||||
|
brakeProcessor = null;
|
||||||
|
if (autopilot) start(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Tag faster(int steps) {
|
private Tag faster(int steps) {
|
||||||
setSpeed(speed+steps);
|
setSpeed(speed+steps);
|
||||||
return properties();
|
return properties();
|
||||||
@@ -665,9 +668,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return super.properties(preForm, formInputs, postForm,errors);
|
return super.properties(preForm, formInputs, postForm,errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object quitAutopilot() {
|
public String quitAutopilot() {
|
||||||
// TODO Auto-generated method stub
|
if (autopilot) {
|
||||||
return "not implemented";
|
autopilot = false;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return t("Autopilot already was disabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -764,21 +770,31 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void set(BrakeProcessor bp) {
|
||||||
|
LOG.debug("{}.set({})",this,bp);
|
||||||
|
brakeProcessor = bp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void set(PathFinder pf) {
|
||||||
|
LOG.debug("{}.set({})",this,pf);
|
||||||
|
pathFinder = pf;
|
||||||
|
}
|
||||||
|
|
||||||
private Object setDestination(HashMap<String, String> params) {
|
private Object setDestination(HashMap<String, String> params) {
|
||||||
String dest = params.get(DESTINATION);
|
String dest = params.get(DESTINATION);
|
||||||
if (isNull(dest)) return t("No destination supplied!");
|
if (isNull(dest)) return properties(t("No destination supplied!"));
|
||||||
if (dest.isEmpty()) {
|
if (dest.isEmpty()) {
|
||||||
destination = null;
|
destination = null;
|
||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
Tile tile = plan.get(new Id(dest), true);
|
Tile tile = plan.get(new Id(dest), true);
|
||||||
if (isNull(tile)) return t("Tile {} not known!",dest);
|
if (isNull(tile)) return properties(t("Tile {} not known!",dest));
|
||||||
if (tile instanceof Block) {
|
if (tile instanceof Block) {
|
||||||
destination = (Block) tile;
|
destination = (Block) tile;
|
||||||
start();
|
start(false);
|
||||||
return t("{} now heading for {}",this,destination);
|
return t("{} now heading for {}",this,destination);
|
||||||
}
|
}
|
||||||
return t("{} is not a block!",tile);
|
return properties(t("{} is not a block!",tile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object setFunction(int num, boolean active) {
|
public Object setFunction(int num, boolean active) {
|
||||||
@@ -865,9 +881,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String start() {
|
public String start(boolean autopilot) {
|
||||||
|
this.autopilot |= autopilot;
|
||||||
if (isSet(pathFinder)) return t("Pathfinder already active for {}!",this);
|
if (isSet(pathFinder)) return t("Pathfinder already active for {}!",this);
|
||||||
pathFinder = new PathFinder(this,currentBlock,direction) {
|
PathFinder pathFinder = new PathFinder(this,currentBlock,direction) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void aborted() {
|
public void aborted() {
|
||||||
@@ -889,23 +906,17 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public void prepared(Route newRoute) {
|
public void prepared(Route newRoute) {
|
||||||
LOG.debug("Prepared route {} for {}",newRoute,Train.this);
|
LOG.debug("Prepared route {} for {}",newRoute,Train.this);
|
||||||
route = newRoute;
|
route = newRoute;
|
||||||
pathFinder = null;
|
set((PathFinder)null);
|
||||||
route.start(Train.this);
|
route.start(Train.this);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
set(pathFinder);
|
||||||
}.start();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startAll() {
|
public static void startAll() {
|
||||||
LOG.debug("Train.startAll()");
|
LOG.debug("Train.startAll()");
|
||||||
for (Train train : BaseClass.listElements(Train.class)) LOG.info(train.startAutopilot());
|
for (Train train : BaseClass.listElements(Train.class)) LOG.info(train.start(true));
|
||||||
}
|
|
||||||
|
|
||||||
private String startAutopilot() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startBrake() {
|
public void startBrake() {
|
||||||
@@ -917,19 +928,20 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
LOG.debug("{} already is braking.");
|
LOG.debug("{} already is braking.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
brakeProcessor = new BrakeProcessor(this).start();
|
set(new BrakeProcessor(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Window stopNow() {
|
public Window stopNow() {
|
||||||
setSpeed(0);
|
setSpeed(0);
|
||||||
if (isSet(pathFinder)) {
|
if (isSet(pathFinder)) {
|
||||||
pathFinder.abort();
|
pathFinder.abort();
|
||||||
pathFinder = null;
|
set((PathFinder)null);
|
||||||
}
|
}
|
||||||
if (isSet(route)) {
|
if (isSet(route)) {
|
||||||
route.reset();
|
route.reset();
|
||||||
route = null;
|
route = null;
|
||||||
}
|
}
|
||||||
|
quitAutopilot();
|
||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,7 +1033,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean usesAutopilot() {
|
public boolean usesAutopilot() {
|
||||||
return false; // TODO
|
return autopilot ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStoppable() {
|
public boolean isStoppable() {
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ public class BrakeProcessor extends BaseClass implements Runnable {
|
|||||||
|
|
||||||
public BrakeProcessor(Train train) {
|
public BrakeProcessor(Train train) {
|
||||||
this.train = train;
|
this.train = train;
|
||||||
|
Thread thread = new Thread(this);
|
||||||
|
thread.setName(getClass().getSimpleName());
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void end() {
|
public void end() {
|
||||||
@@ -88,12 +91,4 @@ public class BrakeProcessor extends BaseClass implements Runnable {
|
|||||||
}
|
}
|
||||||
LOG.debug("{} reached final speed.", train);
|
LOG.debug("{} reached final speed.", train);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrakeProcessor start() {
|
|
||||||
Thread thread = new Thread(this);
|
|
||||||
thread.setName(getClass().getSimpleName());
|
|
||||||
thread.start();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ public abstract class PathFinder extends BaseClass implements Runnable{
|
|||||||
this.train = train;
|
this.train = train;
|
||||||
this.startBlock = start;
|
this.startBlock = start;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
|
||||||
|
Thread thread = new Thread(this);
|
||||||
|
thread.setName("Pathfinder("+train+")");
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abort() {
|
public void abort() {
|
||||||
@@ -178,11 +182,4 @@ public abstract class PathFinder extends BaseClass implements Runnable{
|
|||||||
public abstract void locked(Route r);
|
public abstract void locked(Route r);
|
||||||
public abstract void found(Route r);
|
public abstract void found(Route r);
|
||||||
public abstract void prepared(Route r);
|
public abstract void prepared(Route r);
|
||||||
|
|
||||||
public PathFinder start() {
|
|
||||||
Thread thread = new Thread(this);
|
|
||||||
thread.setName("Pathfinder("+train+")");
|
|
||||||
thread.start();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user