Package jmri.jmrit.logix
Class SpeedUtil
java.lang.Object
jmri.jmrit.logix.SpeedUtil
All speed related method transferred from Engineer and Warrant classes.
Until June 2017, the problem of determining the actual track speed of a
model train in millimeters per millisecond (same as meters/sec) from the
throttle setting was usually done with an ad hoc "throttle factor". When
created, the RosterSpeedProfile provides this needed conversion but
generally is not done by users for each of their locos.
Methods to dynamically determine a RosterSpeedProfile for each loco are
implemented in this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatstatic final float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Stringprotected BlockSpeedInfogetBlockSpeedInfo(int idxBlockOrder) protected voidgetBlockSpeedTimes(List<ThrottleSetting> commands, List<BlockOrder> orders) build map of BlockSpeedInfo's for the route.protected floatgetDistanceOfSpeedChange(float fromSpeed, float toSpeed, long speedTime) Return the distance traveled at current speed after a speed change was made.protected floatgetDistanceTraveled(float speedSetting, String speedtype, float time) Get distance traveled at a constant speed.protected booleanprotected RosterSpeedProfileprotected floatgetMomentumTime(float fromSpeed, float toSpeed) ms momentum time to change speed for a throttle amountprotected RampDatagetRampForSpeedChange(float fromSpeed, float toSpeed) Get the ramp for a speed change from Throttle settingsprotected floatgetRampLengthForEntry(float fromSpeed, float toSpeed) Get the ramp length for a speed change from Throttle settingsprotected floatprotected intSet the key identifier for the Speed Profile If a RosterEntry exists, _rosterId is the RosterEntry id or possibly is the RosterEntrytitle.protected DccThrottleprotected floatgetThrottleSettingForSpeed(float trackSpeed) Get the throttle setting needed to achieve a given track speed track speed is mm/ms.protected floatthrottle's minimum speed change amountprotected intgetTimeForDistance(float throttleSetting, float distance) Get time needed to travel a distance at a constant speed.protected floatgetTrackSpeed(float throttleSetting) Get the track speed in millimeters per millisecond (= meters/sec) If SpeedProfile has no speed information an estimate is given using the WarrantPreferences throttleFactor.protected voidleavingBlock(int blkIdx) Just entered a new block at 'toTime'.protected RosterEntryprotected floatmodifySpeed(float tSpeed, String sType) Modify a throttle setting to match a speed name type Modification is done according to the interpretation of the speed nameprotected static longmodifyTime(float speed, long time, float modifiedSpeed) A a train's speed at a given throttle setting and time would travel a distance.protected booleanprotected booleansecondGreaterThanFirst(String speed1, String speed2) booleansetAddress(String id) Sets dccAddress and key for a speedProfile.booleansetDccAddress(int number, String type) protected voidsetDccAddress(DccLocoAddress dccAddr) Called by: Warrant.setRunMode() about to run a warrant WarrantFrame.setup() for an existing warrant WarrantTableModel.cloneWarrant() when cloning an existing warrantprotected voidsetIsForward(boolean direction) protected voidsetRampThrottleIncrement(float incr) protected voidsetRampTimeIncrement(int incr) booleansetRosterId(String id) Set a key to a loco's roster and speed info.protected voidsetThrottle(DccThrottle throttle) protected voidspeedChange(float throttleSetting) The engineer makes this notification before setting a new speed.
-
Field Details
-
SCALE_FACTOR
- See Also:
-
MAX_TGV_SPEED
- See Also:
-
-
Constructor Details
-
SpeedUtil
protected SpeedUtil()
-
-
Method Details
-
getRosterEntry
- Returns:
- RosterEntry
-
getRosterId
Set the key identifier for the Speed Profile If a RosterEntry exists, _rosterId is the RosterEntry id or possibly is the RosterEntrytitle. Otherwise it may be just the decoder address- Returns:
- key to speedProfile
-
setRosterId
Set a key to a loco's roster and speed info. If there is no RosterEntry, the id still locates a session SpeedProfile for the loco. Called from: SpeedUtil.setDccAdress(String) - main parser WarrantFrame.setup() - edit existing warrant WarrantManagerXml - load warrant- Parameters:
id- key to speedProfile- Returns:
- true if RosterEntry exists for id
-
getDccAddress
-
getAddress
-
setDccAddress
Called by: Warrant.setRunMode() about to run a warrant WarrantFrame.setup() for an existing warrant WarrantTableModel.cloneWarrant() when cloning an existing warrant- Parameters:
dccAddr- DccLocoAddress
-
setDccAddress
-
makeRosterEntry
-
setAddress
Sets dccAddress and key for a speedProfile. Will fetch RosterEntry if one exists. If _rosterEntry exists, _rosterId set to RosterEntry Id (which may or not be "id") else _rosterId set to "id" or decoder address. Called from: DefaultConditional.takeActionIfNeeded() - execute a setDccAddress action SpeedUtil.makeSpeedTree() - need to use track speeds WarrantFrame.checkTrainId() - about to run, assures address is set Warrantroute.getRoster() - selection form _rosterBox WarrantRoute.setAddress() - whatever is in _dccNumBox.getText() WarrantRoute.setTrainPanel() - whatever in _dccNumBox.getText() WarrantTableModel.setValue() - whatever address is put into the ADDRESS_COLUMN- Parameters:
id- address as a String, either RosterEntryTitle or decoder address- Returns:
- true if address found for id
-
getRampThrottleIncrement
-
setRampThrottleIncrement
-
getRampTimeIncrement
-
setRampTimeIncrement
-
getMomentumTime
ms momentum time to change speed for a throttle amount- Parameters:
fromSpeed- throttle changetoSpeed- throttle change- Returns:
- momentum time
-
getThrottleSpeedStepIncrement
throttle's minimum speed change amount- Returns:
- speed step amount
-
getMergeProfile
-
profileHasSpeedInfo
-
setIsForward
-
getIsForward
-
setThrottle
- Parameters:
throttle- set DccThrottle
-
getThrottle
-
secondGreaterThanFirst
-
modifySpeed
Modify a throttle setting to match a speed name type Modification is done according to the interpretation of the speed name- Parameters:
tSpeed- throttle setting (current)sType- speed type name- Returns:
- modified throttle setting
-
modifyTime
A a train's speed at a given throttle setting and time would travel a distance. return the time it would take for the train at another throttle setting to travel the same distance.- Parameters:
speed- a given throttle settingtime- a given timemodifiedSpeed- a different speed setting- Returns:
- the time to travel the same distance at the different setting
-
getTrackSpeed
Get the track speed in millimeters per millisecond (= meters/sec) If SpeedProfile has no speed information an estimate is given using the WarrantPreferences throttleFactor. NOTE: Call profileHasSpeedInfo() first to determine if a reliable speed is known. for a given throttle setting and direction. SpeedProfile returns 0 if it has no speed information- Parameters:
throttleSetting- throttle setting- Returns:
- track speed in millimeters/millisecond (not mm/sec)
-
getThrottleSettingForSpeed
Get the throttle setting needed to achieve a given track speed track speed is mm/ms. SpeedProfile wants mm/s SpeedProfile returns 0 if it has no speed information- Parameters:
trackSpeed- in millimeters per millisecond (m/s)- Returns:
- throttle setting or 0
-
getDistanceTraveled
Get distance traveled at a constant speed. If this is called at a speed change the throttleSetting should be modified to reflect the average speed over the time interval.- Parameters:
speedSetting- Recorded (Normal) throttle settingspeedtype- speed name to modify throttle setting to get modified speedtime- milliseconds- Returns:
- distance in millimeters
-
getTimeForDistance
Get time needed to travel a distance at a constant speed.- Parameters:
throttleSetting- Throttle settingdistance- in millimeters- Returns:
- time in milliseconds
-
getBlockSpeedTimes
build map of BlockSpeedInfo's for the route. Map corresponds to list of BlockOrders of a Warrant- Parameters:
commands- list of script commandsorders- list of BlockOrders
-
getBlockSpeedInfo
-
getRampForSpeedChange
Get the ramp for a speed change from Throttle settings- Parameters:
fromSpeed- - starting speed settingtoSpeed- - ending speed setting- Returns:
- ramp data
-
getRampLengthForEntry
Get the ramp length for a speed change from Throttle settings- Parameters:
fromSpeed- - starting speed settingtoSpeed- - ending speed setting- Returns:
- ramp length
-
getDistanceOfSpeedChange
Return the distance traveled at current speed after a speed change was made. Takes into account the momentum configured for the decoder to change from the previous speed to the current speed. Assumes the velocity change is linear. Does not return a distance greater than that needed by momentum time.- Parameters:
fromSpeed- throttle setting when speed changed to toSpeedtoSpeed- throttle setting being setspeedTime- elapsed time from when the speed change was made to now- Returns:
- distance traveled
-
leavingBlock
Just entered a new block at 'toTime'. Do the calculation of speed of the previous block from when the previous block block was entered. Throttle changes within the block will cause different speeds. We attempt to accumulate these time and distances to calculate a weighted speed average. See method speedChange() below.- Parameters:
blkIdx- BlockOrder index of the block the engine just left. (not train) The lead engine just entered the next block after blkIdx.
-
speedChange
The engineer makes this notification before setting a new speed. Calculate the distance traveled since the last speed change.- Parameters:
throttleSetting- the new Speed of the Throttle.
-