1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 05:11:24 +01:00
CommandStation-EX/myAutomation.example.h

81 lines
3.1 KiB
C
Raw Normal View History

/* This is an automation example file.
* The presence of a file called "myAutomation.h" brings EX-RAIL code into
* the command station.
* The automation may have multiple concurrent tasks.
* A task may
* - Act as a ROUTE setup macro for a user to drive over
* - drive a loco through an AUTOMATION
* - automate some cosmetic part of the layout without any loco.
*
* At startup, a single task is created to execute the startup sequence.
2021-08-10 11:41:35 +02:00
* This task may simply follow a route, or may START
* further tasks (that is.. send a loco out along a route).
*
* Where the loco id is not known at compile time, a new task
* can be created with the command:
2021-08-10 11:41:35 +02:00
* </ START [cab] route>
*
* A ROUTE, AUTOMATION or SEQUENCE are internally identical in ExRail terms
* but are just represented differently to a Withrottle user:
2021-08-10 11:41:35 +02:00
* ROUTE(n,"name") - as Route_n .. to setup a route through a layout
* AUTOMATION(n,"name") as Auto_n .. to send the current loco off along an automated journey
* SEQUENCE(n) is not visible to Withrottle.
*
*/
2023-03-18 19:52:01 +01:00
// This is the startup sequence,
AUTOSTART
POWERON // turn on track power
SENDLOCO(3,1) // send loco 3 off along route 1
SENDLOCO(10,2) // send loco 10 off along route 2
DONE // This just ends the startup thread, leaving 2 others running.
2021-08-10 11:41:35 +02:00
/* SEQUENCE(1) is a simple shuttle between 2 sensors
2021-08-12 21:35:56 +02:00
* S20 and S21 are sensors on arduino pins 20 and 21
* S20 S21
* === START->================
*/
2021-08-10 11:41:35 +02:00
SEQUENCE(1)
DELAY(10000) // wait 10 seconds
FON(3) // Set Loco Function 3, Horn on
2021-08-10 11:41:35 +02:00
DELAY(1000) // wait 1 second
FOFF(3) // Horn off
FWD(80) // Move forward at speed 80
2021-08-12 21:35:56 +02:00
AT(21) // until we hit sensor id 21
STOP // then stop
2021-08-10 11:41:35 +02:00
DELAY(5000) // Wait 5 seconds
FON(2) // ring bell
REV(60) // reverse at speed 60
2021-08-12 21:35:56 +02:00
AT(20) // until we get to S20
STOP // then stop
FOFF(2) // Bell off
2021-08-10 11:41:35 +02:00
FOLLOW(1) // and follow sequence 1 again
2021-08-10 11:41:35 +02:00
/* SEQUENCE(2) is an automation example for a single loco Y shaped journey
2021-08-12 21:35:56 +02:00
* S31,S32,S33 are sensors, T4 is a turnout
*
2021-08-12 21:35:56 +02:00
* S33 T4 S31
* ===-START->=============================================
* //
2021-08-12 21:35:56 +02:00
* S32 //
* ======================//
*
2021-08-12 21:35:56 +02:00
* Train runs from START to S31, back to S32, again to S31, Back to start.
*/
2021-08-10 11:41:35 +02:00
SEQUENCE(2)
FWD(60) // go forward at DCC speed 60
2021-08-12 21:35:56 +02:00
AT(31) STOP // when we get to sensor 31
2021-08-10 11:41:35 +02:00
DELAY(10000) // wait 10 seconds
2021-08-12 21:35:56 +02:00
THROW(4) // throw turnout for route to S32
REV(45) // go backwards at speed 45
2021-08-12 21:35:56 +02:00
AT(32) STOP // until we arrive at sensor 32
2021-08-10 11:41:35 +02:00
DELAY(5000) // wait 5 seconds
FWD(50) // go forwards at speed 50
2021-08-12 21:35:56 +02:00
AT(31) STOP // and stop at sensor 31
2021-08-10 11:41:35 +02:00
DELAY(5000) // wait 5 seconds
CLOSE(4) // set turnout closed
REV(50) // reverse back to S3
2021-08-12 21:35:56 +02:00
AT(33) STOP
2021-08-10 11:41:35 +02:00
DELAY(20000) // wait 20 seconds
FOLLOW(2) // follow sequence 2... ie repeat the process