Class AutoActiveTrain
- All Implemented Interfaces:
EventListener,ThrottleListener
This class implements logic that follows a train around a layout. Train follows signals, provided the next Section is allocated to it, and its ActiveTrain's status is RUNNING.
This class is linked via its parent ActiveTrain object.
This file is part of JMRI.
JMRI is open source software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The AutoEngineer sub class is based in part on code by Pete Cressman contained in Warrants.java
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) static class(package private) classPause the train in a separate thread.(package private) classNested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int(package private) floatstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int(package private) boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected booleanprotected voidvoiddispose()protected voidexecuteStopTasks(int task) protected AllocatedSectionprotected AllocatedSectionGet current Signal DisplayName.Get current Signal UserName.booleanintReturns the F-Number for the Bell.intReturns the F-Number for the Horn.intReturns the F-Number for the light.protected Sectionfloatlongfloatgets the lowest speed as a percentage of throttle that the loco reliably operates.intstatic intgetRampRateFromName(String rampRate) Convert ramp rate name, stored as a string into the constant value assigned.booleanintbooleanfloatprotected floatgetSpeedFromBlock(Block block) booleanfloatfloatprotected DccThrottlebooleanprotected voidprotected voidHandle notification of changes in section occupancy.protected voidHandle notification of changes in section state.protected voidbooleanInitialize new Auto Active Train or get a new throttle after WORKING Sets up the DCC address and initiates creation of a throttle to run the train.protected voidInitiates running in manual mode with external throttle.protected booleanchecks for a controlling signalvoidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question) No steal or share decisions made locallyvoidnotifyFailedThrottleRequest(LocoAddress address, String reason) Get notification that an attempt to request a throttle has failed.voidGet notification that a throttle has been found as requested.pauseTrain(int fastMinutes) Pause the auto active train for a specified number of fast clock minutes.protected voidprotected voidResumes automatic running after a working session using an external throttle This method is triggered by the dispatcher hitting the "Resume Auto Running" button A new throttle is acquired to allow automatic running to resumeprotected voidvoidset_useStopSensor(boolean _useStopSensor) voidsetCurrentRampRate(int rate) protected voidsupport methodsvoidsetForward(boolean set) voidsetFunction(int functionNum, boolean isSet) Manually set the train throttle Function value.voidsetFunctionBell(int value) Set the F-Number for the BellvoidsetFunctionHorn(int value) Set the F-Number for the HornvoidsetFunctionLight(int value) Set the F-Number for the lightvoidsetMaxSpeed(float speed) voidsetMaxTrainLength(double length, double scaleFactor) Set Train length in Scale MetersvoidsetMinReliableOperatingSpeed(float speed) Sets the lowest speed as a percentage of throttle that the loco reliably operates.voidsetRampRate(int rate) voidsetResistanceWheels(boolean set) Deprecated, for removal: This API element is subject to removal in a future version.voidsetRunInReverse(boolean set) voidsetSavedStatus(int status) voidsetSoundDecoder(boolean set) protected voidvoidsetSpeedFactor(float factor) voidsetStopBySpeedProfile(boolean tf) voidsetStopBySpeedProfileAdjust(float adjust) voidsetTargetSpeed(float speed) voidsetTargetSpeed(float distance, float speed) voidsetTargetSpeedByPass(float speed) voidsetTargetSpeedByPass(float distance, float speed) protected voidsetupNewCurrentSignal(AllocatedSection as, boolean forceSpeedChange) voidsetUseSpeedProfile(boolean tf) voidprotected voidReturns when train is stopped.
-
Field Details
-
STOP_SPEED
- See Also:
-
RESTRICTED_SPEED
- See Also:
-
SLOW_SPEED
- See Also:
-
MEDIUM_SPEED
- See Also:
-
LIMITED_SPEED
- See Also:
-
NORMAL_SPEED
- See Also:
-
MAXIMUM_SPEED
- See Also:
-
RAMP_NONE
- See Also:
-
RAMP_FAST
- See Also:
-
RAMP_MEDIUM
- See Also:
-
RAMP_MED_SLOW
- See Also:
-
RAMP_SLOW
- See Also:
-
RAMP_SPEEDPROFILE
- See Also:
-
NO_TASK
- See Also:
-
END_REVERSAL
- See Also:
-
BEGINNING_RESET
- See Also:
-
END_TRAIN
- See Also:
-
useSpeedProfile
boolean useSpeedProfile -
prevSpeed
float prevSpeed
-
-
Constructor Details
-
AutoActiveTrain
Create an AutoActiveTrain.- Parameters:
at- the train to automate
-
-
Method Details
-
getActiveTrain
-
getAutoEngineer
-
getAutoTrainAction
-
getRosterEntry
-
getForward
-
setForward
-
setFunction
Manually set the train throttle Function value. Value passed through to the Throttle.- Parameters:
functionNum- the function number.isSet- true is on, false is off.
-
getTargetSpeed
-
setTargetSpeedByPass
-
setTargetSpeedByPass
-
setTargetSpeed
-
setTargetSpeed
-
getSavedStatus
-
setSavedStatus
-
setCurrentRampRate
-
getRampRate
-
setRampRate
-
getSpeedFactor
-
setSpeedFactor
-
getMaxSpeed
-
setMaxSpeed
-
getMinReliableOperatingSpeed
gets the lowest speed as a percentage of throttle that the loco reliably operates.- Returns:
- percentage throttle
-
setMinReliableOperatingSpeed
Sets the lowest speed as a percentage of throttle that the loco reliably operates.- Parameters:
speed- percentage of throttle.
-
setResistanceWheels
Deprecated, for removal: This API element is subject to removal in a future version.UseActiveTrain.setTrainDetection(TrainDetection valueinsteadUse- Parameters:
set- True if entire train is detectable
-
getRunInReverse
-
setRunInReverse
-
getSoundDecoder
-
setSoundDecoder
-
getMaxTrainLengthMM
- Returns:
- train length in MM.
-
setMaxTrainLength
Set Train length in Scale Meters- Parameters:
length- length of train in meterdscaleFactor- as supplied by scale object
-
setUseSpeedProfile
-
getUseSpeedProfile
-
setStopBySpeedProfile
-
setStopBySpeedProfileAdjust
-
getStopBySpeedProfile
-
getStopBySpeedProfileAdjust
-
setFunctionLight
Set the F-Number for the light- Parameters:
value- F-Number
-
getFunctionLight
Returns the F-Number for the light.- Returns:
- F-Number
-
setFunctionBell
Set the F-Number for the Bell- Parameters:
value- F-Number
-
getFunctionBell
Returns the F-Number for the Bell.- Returns:
- F-Number
-
setFunctionHorn
Set the F-Number for the Horn- Parameters:
value- F-Number
-
getFunctionHorn
Returns the F-Number for the Horn.- Returns:
- F-Number
-
getCurrentSignal
Get current Signal DisplayName.- Returns:
- empty String if no signal, otherwise Display Name.
-
getCurrentSignalUserName
Get current Signal UserName.- Returns:
- empty String if no signal, otherwise UserName.
-
initialize
Initialize new Auto Active Train or get a new throttle after WORKING Sets up the DCC address and initiates creation of a throttle to run the train.- Returns:
- true if initialized; false otherwise
-
notifyThrottleFound
Description copied from interface:ThrottleListenerGet notification that a throttle has been found as requested.- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
t- the throttle with the requested address
-
getThrottle
-
notifyFailedThrottleRequest
Description copied from interface:ThrottleListenerGet notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- address of the failed requestreason- failure cause
-
notifyDecisionRequired
No steal or share decisions made locallyGet notification that a throttle request is in use by another device, and a "steal", "share", or "steal/share" decision may be required.
- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- The LocoAddress that needs the decision.question- The question being asked, steal / cancel, share / cancel, steal / share / cancel
-
getLastAllocatedSection
-
set_useStopSensor
-
saveSpeedAndDirection
-
restoreSavedSpeedAndDirection
-
decrementHornExecution
-
incrementHornExecution
-
handleSectionStateChange
Handle notification of changes in section state.- Parameters:
as- the allocated that changed
-
handleSectionOccupancyChange
Handle notification of changes in section occupancy.- Parameters:
as- the section that changed
-
handleBlockStateChange
-
setEngineDirection
support methods -
getCurrentAllocatedSection
-
getAllocatedSectionForSection
-
allocateAFresh
-
isCurrentSignal
checks for a controlling signal- Returns:
- true if there is one
-
setupNewCurrentSignal
- Parameters:
as- current section the train is in, can be nullforceSpeedChange- if true, the speed will be set using the signal mast even if it is not on the immediate block boundary
-
canSpeedBeSetOrChecked
-
setSpeedBySignal
-
getSpeedFromBlock
-
executeStopTasks
-
initiateWorking
Initiates running in manual mode with external throttle.This method is triggered by an action in the Transit. The throttle in use for automatic operation is dispatched.
-
waitUntilStopped
Returns when train is stopped.Note: Provides for _autoEngineer becoming null during wait Ties up the current autoActiveTrain thread.
-
resumeAutomaticRunning
Resumes automatic running after a working session using an external throttle This method is triggered by the dispatcher hitting the "Resume Auto Running" button A new throttle is acquired to allow automatic running to resume -
pauseTrain
Pause the auto active train for a specified number of fast clock minutes.- Parameters:
fastMinutes- the number of minutes to pause the train- Returns:
- the thread waiting on the pause or null if already paused
-
terminate
-
dispose
-
getRampRateFromName
Convert ramp rate name, stored as a string into the constant value assigned.- Parameters:
rampRate- name of ramp rate, such as "RAMP_FAST"- Returns:
- integer representing a ramprate constant value
-
ActiveTrain.setTrainDetection(TrainDetection valueinsteadUse