Class AutoActiveTrain
- java.lang.Object
-
- jmri.jmrit.dispatcher.AutoActiveTrain
-
- All Implemented Interfaces:
java.util.EventListener
,ThrottleListener
public class AutoActiveTrain extends java.lang.Object implements ThrottleListener
This class holds information and options for an ActiveTrain when it is running in AUTOMATIC mode. It is an extension to Active Train for automatic running.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 Classes Modifier and Type Class Description (package private) class
AutoActiveTrain.AutoEngineer
(package private) class
AutoActiveTrain.PauseTrain
Pause the train in a separate thread.(package private) class
AutoActiveTrain.WaitForTrainToStop
-
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType
-
-
Field Summary
Fields Modifier and Type Field Description static int
BEGINNING_RESET
static int
END_REVERSAL
static int
END_TRAIN
static int
LIMITED_SPEED
static int
MAXIMUM_SPEED
static int
MEDIUM_SPEED
static int
NO_TASK
static int
NORMAL_SPEED
(package private) float
prevSpeed
static int
RAMP_FAST
static int
RAMP_MED_SLOW
static int
RAMP_MEDIUM
static int
RAMP_NONE
static int
RAMP_SLOW
static int
RAMP_SPEEDPROFILE
static int
RESTRICTED_SPEED
static int
SLOW_SPEED
static int
STOP_SPEED
(package private) boolean
useSpeedProfile
-
Constructor Summary
Constructors Constructor Description AutoActiveTrain(ActiveTrain at)
Create an AutoActiveTrain.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
allocateAFresh()
protected void
decrementHornExecution()
void
dispose()
protected void
executeStopTasks(int task)
ActiveTrain
getActiveTrain()
AutoActiveTrain.AutoEngineer
getAutoEngineer()
AutoTrainAction
getAutoTrainAction()
protected AllocatedSection
getCurrentAllocatedSection()
java.lang.String
getCurrentSignal()
Get current Signal DisplayName.java.lang.String
getCurrentSignalUserName()
Get current Signal UserName.boolean
getForward()
protected Section
getLastAllocatedSection()
float
getMaxSpeed()
float
getMaxTrainLength()
int
getMaxTrainLengthMM()
float
getMinReliableOperatingSpeed()
gets the lowest speed as a percentage of throttle that the loco reliably operates.int
getRampRate()
static int
getRampRateFromName(java.lang.String rampRate)
Convert ramp rate name, stored as a string into the constant value assigned.RosterEntry
getRosterEntry()
boolean
getRunInReverse()
int
getSavedStatus()
boolean
getSoundDecoder()
float
getSpeedFactor()
protected float
getSpeedFromBlock(Block block)
boolean
getStopBySpeedProfile()
float
getStopBySpeedProfileAdjust()
float
getTargetSpeed()
protected DccThrottle
getThrottle()
boolean
getUseSpeedProfile()
protected void
handleBlockStateChange(AllocatedSection as, Block b)
protected void
handleSectionOccupancyChange(AllocatedSection as)
Handle notification of changes in section occupancy.protected void
handleSectionStateChange(AllocatedSection as)
Handle notification of changes in section state.protected void
incrementHornExecution()
boolean
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.protected void
initiateWorking()
Initiates running in manual mode with external throttle.protected boolean
isCurrentSignal()
checks for a controlling signalvoid
notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
No steal or share decisions made locallyvoid
notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Get notification that an attempt to request a throttle has failed.void
notifyThrottleFound(DccThrottle t)
Get notification that a throttle has been found as requested.java.lang.Thread
pauseTrain(int fastMinutes)
Pause the auto active train for a specified number of fast clock minutes.protected void
restoreSavedSpeedAndDirection()
protected void
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 resumeprotected void
saveSpeedAndDirection()
void
set_useStopSensor(boolean _useStopSensor)
void
setCurrentRampRate(int rate)
protected void
setEngineDirection()
support methodsvoid
setForward(boolean set)
void
setMaxSpeed(float speed)
void
setMaxTrainLength(float length)
void
setMinReliableOperatingSpeed(float speed)
Sets the lowest speed as a percentage of throttle that the loco reliably operates.void
setRampRate(int rate)
void
setResistanceWheels(boolean set)
Deprecated, for removal: This API element is subject to removal in a future version.UseActiveTrain.setTrainDetection(TrainDetection value
insteadUsevoid
setRunInReverse(boolean set)
void
setSavedStatus(int status)
void
setSoundDecoder(boolean set)
protected void
setSpeedBySignal()
void
setSpeedFactor(float factor)
void
setStopBySpeedProfile(boolean tf)
void
setStopBySpeedProfileAdjust(float adjust)
void
setTargetSpeed(float speed)
void
setTargetSpeedByPass(float speed)
protected void
setupNewCurrentSignal(AllocatedSection as, boolean forceSpeedChange)
void
setUseSpeedProfile(boolean tf)
void
terminate()
protected void
waitUntilStopped()
Returns when train is stopped.
-
-
-
Field Detail
-
STOP_SPEED
public static final int STOP_SPEED
- See Also:
- Constant Field Values
-
RESTRICTED_SPEED
public static final int RESTRICTED_SPEED
- See Also:
- Constant Field Values
-
SLOW_SPEED
public static final int SLOW_SPEED
- See Also:
- Constant Field Values
-
MEDIUM_SPEED
public static final int MEDIUM_SPEED
- See Also:
- Constant Field Values
-
LIMITED_SPEED
public static final int LIMITED_SPEED
- See Also:
- Constant Field Values
-
NORMAL_SPEED
public static final int NORMAL_SPEED
- See Also:
- Constant Field Values
-
MAXIMUM_SPEED
public static final int MAXIMUM_SPEED
- See Also:
- Constant Field Values
-
RAMP_NONE
public static final int RAMP_NONE
- See Also:
- Constant Field Values
-
RAMP_FAST
public static final int RAMP_FAST
- See Also:
- Constant Field Values
-
RAMP_MEDIUM
public static final int RAMP_MEDIUM
- See Also:
- Constant Field Values
-
RAMP_MED_SLOW
public static final int RAMP_MED_SLOW
- See Also:
- Constant Field Values
-
RAMP_SLOW
public static final int RAMP_SLOW
- See Also:
- Constant Field Values
-
RAMP_SPEEDPROFILE
public static final int RAMP_SPEEDPROFILE
- See Also:
- Constant Field Values
-
NO_TASK
public static final int NO_TASK
- See Also:
- Constant Field Values
-
END_REVERSAL
public static final int END_REVERSAL
- See Also:
- Constant Field Values
-
BEGINNING_RESET
public static final int BEGINNING_RESET
- See Also:
- Constant Field Values
-
END_TRAIN
public static final int END_TRAIN
- See Also:
- Constant Field Values
-
useSpeedProfile
boolean useSpeedProfile
-
prevSpeed
float prevSpeed
-
-
Constructor Detail
-
AutoActiveTrain
public AutoActiveTrain(ActiveTrain at)
Create an AutoActiveTrain.- Parameters:
at
- the train to automate
-
-
Method Detail
-
getActiveTrain
public ActiveTrain getActiveTrain()
-
getAutoEngineer
public AutoActiveTrain.AutoEngineer getAutoEngineer()
-
getAutoTrainAction
public AutoTrainAction getAutoTrainAction()
-
getRosterEntry
public RosterEntry getRosterEntry()
-
getForward
public boolean getForward()
-
setForward
public void setForward(boolean set)
-
getTargetSpeed
public float getTargetSpeed()
-
setTargetSpeedByPass
public void setTargetSpeedByPass(float speed)
-
setTargetSpeed
public void setTargetSpeed(float speed)
-
getSavedStatus
public int getSavedStatus()
-
setSavedStatus
public void setSavedStatus(int status)
-
setCurrentRampRate
public void setCurrentRampRate(int rate)
-
getRampRate
public int getRampRate()
-
setRampRate
public void setRampRate(int rate)
-
getSpeedFactor
public float getSpeedFactor()
-
setSpeedFactor
public void setSpeedFactor(float factor)
-
getMaxSpeed
public float getMaxSpeed()
-
setMaxSpeed
public void setMaxSpeed(float speed)
-
getMinReliableOperatingSpeed
public float getMinReliableOperatingSpeed()
gets the lowest speed as a percentage of throttle that the loco reliably operates.- Returns:
- percentage throttle
-
setMinReliableOperatingSpeed
public void setMinReliableOperatingSpeed(float speed)
Sets the lowest speed as a percentage of throttle that the loco reliably operates.- Parameters:
speed
- percentage of throttle.
-
setResistanceWheels
@Deprecated(since="5.7.6", forRemoval=true) public void setResistanceWheels(boolean set)
Deprecated, for removal: This API element is subject to removal in a future version.UseActiveTrain.setTrainDetection(TrainDetection value
insteadUse- Parameters:
set
- True if entire train is detectable
-
getRunInReverse
public boolean getRunInReverse()
-
setRunInReverse
public void setRunInReverse(boolean set)
-
getSoundDecoder
public boolean getSoundDecoder()
-
setSoundDecoder
public void setSoundDecoder(boolean set)
-
getMaxTrainLength
public float getMaxTrainLength()
-
getMaxTrainLengthMM
public int getMaxTrainLengthMM()
-
setMaxTrainLength
public void setMaxTrainLength(float length)
-
setUseSpeedProfile
public void setUseSpeedProfile(boolean tf)
-
getUseSpeedProfile
public boolean getUseSpeedProfile()
-
setStopBySpeedProfile
public void setStopBySpeedProfile(boolean tf)
-
setStopBySpeedProfileAdjust
public void setStopBySpeedProfileAdjust(float adjust)
-
getStopBySpeedProfile
public boolean getStopBySpeedProfile()
-
getStopBySpeedProfileAdjust
public float getStopBySpeedProfileAdjust()
-
getCurrentSignal
public java.lang.String getCurrentSignal()
Get current Signal DisplayName.- Returns:
- empty String if no signal, otherwise Display Name.
-
getCurrentSignalUserName
public java.lang.String getCurrentSignalUserName()
Get current Signal UserName.- Returns:
- empty String if no signal, otherwise UserName.
-
initialize
public boolean 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
public void notifyThrottleFound(DccThrottle t)
Description copied from interface:ThrottleListener
Get notification that a throttle has been found as requested.- Specified by:
notifyThrottleFound
in interfaceThrottleListener
- Parameters:
t
- the throttle with the requested address
-
getThrottle
protected DccThrottle getThrottle()
-
notifyFailedThrottleRequest
public void notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Description copied from interface:ThrottleListener
Get notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequest
in interfaceThrottleListener
- Parameters:
address
- address of the failed requestreason
- failure cause
-
notifyDecisionRequired
public void notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
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:
notifyDecisionRequired
in interfaceThrottleListener
- Parameters:
address
- The LocoAddress that needs the decision.question
- The question being asked, steal / cancel, share / cancel, steal / share / cancel
-
getLastAllocatedSection
protected Section getLastAllocatedSection()
-
set_useStopSensor
public void set_useStopSensor(boolean _useStopSensor)
-
saveSpeedAndDirection
protected void saveSpeedAndDirection()
-
restoreSavedSpeedAndDirection
protected void restoreSavedSpeedAndDirection()
-
decrementHornExecution
protected void decrementHornExecution()
-
incrementHornExecution
protected void incrementHornExecution()
-
handleSectionStateChange
protected void handleSectionStateChange(AllocatedSection as)
Handle notification of changes in section state.- Parameters:
as
- the allocated that changed
-
handleSectionOccupancyChange
protected void handleSectionOccupancyChange(AllocatedSection as)
Handle notification of changes in section occupancy.- Parameters:
as
- the section that changed
-
handleBlockStateChange
protected void handleBlockStateChange(AllocatedSection as, Block b)
-
setEngineDirection
protected void setEngineDirection()
support methods
-
getCurrentAllocatedSection
protected AllocatedSection getCurrentAllocatedSection()
-
allocateAFresh
protected void allocateAFresh()
-
isCurrentSignal
protected boolean isCurrentSignal()
checks for a controlling signal- Returns:
- true if there is one
-
setupNewCurrentSignal
protected void setupNewCurrentSignal(AllocatedSection as, boolean forceSpeedChange)
- 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
-
setSpeedBySignal
protected void setSpeedBySignal()
-
getSpeedFromBlock
protected float getSpeedFromBlock(Block block)
-
executeStopTasks
protected void executeStopTasks(int task)
-
initiateWorking
protected void 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
protected void waitUntilStopped()
Returns when train is stopped.Note: Provides for _autoEngineer becoming null during wait Ties up the current autoActiveTrain thread.
-
resumeAutomaticRunning
protected void 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
public java.lang.Thread pauseTrain(int fastMinutes)
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
public void terminate()
-
dispose
public void dispose()
-
getRampRateFromName
public static int getRampRateFromName(java.lang.String rampRate)
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
-
-