Class SpeedUtil

java.lang.Object
jmri.jmrit.logix.SpeedUtil

public class SpeedUtil
extends Object
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 Details

  • Constructor Details

  • Method Details

    • setIsForward

      protected void setIsForward​(boolean forward)
    • getRosterEntry

      Returns:
      RosterEntry
    • getRosterId

      public String 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

      public void setRosterId​(String id)
      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
    • getDccAddress

    • getAddress

      protected String getAddress()
    • setDccAddress

      protected void setDccAddress​(DccLocoAddress dccAddr)
      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

      public boolean setDccAddress​(int number, String type)
    • setAddress

      public boolean setAddress​(String id)
      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

      protected float getRampThrottleIncrement()
    • setRampThrottleIncrement

      protected void setRampThrottleIncrement​(float incr)
    • getRampTimeIncrement

      protected int getRampTimeIncrement()
    • setRampTimeIncrement

      protected void setRampTimeIncrement​(int incr)
    • getMomentumTime

      protected float getMomentumTime​(float delta, boolean increasing)
      ms momentum time to change speed for a throttle amount
      Parameters:
      delta - throttle change
      increasing - is acceleration
      Returns:
      momentum time
    • getThrottleSpeedStepIncrement

      protected float getThrottleSpeedStepIncrement()
      throttle's minimum speed change amount
      Returns:
      speed step amount
    • getMergeProfile

    • getSessionProfile

    • resetSpeedProfile

      protected void resetSpeedProfile()
    • profileHasSpeedInfo

      protected boolean profileHasSpeedInfo()
    • stopRun

      protected void stopRun​(boolean updateSpeedProfile)
    • setThrottle

      protected void setThrottle​(DccThrottle throttle)
      Parameters:
      throttle - set DccThrottle
    • getThrottle

      protected DccThrottle getThrottle()
    • secondGreaterThanFirst

      protected boolean secondGreaterThanFirst​(String speed1, String speed2)
    • modifySpeed

      protected float modifySpeed​(float tSpeed, String sType)
      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
    • getTrackSpeed

      protected float getTrackSpeed​(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. 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

      protected float getThrottleSettingForSpeed​(float trackSpeed)
      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

      protected float getDistanceTraveled​(float speedSetting, String speedtype, float time)
      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 setting
      speedtype - speed name to modify throttle setting to get modified speed
      time - milliseconds
      Returns:
      distance in millimeters
    • getTimeForDistance

      protected float getTimeForDistance​(float throttleSetting, float distance)
      Get time needed to travel a distance at a constant speed.
      Parameters:
      throttleSetting - Throttle setting
      distance - in millimeters
      Returns:
      time in milliseconds
    • rampLengthForRampDown

      protected float rampLengthForRampDown​(float curSetting, String curSpeedType, String toSpeedType)
      Get ramp length needed to change speed using the WarrantPreference deltas for throttle increment and time increment. This should only be used for ramping down when the warrant is interrupted for a signal or obstacle ahead. The length is increased by 40 scale feet to allow a safety margin.
      Parameters:
      curSetting - current throttle setting
      curSpeedType - current speed type
      toSpeedType - Speed type change
      Returns:
      distance in millimeters
    • getRampForSpeedChange

      protected RampData getRampForSpeedChange​(float fromSpeed, float toSpeed)
      Get the length of ramp for a speed change
      Parameters:
      fromSpeed - - starting speed setting
      toSpeed - - ending speed setting
      Returns:
      distance in millimeters
    • getDistanceOfSpeedChange

      protected float getDistanceOfSpeedChange​(float prevSpeed, float currSpeed, long speedTime)
      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.
      Parameters:
      prevSpeed - throttle setting when speed changed to currSpeed
      currSpeed - throttle setting being set
      speedTime - elapsed time from when the speed change was made to now
      Returns:
      distance traveled
    • enteredBlock

      protected void enteredBlock​(OBlock block, float length)
      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. Dynamic measurement of speed profile is being studied further. For now the only recorded speeds are those at constant speed. i.e. weighted averages not used
      Parameters:
      block - went active
      length - distance traveled. (from user's input of path lengths
    • clearStats

      protected void clearStats()
    • speedChange

      protected void speedChange()
    • setDistanceTravelled

      protected void setDistanceTravelled​(float dist)