Package jmri.jmrit.roster
Class RosterSpeedProfile
- java.lang.Object
-
- jmri.jmrit.roster.RosterSpeedProfile
-
public class RosterSpeedProfile extends java.lang.Object
A simple class to store a speed profile for a given loco The speed steps against the profile are on a scale of 0 to 1000, this equates to the float speed x 1000. This allows a single profile to cover different throttle speed step settings. So a profile generate for a loco using 28 steps can be used for a throttle using 126 steps.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
RosterSpeedProfile.SpeedSetting
static class
RosterSpeedProfile.SpeedStep
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
_hasForwardSpeeds
(package private) boolean
_hasReverseSpeeds
(package private) RosterEntry
_re
(package private) DccThrottle
_throttle
(package private) float
desiredSpeedStep
(package private) float
distanceRemaining
(package private) float
distanceTravelled
(package private) float
extraDelay
(package private) int
extraTime
(package private) long
lastTimeTimerStarted
static float
MMS_TO_KPH
static float
MMS_TO_MPH
(package private) float
overRunTimeForward
(package private) float
overRunTimeReverse
(package private) NamedBean
referenced
(package private) java.util.TreeMap<java.lang.Integer,RosterSpeedProfile.SpeedStep>
speeds
(package private) java.util.LinkedList<RosterSpeedProfile.SpeedSetting>
stepQueue
(package private) javax.swing.Timer
stopTimer
-
Constructor Summary
Constructors Constructor Description RosterSpeedProfile(RosterEntry re)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) float
calculateInitialOverRun(float distance)
(package private) void
calculateStepDetails(float speedStep, float distance)
void
cancelSpeedChange()
This method is called to cancel the existing change in speed.void
changeLocoSpeed(DccThrottle t, float distance, float speed)
Set speed of a throttle.void
changeLocoSpeed(DccThrottle t, Block blk, float speed)
Set speed of a throttle.void
changeLocoSpeed(DccThrottle t, Block blk, float speed, float usePercentage)
Set speed of a throttle.void
changeLocoSpeed(DccThrottle t, Section sec, float speed)
Set speed of a throttle to a speeed set by a float, using the section for the length details Set speed of a throttle.void
changeLocoSpeed(DccThrottle t, Section sec, float speed, float usePercentage)
Set speed of a throttle.void
clearCurrentProfile()
static java.lang.String
convertMMSToScaleSpeedWithUnits(float mms)
Returns the scale speed format as a string with the units added given MilliMetres per Second.float
convertScaleSpeedToMMS(float scaleSpeed)
MilliMetres per Second given scale speed.java.lang.String
convertThrottleSettingToScaleSpeedWithUnits(float throttleSetting, boolean isForward)
Returns the scale speed format as a string with the units added given a throttle setting. and directionvoid
deleteStep(java.lang.Integer step)
(package private) void
finishChange()
reset everything back to default once the change has finished.float
getDistanceTravelled(boolean isForward, float speedStep, float duration)
Get the approximate distance a loco may travel a given duration at a given speed step.float
getDurationOfTravelInSeconds(boolean isForward, float speedStep, int distance)
Get the approximate time a loco may travel a given distance at a given speed step.float
getForwardSpeed(float speedStep)
return the forward speed in milli-meters per second for a given percentage throttlefloat
getOverRunTimeForward()
float
getOverRunTimeReverse()
int
getProfileSize()
java.util.TreeMap<java.lang.Integer,RosterSpeedProfile.SpeedStep>
getProfileSpeeds()
float
getReverseSpeed(float speedStep)
return the reverse speed in millimetres per second for a given percentage throttleRosterEntry
getRosterEntry()
float
getSpeed(float speedStep, boolean isForward)
Get track speed in millimeters per second from throttle settingRosterSpeedProfile.SpeedStep
getSpeedStep(float speed)
protected java.util.List<RosterSpeedProfile.SpeedSetting>
getSpeedStepTrace()
Gets the speed step trace array.float
getThrottleSetting(float speed, boolean isForward)
Get the throttle setting to achieve a track speedfloat
getThrottleSettingFromSignalMapSpeed(float signalMapSpeed, boolean isForward)
Converts from signal map speed to a throttle settingboolean
hasForwardSpeeds()
boolean
hasReverseSpeeds()
void
load(Element e)
float
MMSToScaleSpeed(float mms)
Returns the scale speed as a numeric. if warrent prefernces are not a speed value returned unchanged.void
setExtraInitialDelay(float eDelay)
void
setForwardSpeed(float speedStep, float forward)
void
setForwardSpeed(float throttleSetting, float speed, float speedIncrement)
Merge raw throttleSetting value with an existing profile SpeedStep if key for the throttleSetting is within the speedIncrement of the SpeedStep.(package private) void
setNextStep()
void
setOverRunTimeForward(float dt)
void
setOverRunTimeReverse(float dt)
void
setReverseSpeed(float speedStep, float reverse)
void
setReverseSpeed(float throttleSetting, float speed, float speedIncrement)
Merge raw throttleSetting value with an existing profile SpeedStep if key for the throttleSetting is within the speedIncrement of the SpeedStep.void
setSpeed(int speedStep, float forward, float reverse)
Set the speed for the given speed step.protected void
setTestMode(boolean value)
place / remove SpeedProfile from test mode.(package private) void
stopLocoTimeOut(DccThrottle t)
void
store(Element e)
-
-
-
Field Detail
-
_re
RosterEntry _re
-
overRunTimeReverse
float overRunTimeReverse
-
overRunTimeForward
float overRunTimeForward
-
_hasForwardSpeeds
boolean _hasForwardSpeeds
-
_hasReverseSpeeds
boolean _hasReverseSpeeds
-
MMS_TO_MPH
public static final float MMS_TO_MPH
- See Also:
- Constant Field Values
-
MMS_TO_KPH
public static final float MMS_TO_KPH
- See Also:
- Constant Field Values
-
distanceRemaining
float distanceRemaining
-
distanceTravelled
float distanceTravelled
-
speeds
java.util.TreeMap<java.lang.Integer,RosterSpeedProfile.SpeedStep> speeds
-
_throttle
DccThrottle _throttle
-
desiredSpeedStep
float desiredSpeedStep
-
extraDelay
float extraDelay
-
referenced
NamedBean referenced
-
stopTimer
javax.swing.Timer stopTimer
-
lastTimeTimerStarted
long lastTimeTimerStarted
-
extraTime
int extraTime
-
stepQueue
java.util.LinkedList<RosterSpeedProfile.SpeedSetting> stepQueue
-
-
Constructor Detail
-
RosterSpeedProfile
public RosterSpeedProfile(RosterEntry re)
-
-
Method Detail
-
getRosterEntry
public RosterEntry getRosterEntry()
-
getOverRunTimeForward
public float getOverRunTimeForward()
-
setOverRunTimeForward
public void setOverRunTimeForward(float dt)
-
getOverRunTimeReverse
public float getOverRunTimeReverse()
-
setOverRunTimeReverse
public void setOverRunTimeReverse(float dt)
-
clearCurrentProfile
public void clearCurrentProfile()
-
deleteStep
public void deleteStep(java.lang.Integer step)
-
hasForwardSpeeds
public boolean hasForwardSpeeds()
-
hasReverseSpeeds
public boolean hasReverseSpeeds()
-
setTestMode
protected void setTestMode(boolean value)
place / remove SpeedProfile from test mode. reinitializes speedstep trace array- Parameters:
value
- true/false
-
getSpeedStepTrace
protected java.util.List<RosterSpeedProfile.SpeedSetting> getSpeedStepTrace()
Gets the speed step trace array.- Returns:
- speedstep trace array
-
MMSToScaleSpeed
public float MMSToScaleSpeed(float mms)
Returns the scale speed as a numeric. if warrent prefernces are not a speed value returned unchanged.- Parameters:
mms
- MilliMetres per second- Returns:
- scale speed in units specified by Warrant Preferences. if warrant preferences are not a speed
-
convertMMSToScaleSpeedWithUnits
public static java.lang.String convertMMSToScaleSpeedWithUnits(float mms)
Returns the scale speed format as a string with the units added given MilliMetres per Second. If the warrant preference is a percentage of normal or throttle will use metres per second.- Parameters:
mms
- MilliMetres per second- Returns:
- a string with scale speed and units
-
convertThrottleSettingToScaleSpeedWithUnits
public java.lang.String convertThrottleSettingToScaleSpeedWithUnits(float throttleSetting, boolean isForward)
Returns the scale speed format as a string with the units added given a throttle setting. and direction- Parameters:
throttleSetting
- as percentage of 1.0isForward
- true or false- Returns:
- a string with scale speed and units
-
convertScaleSpeedToMMS
public float convertScaleSpeedToMMS(float scaleSpeed)
MilliMetres per Second given scale speed.- Parameters:
scaleSpeed
- in MPH or KPH- Returns:
- MilliMetres per second
-
getThrottleSettingFromSignalMapSpeed
public float getThrottleSettingFromSignalMapSpeed(float signalMapSpeed, boolean isForward)
Converts from signal map speed to a throttle setting- Parameters:
signalMapSpeed
- value from warrants preferencesisForward
- direction of travel- Returns:
- throttle setting
-
setSpeed
public void setSpeed(int speedStep, float forward, float reverse)
Set the speed for the given speed step.- Parameters:
speedStep
- the speed step to setforward
- speed in meters per second for running forward at speedStepreverse
- speed in meters per second for running in reverse at speedStep
-
getSpeedStep
public RosterSpeedProfile.SpeedStep getSpeedStep(float speed)
-
setForwardSpeed
public void setForwardSpeed(float speedStep, float forward)
-
setForwardSpeed
public void setForwardSpeed(float throttleSetting, float speed, float speedIncrement)
Merge raw throttleSetting value with an existing profile SpeedStep if key for the throttleSetting is within the speedIncrement of the SpeedStep.- Parameters:
throttleSetting
- raw throttle setting valuespeed
- track speedspeedIncrement
- throttle's speed step increment.
-
setReverseSpeed
public void setReverseSpeed(float throttleSetting, float speed, float speedIncrement)
Merge raw throttleSetting value with an existing profile SpeedStep if key for the throttleSetting is within the speedIncrement of the SpeedStep.- Parameters:
throttleSetting
- raw throttle setting valuespeed
- track speedspeedIncrement
- throttle's speed step increment.
-
setReverseSpeed
public void setReverseSpeed(float speedStep, float reverse)
-
getForwardSpeed
public float getForwardSpeed(float speedStep)
return the forward speed in milli-meters per second for a given percentage throttle- Parameters:
speedStep
- which is actual percentage throttle- Returns:
- MilliMetres per second using straight line interpolation for missing points
-
getReverseSpeed
public float getReverseSpeed(float speedStep)
return the reverse speed in millimetres per second for a given percentage throttle- Parameters:
speedStep
- percentage of throttle 0.nnn- Returns:
- millimetres per second
-
getDurationOfTravelInSeconds
public float getDurationOfTravelInSeconds(boolean isForward, float speedStep, int distance)
Get the approximate time a loco may travel a given distance at a given speed step.- Parameters:
isForward
- true if loco is running forward; false otherwisespeedStep
- the desired speed stepdistance
- the desired distance in millimeters- Returns:
- the approximate time in seconds
-
getDistanceTravelled
public float getDistanceTravelled(boolean isForward, float speedStep, float duration)
Get the approximate distance a loco may travel a given duration at a given speed step.- Parameters:
isForward
- true if loco is running forward; false otherwisespeedStep
- the desired speed stepduration
- the desired time in seconds- Returns:
- the approximate distance in millimeters
-
finishChange
void finishChange()
reset everything back to default once the change has finished.
-
setExtraInitialDelay
public void setExtraInitialDelay(float eDelay)
-
changeLocoSpeed
public void changeLocoSpeed(DccThrottle t, Block blk, float speed)
Set speed of a throttle.- Parameters:
t
- the throttle to setblk
- the block used for length detailsspeed
- the speed to set
-
changeLocoSpeed
public void changeLocoSpeed(DccThrottle t, Section sec, float speed, float usePercentage)
Set speed of a throttle.- Parameters:
t
- the throttle to setsec
- the section used for length detailsspeed
- the speed to setusePercentage
- the percentage of the block to be used for stopping
-
changeLocoSpeed
public void changeLocoSpeed(DccThrottle t, Block blk, float speed, float usePercentage)
Set speed of a throttle.- Parameters:
t
- the throttle to setblk
- the block used for length detailsspeed
- the speed to setusePercentage
- the percentage of the block to be used for stopping
-
changeLocoSpeed
public void changeLocoSpeed(DccThrottle t, Section sec, float speed)
Set speed of a throttle to a speeed set by a float, using the section for the length details Set speed of a throttle.- Parameters:
t
- the throttle to setsec
- the section used for length detailsspeed
- the speed to set
-
changeLocoSpeed
public void changeLocoSpeed(DccThrottle t, float distance, float speed)
Set speed of a throttle.- Parameters:
t
- the throttle to setdistance
- the distance in metersspeed
- the speed to set
-
calculateStepDetails
void calculateStepDetails(float speedStep, float distance)
-
calculateInitialOverRun
float calculateInitialOverRun(float distance)
-
stopLocoTimeOut
void stopLocoTimeOut(DccThrottle t)
-
cancelSpeedChange
public void cancelSpeedChange()
This method is called to cancel the existing change in speed.
-
setNextStep
void setNextStep()
-
getProfileSize
public int getProfileSize()
-
getProfileSpeeds
public java.util.TreeMap<java.lang.Integer,RosterSpeedProfile.SpeedStep> getProfileSpeeds()
-
getThrottleSetting
public float getThrottleSetting(float speed, boolean isForward)
Get the throttle setting to achieve a track speed- Parameters:
speed
- desired track speed in mm/secisForward
- direction- Returns:
- throttle setting
-
getSpeed
public float getSpeed(float speedStep, boolean isForward)
Get track speed in millimeters per second from throttle setting- Parameters:
speedStep
- throttle settingisForward
- direction- Returns:
- track speed
-
-