Skip to content

Commit

Permalink
Merge pull request #87 from fransjacobs/15-automatic-control
Browse files Browse the repository at this point in the history
15 automatic control
  • Loading branch information
fransjacobs authored Sep 14, 2024
2 parents 91b580a + 3947e01 commit 22fdb56
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 65 deletions.
111 changes: 111 additions & 0 deletions JCS_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# JCS Quick Setup Guide

***

## Get Started driving your Trains automatically
This guide explains how to configure JCS for a layout and automatically run trains.
For the purpose of this guide the following Layout is used.
![Test Layout](assets/testlayout.png)

This layout consist out of 4 blocks and 2 switches.
Every block has 2 sensors, in total there are 8 sensors used.
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.

## Drawing the Layout

When JCS is started select the Edit Button to enable edit mode.
![Start Edit](assets/startedit.png)

JCS will show the Edit Layout Screen
![Start Edit](assets/layoutedittoolbar.png)

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.
Use the __+__ button to add a tile on the canvas. The Bin button will delete a tile.
Rightclick on a tile to see properties or rotate or flip if applicable.
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.

![Start Edit](assets/layoutedit1.png?raw=true)

## Configuring Accessories and Sensors

The next step is to configure the Accessories and Sensors.
Accessories Sensore and locomotive are alway linked to a Command Station.
#### Step 1 selecting the Default Command Station
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.
Use the cog button or via Menu -> Tools Command Stations to show the Command Station Dialog.

![Setup DCC-EX](assets/command-station-DCC-EX.png)

Use the Refresh button on the right side of the Serialport dropdown menu to refresh
connected serial ports. In this example the [DCC-EX](https://dcc-ex.com) is connected via the "ttyACM0" port.

Set the [DCC-EX](https://dcc-ex.com) Command Station as __Default__ and __Enabled__.
The Test Button can be used to check whether the connection can be established.

##### Setup the Feedback module(s)
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.

![Setup HSI-S88](assets/command-station-HSI-S88.png)

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__.

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.
In this case one S88 module, connected to Channel 0 is used.
Click on __*Re-create Sensors*__ button to create the sensors in the system.

### Step 2 create Accessories
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.
To Add a new Accessory click on the __+__ button. For a Turnout choose the right Turnout type in the __*Type*__ dropdown menu.

![Edit Accessory](assets/accessory-edit.png)

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).

### Step 3 add Locomotives
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.

![Edit Locomotive](assets/locomotive-edit.png)

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.

### Step 4 Link sensors to their graphical representation

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.
When a sensor is active JCS will "see" this as occupied and in automatice mode will not plot a route to this block.
To link a Sensor, right click on a sensor.

![Sensor popup](assets/sensor-popup.png)

Click on Properties and select the pysical sensor.

![Select Sensor](assets/select-sensor.png)

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.

![Sensor Monitor Button](assets/sensor-monitor-button.png)

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.

![Sensor Monitor](assets/sensor-monitor-sensor1-active.png)

Select the Sensor with the right name in Sensor Properties dialog. Repeat this for all sensors in the layout.

### Step 5 Trace the layout
Trace the layout. This will generate all the driveways from block to block. Click on the __*Trace*__ button.

![Show Routes](assets/routes-dialog-empty.png)

Left of the Main JCS Window the Routes Dialog will Appear.
Click in the __*Trace*__ Button in the *Routes Dialog* to generate all possible routes.

![Empty Routes](assets/routes-dialog-traced.png)

When a route is selected in the list it is displayed in the main screen.

### Step 6 Configure the Blocks
Configure the Block properties.
First Restart JCS. This is due to a [known issue 78](https://github.com/fransjacobs/model-railway/issues/78).

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.

TBW
99 changes: 46 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,29 @@
![GitHub Gist last commit](https://img.shields.io/github/last-commit/fransjacobs/model-railway)
![GitHub issues](https://img.shields.io/github/issues-raw/fransjacobs/model-railway)
![GitHub Release](https://img.shields.io/github/v/release/fransjacobs/model-railway)

## Model railway control with JCS
Experiments wich should eventually lead to automated rail road control.

## Why?
To have fun!
I know there are ready to go products on the market. This project is not an attempt to compeat with any of them,
hence this project is Open Source so anyone can benefit.

***
## About The Project
JCS is an application to control a model railway. It is in an early stage of development.
The project mostly contains my experiments to automate my model railway.
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:
- Connectivety to the Command Station hardware. (DCC-EX,HSI-S88, Marklin CS2/3)
- Edit and display graphically a layout
- With the layout be able to route all the possible drive ways
- Show the routes and driveways in the layout screen
- Graphically feedback events on track to the layout screen
- Input dialogs to setup Accessories, Locomotives, Command stations, etc
- Locomotive Drive Cap so tha you can manually run you locomotive
- Virtual Command Station, to ease testing and simulate automatic driving
- Monitor Sensor events

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)

I started this project 2019 as (and still is) a hobby to automate my model-rail layout.
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...
## Why?
There are already many "out of the box" working products. I wanted to create my own to learn and to have FUN!

The aim of the program is to automate the running of trains on my layout.
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.

## Supported Hardware
* [DCC-EX](https://dcc-ex.com) can be connected either via serial port or network
* [Marklin CS-2](https://www.marklin.nl/producten/details/article/60215)
* [Marklin CS-3](https://www.marklin.nl/producten/details/article/60216)
* [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
So I hope you get inspired!

## NEW
* Layout router, After the layout is created automatically all driveways are calculated.
* Autopilot, automatically drive locomotives.
* Virtual Command station.
* Auto [Simulator](https://youtu.be/xP6eUdScMY0) in the Virtual Commandstation to test routes.

## Current status
Currently the following modules are build:
* A Throttle for driving locomotives
* Keyboard Screen for switching Turnouts or Signals
* Sensor Monitor to see the status of feedback sensors
* Locomotives overview (including automatic downloading of the Locomotive- and function button images) and control.
* Turnout and Signals overview (Synchronized with the CS2/3) and control.
* A Screen to edit/display de schematic Layout.
* A HAL for command Stations such that other hardware then the Marklin CS 2/3 can be used.
* [First Release V 0.0.1](https://github.com/fransjacobs/model-railway/releases/tag/V0.0.1)
Frans

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

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

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

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

#### Sensor Monitor

To debug or easly setup your feedback sensors
![UI screenshot: JCS Sensor Monitor](assets/sensor_monitor.png?raw=true)

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

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

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

## Releases
* [First Release V 0.0.1](https://github.com/fransjacobs/model-railway/releases/tag/V0.0.1)

## Supported Hardware
* [DCC-EX](https://dcc-ex.com) can be connected either via serial port or network
* [Marklin CS-2](https://www.marklin.nl/producten/details/article/60215)
* [Marklin CS-3](https://www.marklin.nl/producten/details/article/60216)
* [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

## Current status
Currently the following feature are in development:
* Internationalization enable multiple languages
* Add support for ESU ECOS
* Show Signal aspects in automatic driving
* Document

## TODO's (and there are still a lots of todo's...):
Currently the following features are under active development:
* Configuration screens to edit the Locomotives, Accessories and Sensors. [more or less done :)]
* Add deployment configuration for MacOS, Windows and Linux an App [more or less done :)]
* Automatically route the Layout. [more or less done :)]
* React on relevant CS-3 events like start/stop, Sensor events, Loco, Accessory, power etc events. [work in progress :)]
* Automatically run trains. [Work in progress]
* Documentation
* Enhance GUI
* Add more Unit tests
* ...

So I hope you get inspired!

Frans

## License
[LICENSE](LICENSE.md)

Expand All @@ -111,7 +105,6 @@ Frans
</tr>
</table>


** Copyright 2019 - 2024 Frans Jacobs **

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
Expand Down
Binary file added assets/accessory-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/command-station-DCC-EX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/command-station-HSI-S88.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/layoutedit1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/layoutedittoolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/locomotive-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/routes-dialog-empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/routes-dialog-traced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/select-sensor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sensor-monitor-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sensor-monitor-sensor1-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sensor-popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/startedit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/testlayout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/trace-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/main/java/jcs/persistence/PersistenceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ protected boolean createPersistenceService() {

if (persistenceServiceImpl == null) {
RunUtil.loadProperties();
persistenceServiceImpl = System.getProperty("persistenceService");
RunUtil.loadExternalProperties();

persistenceServiceImpl = System.getProperty("persistenceService","jcs.persistence.H2PersistenceService");
}

H2DatabaseUtil.setProperties();
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/jcs/persistence/util/H2DatabaseUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class H2DatabaseUtil {
protected static final String JDBC_PRE = "jdbc:h2:";

protected static final String DB_CREATE_DDL = "jcs-db.sql";

//Future use
protected static final String CLOSE_ON_EXIT = ";DB_CLOSE_ON_EXIT=FALSE";

Expand Down Expand Up @@ -329,7 +329,7 @@ public static String getDataBaseVersion() {
Logger.error("Could not obtain a connection!");
}
} catch (SQLException ex) {
Logger.error(ex);
Logger.error("Can't obtain version!" + ex);
}
return version;
}
Expand Down Expand Up @@ -374,7 +374,10 @@ private static String getVersionNumber(int v) {

public static String updateDatabase() {
String curVersion = getDataBaseVersion();

if (curVersion == null) {
Logger.warn("Assume version 0.0.1");
curVersion = "0.0.1";
}
int fromVersion = Integer.parseInt(curVersion.replace(".", ""));
int toVersion = Integer.parseInt(DB_VERSION.replace(".", ""));

Expand All @@ -396,6 +399,7 @@ public static String updateDatabase() {
} catch (Exception ex) {
Logger.error(ex);
}
//Logger.info((test ? "TESTMODE " : "") + "Database updated to version: " + getDataBaseVersion());
Logger.info((test ? "TESTMODE " : "") + "Database updated to version: " + getDataBaseVersion());
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jcs/ui/DriverCabPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ public void onSpeedChange(LocomotiveSpeedEvent event) {

max = this.speedGauge.getMaxValue();
double gaugeValue = Math.round(max / 1000 * velocity);
this.speedGauge.setValue(gaugeValue);
//this.speedGauge.setValue(gaugeValue);
this.speedGauge.setValueAnimated(gaugeValue);

this.speedGauge.setUserLedOn(this.power);
this.speedGauge.setLedBlinking(!this.power);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/tinylog-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ writer1.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}


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

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/tinylog.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ stacktrace = 100
writer1.format = {level}\t{date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class-name}.{method}(): {message}

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

Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/update-jcs-db-001.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
create table jcs_version (
create table if not exists jcs_version (
db_version varchar(255) not null,
app_version varchar(255) not null
);

commit;

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

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)
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);
Expand All @@ -30,6 +30,5 @@ commit;

alter table locomotives drop richtung;


insert into jcs_version (db_version,app_version) values ('0.0.2','0.0.2');
commit;

0 comments on commit 22fdb56

Please sign in to comment.