Skip to content

Commit 22fdb56

Browse files
authored
Merge pull request #87 from fransjacobs/15-automatic-control
15 automatic control
2 parents 91b580a + 3947e01 commit 22fdb56

23 files changed

+175
-65
lines changed

JCS_SETUP.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# JCS Quick Setup Guide
2+
3+
***
4+
5+
## Get Started driving your Trains automatically
6+
This guide explains how to configure JCS for a layout and automatically run trains.
7+
For the purpose of this guide the following Layout is used.
8+
![Test Layout](assets/testlayout.png)
9+
10+
This layout consist out of 4 blocks and 2 switches.
11+
Every block has 2 sensors, in total there are 8 sensors used.
12+
What is a Block? A block is a part of track where one train can be without hindering other routes. In JCS a block is always demarcated by two sensors.
13+
14+
## Drawing the Layout
15+
16+
When JCS is started select the Edit Button to enable edit mode.
17+
![Start Edit](assets/startedit.png)
18+
19+
JCS will show the Edit Layout Screen
20+
![Start Edit](assets/layoutedittoolbar.png)
21+
22+
The Toolbar has the most common elements to draw a layout. A layout consist out of tiles. A Tile mimics a component like a straight, sensor, block etc.
23+
Use the __+__ button to add a tile on the canvas. The Bin button will delete a tile.
24+
Rightclick on a tile to see properties or rotate or flip if applicable.
25+
When a tile is selected it can be dragged to the right position. Tiles are automatically saved. The example looks like this when all tiles are placed on the canvas.
26+
27+
![Start Edit](assets/layoutedit1.png?raw=true)
28+
29+
## Configuring Accessories and Sensors
30+
31+
The next step is to configure the Accessories and Sensors.
32+
Accessories Sensore and locomotive are alway linked to a Command Station.
33+
#### Step 1 selecting the Default Command Station
34+
For this guide the [DCC-EX](https://dcc-ex.com) Command Station is used. Feedback via [DCC-EX](https://dcc-ex.com) is not yet supported, see [issue 59](https://github.com/fransjacobs/model-railway/issues/59), hence the [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) is used for Sensor feedback.
35+
Use the cog button or via Menu -> Tools Command Stations to show the Command Station Dialog.
36+
37+
![Setup DCC-EX](assets/command-station-DCC-EX.png)
38+
39+
Use the Refresh button on the right side of the Serialport dropdown menu to refresh
40+
connected serial ports. In this example the [DCC-EX](https://dcc-ex.com) is connected via the "ttyACM0" port.
41+
42+
Set the [DCC-EX](https://dcc-ex.com) Command Station as __Default__ and __Enabled__.
43+
The Test Button can be used to check whether the connection can be established.
44+
45+
##### Setup the Feedback module(s)
46+
In the Command Station Dialog select the [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) in the Command Stations dropdown menu.
47+
48+
![Setup HSI-S88](assets/command-station-HSI-S88.png)
49+
50+
Do __*NOT*__ set the [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) as *Default*, as the default Command Station is supposed to put the power on the Track. However set the [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) __Enabled__.
51+
52+
For the Feedback Interface like the [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) the number of connected S88 modules has to be specified. Set the Channel to which the S88 module(s) is/are connected and the number of Modules.
53+
In this case one S88 module, connected to Channel 0 is used.
54+
Click on __*Re-create Sensors*__ button to create the sensors in the system.
55+
56+
### Step 2 create Accessories
57+
The Test track has two turnouts which can be added using the Accessory Dialog. This Dialog can be opened via Settings (Mac) or Menu -> Tools -> Options.
58+
To Add a new Accessory click on the __+__ button. For a Turnout choose the right Turnout type in the __*Type*__ dropdown menu.
59+
60+
![Edit Accessory](assets/accessory-edit.png)
61+
62+
To save the Accessory click the Save Button. When save the Accessory will appear in the list on the left side. This List can be filtered using the 3 radio buttons on top (All, Turnouts, Signals).
63+
64+
### Step 3 add Locomotives
65+
As we are in the options Dialog let's also add the Locomotives. In this Example two locomotives used. For both locomotives an icon is already put in a subdirectory .../jcs/images.
66+
67+
![Edit Locomotive](assets/locomotive-edit.png)
68+
69+
Locomotives can only commute back and forth, hence the __Commuter__ check box is selected for both locomotives. If the __Commuter__ checkbox not selected the Locomotice can __*NOT*__ change direction in Automatic mode.
70+
71+
### Step 4 Link sensors to their graphical representation
72+
73+
JCS "knows" where a locomotive is by monitoring the sensors on the track. Every sensor has to be linked to the location in the schematic layout. As already mentioned a block allways needs two sensors. When a train arrives in a block (enter) the enter sensor detects this. When the train reaches the destination, a.k.a. is fully in the block, this is detected by the occupation (in) sensor.
74+
When a sensor is active JCS will "see" this as occupied and in automatice mode will not plot a route to this block.
75+
To link a Sensor, right click on a sensor.
76+
77+
![Sensor popup](assets/sensor-popup.png)
78+
79+
Click on Properties and select the pysical sensor.
80+
81+
![Select Sensor](assets/select-sensor.png)
82+
83+
If you do no exactly know which sensor is at this location, you can use the Sensor Monitor. Click on the Sensor Monitor button to activate.
84+
85+
![Sensor Monitor Button](assets/sensor-monitor-button.png)
86+
87+
The Sensor Monitor will appear. When the sensor is activated (pre condition is that the HSI-S88 is connected), it will be visible in the Sensor Monitor as active.
88+
89+
![Sensor Monitor](assets/sensor-monitor-sensor1-active.png)
90+
91+
Select the Sensor with the right name in Sensor Properties dialog. Repeat this for all sensors in the layout.
92+
93+
### Step 5 Trace the layout
94+
Trace the layout. This will generate all the driveways from block to block. Click on the __*Trace*__ button.
95+
96+
![Show Routes](assets/routes-dialog-empty.png)
97+
98+
Left of the Main JCS Window the Routes Dialog will Appear.
99+
Click in the __*Trace*__ Button in the *Routes Dialog* to generate all possible routes.
100+
101+
![Empty Routes](assets/routes-dialog-traced.png)
102+
103+
When a route is selected in the list it is displayed in the main screen.
104+
105+
### Step 6 Configure the Blocks
106+
Configure the Block properties.
107+
First Restart JCS. This is due to a [known issue 78](https://github.com/fransjacobs/model-railway/issues/78).
108+
109+
The Sensors must be linked to a block. The side of the Block with the __Bold__ line is the __+__ (plus) side of the Block. The Sensor can be automatically linked.
110+
111+
TBW

README.md

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,29 @@
88
![GitHub Gist last commit](https://img.shields.io/github/last-commit/fransjacobs/model-railway)
99
![GitHub issues](https://img.shields.io/github/issues-raw/fransjacobs/model-railway)
1010
![GitHub Release](https://img.shields.io/github/v/release/fransjacobs/model-railway)
11-
12-
## Model railway control with JCS
13-
Experiments wich should eventually lead to automated rail road control.
14-
15-
## Why?
16-
To have fun!
17-
I know there are ready to go products on the market. This project is not an attempt to compeat with any of them,
18-
hence this project is Open Source so anyone can benefit.
19-
11+
***
2012
## About The Project
21-
JCS is an application to control a model railway. It is in an early stage of development.
22-
The project mostly contains my experiments to automate my model railway.
13+
JCS is a hobby project of me where I try to automate my Model Railway. The past year I have on and off worked on several aspects or modules of the software whic are needed to finally drive automatically. A short summary of the topics which are needed and used to finally be able to drive a train automatically:
14+
- Connectivety to the Command Station hardware. (DCC-EX,HSI-S88, Marklin CS2/3)
15+
- Edit and display graphically a layout
16+
- With the layout be able to route all the possible drive ways
17+
- Show the routes and driveways in the layout screen
18+
- Graphically feedback events on track to the layout screen
19+
- Input dialogs to setup Accessories, Locomotives, Command stations, etc
20+
- Locomotive Drive Cap so tha you can manually run you locomotive
21+
- Virtual Command Station, to ease testing and simulate automatic driving
22+
- Monitor Sensor events
23+
24+
I created a [short video](https://youtu.be/xP6eUdScMY0) demonstrating automatic running of locomotives. Also a [video of pysical locomotives running on the Test Layout](https://www.youtube.com/watch?v=CyLmGk6gfHA)
2325

24-
I started this project 2019 as (and still is) a hobby to automate my model-rail layout.
25-
As I am trying to do this project beside my work, family and other hobbies it is a project with sometimes a very slow pace...
26+
## Why?
27+
There are already many "out of the box" working products. I wanted to create my own to learn and to have FUN!
2628

27-
The aim of the program is to automate the running of trains on my layout.
29+
As I am a great supporter of Open Source I have put the project on github with the purpose for others to use it, learn from it, or improve it.
2830

29-
## Supported Hardware
30-
* [DCC-EX](https://dcc-ex.com) can be connected either via serial port or network
31-
* [Marklin CS-2](https://www.marklin.nl/producten/details/article/60215)
32-
* [Marklin CS-3](https://www.marklin.nl/producten/details/article/60216)
33-
* [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) or the [DIY version](https://mobatron.4lima.de/2020/05/s88-scanner-mit-arduino) for feedback
31+
So I hope you get inspired!
3432

35-
## NEW
36-
* Layout router, After the layout is created automatically all driveways are calculated.
37-
* Autopilot, automatically drive locomotives.
38-
* Virtual Command station.
39-
* Auto [Simulator](https://youtu.be/xP6eUdScMY0) in the Virtual Commandstation to test routes.
40-
41-
## Current status
42-
Currently the following modules are build:
43-
* A Throttle for driving locomotives
44-
* Keyboard Screen for switching Turnouts or Signals
45-
* Sensor Monitor to see the status of feedback sensors
46-
* Locomotives overview (including automatic downloading of the Locomotive- and function button images) and control.
47-
* Turnout and Signals overview (Synchronized with the CS2/3) and control.
48-
* A Screen to edit/display de schematic Layout.
49-
* A HAL for command Stations such that other hardware then the Marklin CS 2/3 can be used.
50-
* [First Release V 0.0.1](https://github.com/fransjacobs/model-railway/releases/tag/V0.0.1)
33+
Frans
5134

5235
## Screenshots
5336
So here are a few screenshots of the Project:
@@ -57,38 +40,49 @@ Or can be manually added.
5740

5841
![UI screenshot: JCS Throttle](assets/driver_cab.png?raw=true)
5942

60-
#### Keyboard Panel for switching accessories and viewing feedback sensor status
43+
#### Layout overview
44+
The (schematic) layout is displayed. Locomotive can be Placed in a Block.
45+
When the AutoPilot is switched on Locomotive will drive from block to block.
46+
![UI screenshot: JCS Main Screen](assets/mainscreen.png?raw=true)
6147

62-
![UI screenshot: JCS keyboard Screen](assets/keyboard-panel.png?raw=true)
48+
In Editmode you can draw a layout using pre defined Tiles.
49+
also the layout can be routed. (it the very first and early step for the preparation of automatic running).
50+
![UI screenshot: JCS Edit Screen](assets/mainscreen_edit_route.png?raw=true)
6351

6452
#### Sensor Monitor
65-
53+
To debug or easly setup your feedback sensors
6654
![UI screenshot: JCS Sensor Monitor](assets/sensor_monitor.png?raw=true)
6755

68-
#### Layout display
69-
![UI screenshot: JCS Main Screen](assets/mainscreen.png?raw=true)
56+
#### Keyboard Panel for switching accessories and viewing feedback sensor status
7057

71-
In Editmode you can draw a layout using pre defined Tiles.
72-
also the layout can be routed. (it the very first and early step for the preparation of automatic running).
73-
![UI screenshot: JCS Edit Screen](assets/mainscreen_edit_route.png?raw=true)
58+
![UI screenshot: JCS keyboard Screen](assets/keyboard-panel.png?raw=true)
7459

7560
#### Import Locomotives from a CS-2 or CS-3
7661
![UI screenshot: JCS Preferences Locomotives](assets/prefs_locomotives.png?raw=true)
7762

63+
## Releases
64+
* [First Release V 0.0.1](https://github.com/fransjacobs/model-railway/releases/tag/V0.0.1)
65+
66+
## Supported Hardware
67+
* [DCC-EX](https://dcc-ex.com) can be connected either via serial port or network
68+
* [Marklin CS-2](https://www.marklin.nl/producten/details/article/60215)
69+
* [Marklin CS-3](https://www.marklin.nl/producten/details/article/60216)
70+
* [HSI-S88](https://www.ldt-infocenter.com/dokuwiki/doku.php?id=en:hsi-88-usb) or the [DIY version](https://mobatron.4lima.de/2020/05/s88-scanner-mit-arduino) for feedback
71+
72+
## Current status
73+
Currently the following feature are in development:
74+
* Internationalization enable multiple languages
75+
* Add support for ESU ECOS
76+
* Show Signal aspects in automatic driving
77+
* Document
78+
7879
## TODO's (and there are still a lots of todo's...):
7980
Currently the following features are under active development:
80-
* Configuration screens to edit the Locomotives, Accessories and Sensors. [more or less done :)]
81-
* Add deployment configuration for MacOS, Windows and Linux an App [more or less done :)]
82-
* Automatically route the Layout. [more or less done :)]
83-
* React on relevant CS-3 events like start/stop, Sensor events, Loco, Accessory, power etc events. [work in progress :)]
84-
* Automatically run trains. [Work in progress]
81+
* Documentation
82+
* Enhance GUI
8583
* Add more Unit tests
8684
* ...
8785

88-
So I hope you get inspired!
89-
90-
Frans
91-
9286
## License
9387
[LICENSE](LICENSE.md)
9488

@@ -111,7 +105,6 @@ Frans
111105
</tr>
112106
</table>
113107

114-
115108
** Copyright 2019 - 2024 Frans Jacobs **
116109

117110
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),

assets/accessory-edit.png

54.9 KB
Loading

assets/command-station-DCC-EX.png

49.7 KB
Loading

assets/command-station-HSI-S88.png

48.3 KB
Loading

assets/layoutedit1.png

13.3 KB
Loading

assets/layoutedittoolbar.png

21.1 KB
Loading

assets/locomotive-edit.png

60.9 KB
Loading

assets/routes-dialog-empty.png

43.3 KB
Loading

assets/routes-dialog-traced.png

60.6 KB
Loading

assets/select-sensor.png

15.7 KB
Loading

assets/sensor-monitor-button.png

12.4 KB
Loading
8.73 KB
Loading

assets/sensor-popup.png

10.2 KB
Loading

assets/startedit.png

16.8 KB
Loading

assets/testlayout.png

364 KB
Loading

assets/trace-button.png

6.08 KB
Loading

src/main/java/jcs/persistence/PersistenceFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ protected boolean createPersistenceService() {
4949

5050
if (persistenceServiceImpl == null) {
5151
RunUtil.loadProperties();
52-
persistenceServiceImpl = System.getProperty("persistenceService");
52+
RunUtil.loadExternalProperties();
53+
54+
persistenceServiceImpl = System.getProperty("persistenceService","jcs.persistence.H2PersistenceService");
5355
}
5456

5557
H2DatabaseUtil.setProperties();

src/main/java/jcs/persistence/util/H2DatabaseUtil.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class H2DatabaseUtil {
5050
protected static final String JDBC_PRE = "jdbc:h2:";
5151

5252
protected static final String DB_CREATE_DDL = "jcs-db.sql";
53-
53+
5454
//Future use
5555
protected static final String CLOSE_ON_EXIT = ";DB_CLOSE_ON_EXIT=FALSE";
5656

@@ -329,7 +329,7 @@ public static String getDataBaseVersion() {
329329
Logger.error("Could not obtain a connection!");
330330
}
331331
} catch (SQLException ex) {
332-
Logger.error(ex);
332+
Logger.error("Can't obtain version!" + ex);
333333
}
334334
return version;
335335
}
@@ -374,7 +374,10 @@ private static String getVersionNumber(int v) {
374374

375375
public static String updateDatabase() {
376376
String curVersion = getDataBaseVersion();
377-
377+
if (curVersion == null) {
378+
Logger.warn("Assume version 0.0.1");
379+
curVersion = "0.0.1";
380+
}
378381
int fromVersion = Integer.parseInt(curVersion.replace(".", ""));
379382
int toVersion = Integer.parseInt(DB_VERSION.replace(".", ""));
380383

@@ -396,6 +399,7 @@ public static String updateDatabase() {
396399
} catch (Exception ex) {
397400
Logger.error(ex);
398401
}
402+
//Logger.info((test ? "TESTMODE " : "") + "Database updated to version: " + getDataBaseVersion());
399403
Logger.info((test ? "TESTMODE " : "") + "Database updated to version: " + getDataBaseVersion());
400404
}
401405
} else {

src/main/java/jcs/ui/DriverCabPanel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ public void onSpeedChange(LocomotiveSpeedEvent event) {
459459

460460
max = this.speedGauge.getMaxValue();
461461
double gaugeValue = Math.round(max / 1000 * velocity);
462-
this.speedGauge.setValue(gaugeValue);
462+
//this.speedGauge.setValue(gaugeValue);
463+
this.speedGauge.setValueAnimated(gaugeValue);
463464

464465
this.speedGauge.setUserLedOn(this.power);
465466
this.speedGauge.setLedBlinking(!this.power);

src/main/resources/tinylog-dev.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ writer1.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}
2424

2525

2626
writer2 = rolling file
27-
writer2.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}.{method}(): {message}
27+
writer2.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}.{method}(): {message}
2828
writer2.level = trace
2929
#writer2.append = true
3030
writer2.buffered = true
31-
writer2.file = ${HOME}/jcs/logs/jcs_log_{count}.txt
31+
writer2.file = #{user.home}/jcs/logs/jcs_log_{count}.txt
3232
writer2.policies = startup
3333
writer2.backups = 10
3434

src/main/resources/tinylog.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ stacktrace = 100
2323
writer1.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}.{method}(): {message}
2424

2525
writer2 = rolling file
26-
writer2.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}.{method}(): {message}
26+
writer2.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}.{method}(): {message}
2727
writer2.level = trace
2828
writer2.append = true
2929
writer2.buffered = true
30-
writer2.file = ${HOME:/jcs}/logs/jcs_log_{count}.txt
30+
writer2.file = #{user.home}/jcs/logs/jcs_log_{count}.txt
3131
writer2.policies = startup
3232
writer2.backups = 10
3333

src/main/resources/update-jcs-db-001.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
create table jcs_version (
1+
create table if not exists jcs_version (
22
db_version varchar(255) not null,
33
app_version varchar(255) not null
44
);
55

66
commit;
77

8-
--Use the new to be adde virtual command station as default
98
update command_stations set default_cs = false;
9+
commit;
1010

1111
insert into command_stations(id, description, short_name, class_name, connect_via, serial_port, ip_address, network_port, ip_auto_conf, supports_decoder_control, supports_accessory_control, supports_feedback, supports_loco_synch, supports_accessory_synch, supports_loco_image_synch, supports_loco_function_synch, protocols, default_cs, enabled, last_used_serial, sup_conn_types, feedback_module_id, feedback_bus_count, feedback_bus_0_module_count, feedback_bus_1_module_count, feedback_bus_2_module_count, feedback_bus_3_module_count)
1212
values('virtual', 'Virtual CS', 'VIR', 'jcs.commandStation.virtual.VirtualCommandStationImpl', 'NETWORK', NULL, '127.0.0.1', 0, false, true, true, true, false, false, false, false, 'dcc', true, true, '1', 'NETWORK', '0', 1, 1, 0, 0, 0);
@@ -30,6 +30,5 @@ commit;
3030

3131
alter table locomotives drop richtung;
3232

33-
3433
insert into jcs_version (db_version,app_version) values ('0.0.2','0.0.2');
3534
commit;

0 commit comments

Comments
 (0)