Class SampleAutomaton3

  • All Implemented Interfaces:
    java.lang.Runnable

    public class SampleAutomaton3
    extends AbstractAutomaton
    This sample Automaton runs a locomotive back and forth on a piece of track by watching two sensors.

    The sensors and locomotive are hardcoded, as this is an example of just the Automaton function. Adding a GUI to configure these would be straight-forward. The values could be passed via the constructor, or the constructor (which can run in any required thread) could invoke a dialog.

    For test purposes, one of these objects can be created and invoked by a SampleAutomaton3Action.

    For more information on JMRI support for automation classes, please see the JMRI Layout Automation in Java page.

    See Also:
    SampleAutomaton3Action
    • Field Detail

      • fwdSensor

        Sensor fwdSensor
        References the sensor the locomotive will enter when it moves forward to the limit.
      • revSensor

        Sensor revSensor
        References the sensor the locomotive will enter when it moves backward to the limit.
      • fwdSensorName

        java.lang.String fwdSensorName
        By default, monitors sensor "182" for the forward end of the track
      • revSensorName

        java.lang.String revSensorName
        By default, monitors sensor "178" for the reverse end of the track
      • locoNumber

        int locoNumber
        By default, controls locomotive 77(short).
    • Method Detail

      • init

        protected void init()
        Description copied from class: AbstractAutomaton
        User-provided initialization routine.

        This is called exactly once for each object created. This is where you put all the code that needs to be run when your object starts up: Finding sensors and turnouts, getting a throttle, etc.

        Overrides:
        init in class AbstractAutomaton
      • handle

        protected boolean handle()
        Watch the sensors, and change direction to match.
        Overrides:
        handle in class AbstractAutomaton
        Returns:
        Always returns true to continue operation