Skip to content

Commit

Permalink
update sander
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewell committed Feb 12, 2024
1 parent ab5ea99 commit f29be1e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 39 deletions.
6 changes: 6 additions & 0 deletions Source/ORTS.Common/Conversions.cs
Expand Up @@ -732,6 +732,12 @@ public static string FormatVolume(float volumeM3, bool isMetric)
return String.Format(CultureInfo.CurrentCulture, "{0:F0} {1}", volume, isMetric ? m3 : ft3);
}

public static string FormatSmallVolume(float volumeM3, bool isMetric)
{
var volume = isMetric ? volumeM3 : Me3.ToFt3(volumeM3);
return String.Format(CultureInfo.CurrentCulture, "{0:N3} {1}", volume, isMetric ? m3 : ft3);
}

public static string FormatFuelVolume(float volumeL, bool isMetric, bool isUK)
{
var volume = isMetric ? volumeL : isUK ? L.ToGUK(volumeL) : L.ToGUS(volumeL);
Expand Down
80 changes: 45 additions & 35 deletions Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs
Expand Up @@ -251,16 +251,16 @@ public enum SlipControlType

// parameters for Track Sander based upon compressor air and abrasive table for 1/2" sand blasting nozzle @ 50psi
public float MaxTrackSandBoxCapacityM3; // Capacity of sandbox
public float TrackSanderAirComsumptionForwardM3pS;
public float TrackSanderAirComsumptionReverseM3pS = 0;
public float TrackSanderSandConsumptionForwardM3pS;
public float MaxTrackSanderAirComsumptionForwardM3pS;
public float MaxTrackSanderAirComsumptionReverseM3pS = 0;
public float MaxTrackSanderSandConsumptionForwardM3pS;
public float CurrentTrackSanderAirConsumptionM3pS;
public float CurrentTrackSanderSandConsumptionM3pS;
public float CurrentTrackSandBoxCapacityM3;
public float TrackSanderSandConsumptionReverseM3pS = 0;
public float MaxTrackSanderSandConsumptionReverseM3pS = 0;
public float SandWeightKgpM3 = 1600; // One cubic metre of sand weighs about 1.54-1.78 tonnes.
public float TrackSanderSteamConsumptionForwardLbpS;
public float TrackSanderSteamConsumptionReverseLbpS = 0;
public float MaxTrackSanderSteamConsumptionForwardLbpS;
public float MaxTrackSanderSteamConsumptionReverseLbpS = 0;


// Vacuum Braking parameters
Expand Down Expand Up @@ -1150,20 +1150,20 @@ public override void Parse(string lowercasetoken, STFReader stf)
MaxTrackSandBoxCapacityM3 = Me3.FromFt3(MaxTrackSandBoxCapacityM3);
break;
case "engine(ortsmaxtracksandersandconsumptionforward":
Me3.FromFt3( TrackSanderSandConsumptionForwardM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null) );
TrackSanderSandConsumptionForwardM3pS = Me3.FromFt3(TrackSanderSandConsumptionForwardM3pS);
Me3.FromFt3( MaxTrackSanderSandConsumptionForwardM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null) );
MaxTrackSanderSandConsumptionForwardM3pS = Me3.FromFt3(MaxTrackSanderSandConsumptionForwardM3pS);
break;
case "engine(ortsmaxtracksandersandconsumptionreverse":
Me3.FromFt3(TrackSanderSandConsumptionReverseM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null));
TrackSanderSandConsumptionReverseM3pS = Me3.FromFt3(TrackSanderSandConsumptionReverseM3pS);
Me3.FromFt3(MaxTrackSanderSandConsumptionReverseM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null));
MaxTrackSanderSandConsumptionReverseM3pS = Me3.FromFt3(MaxTrackSanderSandConsumptionReverseM3pS);
break;
case "engine(ortsmaxtracksanderairconsumptionforward":
Me3.FromFt3( TrackSanderAirComsumptionForwardM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null) );
TrackSanderAirComsumptionForwardM3pS = Me3.FromFt3(TrackSanderAirComsumptionForwardM3pS);
Me3.FromFt3( MaxTrackSanderAirComsumptionForwardM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null) );
MaxTrackSanderAirComsumptionForwardM3pS = Me3.FromFt3(MaxTrackSanderAirComsumptionForwardM3pS);
break;
case "engine(ortsmaxtracksanderairconsumptionreverse":
Me3.FromFt3(TrackSanderAirComsumptionReverseM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null));
TrackSanderAirComsumptionReverseM3pS = Me3.FromFt3(TrackSanderAirComsumptionReverseM3pS);
Me3.FromFt3(MaxTrackSanderAirComsumptionReverseM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null));
MaxTrackSanderAirComsumptionReverseM3pS = Me3.FromFt3(MaxTrackSanderAirComsumptionReverseM3pS);
break;
case "engine(ortscruisecontrol": SetUpCruiseControl(stf); break;
case "engine(ortsmultipositioncontroller": SetUpMPC(stf); break;
Expand Down Expand Up @@ -1221,10 +1221,10 @@ public override void Copy(MSTSWagon copy)
SanderSpeedEffectUpToMpS = locoCopy.SanderSpeedEffectUpToMpS;
SanderSpeedOfMpS = locoCopy.SanderSpeedOfMpS;
MaxTrackSandBoxCapacityM3 = locoCopy.MaxTrackSandBoxCapacityM3;
TrackSanderSandConsumptionForwardM3pS = locoCopy.TrackSanderSandConsumptionForwardM3pS;
TrackSanderSandConsumptionReverseM3pS = locoCopy.TrackSanderSandConsumptionReverseM3pS;
TrackSanderAirComsumptionForwardM3pS = locoCopy.TrackSanderAirComsumptionForwardM3pS;
TrackSanderAirComsumptionReverseM3pS = locoCopy.TrackSanderAirComsumptionReverseM3pS;
MaxTrackSanderSandConsumptionForwardM3pS = locoCopy.MaxTrackSanderSandConsumptionForwardM3pS;
MaxTrackSanderSandConsumptionReverseM3pS = locoCopy.MaxTrackSanderSandConsumptionReverseM3pS;
MaxTrackSanderAirComsumptionForwardM3pS = locoCopy.MaxTrackSanderAirComsumptionForwardM3pS;
MaxTrackSanderAirComsumptionReverseM3pS = locoCopy.MaxTrackSanderAirComsumptionReverseM3pS;
PowerOnDelayS = locoCopy.PowerOnDelayS;
DoesHornTriggerBell = locoCopy.DoesHornTriggerBell;
MaxSteamHeatPressurePSI = locoCopy.MaxSteamHeatPressurePSI;
Expand Down Expand Up @@ -1331,7 +1331,6 @@ public override void Save(BinaryWriter outf)
outf.Write(PowerReduction);
outf.Write(ScoopIsBroken);
outf.Write(IsWaterScoopDown);
outf.Write(CurrentTrackSandBoxCapacityM3);
outf.Write(SaveAdhesionFilter);
outf.Write(GenericItem1);
outf.Write(GenericItem2);
Expand All @@ -1341,6 +1340,10 @@ public override void Save(BinaryWriter outf)
outf.Write(previousChangedGearBoxNotch);
outf.Write(DynamicBrake);
outf.Write(DynamicBrakeIntervention);
outf.Write(CurrentTrackSandBoxCapacityM3);
outf.Write(CurrentTrackSanderSandConsumptionM3pS);
outf.Write(CurrentTrackSanderAirConsumptionM3pS);


base.Save(outf);

Expand Down Expand Up @@ -1383,7 +1386,6 @@ public override void Restore(BinaryReader inf)
PowerReduction = inf.ReadSingle();
ScoopIsBroken = inf.ReadBoolean();
IsWaterScoopDown = inf.ReadBoolean();
CurrentTrackSandBoxCapacityM3 = inf.ReadSingle();

SaveAdhesionFilter = inf.ReadSingle();

Expand All @@ -1398,6 +1400,9 @@ public override void Restore(BinaryReader inf)

DynamicBrake = inf.ReadBoolean();
DynamicBrakeIntervention = inf.ReadSingle();
CurrentTrackSandBoxCapacityM3 = inf.ReadSingle();
CurrentTrackSanderSandConsumptionM3pS = inf.ReadSingle();
CurrentTrackSanderAirConsumptionM3pS = inf.ReadSingle();

base.Restore(inf);

Expand Down Expand Up @@ -1773,19 +1778,19 @@ public override void Initialize()
MaxTrackSandBoxCapacityM3 = Me3.FromFt3(40.0f); // Capacity of sandbox - assume 40.0 cu ft
}

if (TrackSanderAirComsumptionForwardM3pS == 0)
if (MaxTrackSanderAirComsumptionForwardM3pS == 0 && SandingSystemType == SandingSystemTypes.Air)
{
TrackSanderAirComsumptionForwardM3pS = Me3.FromFt3(56.0f) / 60.0f; // Default value - cubic feet per min (CFM) 28 ft3/m x 2 sanders @ 140 psi - convert to /sec values
MaxTrackSanderAirComsumptionForwardM3pS = Me3.FromFt3(56.0f) / 60.0f; // Default value - cubic feet per min (CFM) 28 ft3/m x 2 sanders @ 140 psi - convert to /sec values
}

if (TrackSanderSandConsumptionForwardM3pS == 0)
if (MaxTrackSanderSandConsumptionForwardM3pS == 0)
{
TrackSanderSandConsumptionForwardM3pS = Me3.FromFt3(3.4f) / 3600.0f; // Default value - 1.7 ft3/h x 2 sanders @ 140 psi - convert to /sec values
MaxTrackSanderSandConsumptionForwardM3pS = Me3.FromFt3(3.4f) / 3600.0f; // Default value - 1.7 ft3/h x 2 sanders @ 140 psi - convert to /sec values
}

if (TrackSanderSteamConsumptionForwardLbpS == 0 && SandingSystemType == SandingSystemTypes.Steam)
if (MaxTrackSanderSteamConsumptionForwardLbpS == 0 && SandingSystemType == SandingSystemTypes.Steam)
{
TrackSanderSteamConsumptionForwardLbpS = 300f / 3600f; // Default value - 300lbs/hr - this value is un confirmed at this stage.
MaxTrackSanderSteamConsumptionForwardLbpS = 300f / 3600f; // Default value - 300lbs/hr - this value is un confirmed at this stage.
}

base.Initialize();
Expand Down Expand Up @@ -3270,13 +3275,13 @@ public void UpdateTrackSander(float elapsedClockSeconds)

if (Direction == Direction.Reverse)
{
sandingSteamConsumptionLbpS = TrackSanderSteamConsumptionReverseLbpS;
sandingSandConsumptionM3pS = TrackSanderSandConsumptionReverseM3pS;
sandingSteamConsumptionLbpS = MaxTrackSanderSteamConsumptionReverseLbpS;
sandingSandConsumptionM3pS = MaxTrackSanderSandConsumptionReverseM3pS;
}
else
{
sandingSteamConsumptionLbpS = TrackSanderSteamConsumptionForwardLbpS;
sandingSandConsumptionM3pS = TrackSanderSandConsumptionForwardM3pS;
sandingSteamConsumptionLbpS = MaxTrackSanderSteamConsumptionForwardLbpS;
sandingSandConsumptionM3pS = MaxTrackSanderSandConsumptionForwardM3pS;
}

// Calculate steam consumption
Expand All @@ -3302,13 +3307,13 @@ public void UpdateTrackSander(float elapsedClockSeconds)

if (Direction == Direction.Reverse)
{
sandingAirConsumptionM3pS = TrackSanderAirComsumptionReverseM3pS;
sandingSandConsumptionM3pS = TrackSanderSandConsumptionReverseM3pS;
sandingAirConsumptionM3pS = MaxTrackSanderAirComsumptionReverseM3pS;
sandingSandConsumptionM3pS = MaxTrackSanderSandConsumptionReverseM3pS;
}
else
{
sandingAirConsumptionM3pS = TrackSanderAirComsumptionForwardM3pS;
sandingSandConsumptionM3pS = TrackSanderSandConsumptionForwardM3pS;
sandingAirConsumptionM3pS = MaxTrackSanderAirComsumptionForwardM3pS;
sandingSandConsumptionM3pS = MaxTrackSanderSandConsumptionForwardM3pS;
}

// Calculate air consumption and change in main air reservoir pressure
Expand All @@ -3331,7 +3336,12 @@ public void UpdateTrackSander(float elapsedClockSeconds)
}
}
}

else // reset to zero if sander is off
{
CurrentTrackSanderSandConsumptionM3pS = 0;
CurrentTrackSanderAirConsumptionM3pS = 0;
SandingSteamUsageLBpS = 0;
}
}

public override bool GetSanderOn()
Expand Down
Expand Up @@ -889,6 +889,12 @@ public override void Parse(string lowercasetoken, STFReader stf)
MSTSNumCylinders = stf.ReadIntBlock(null); break; // retained for legacy purposes
case "engine(numberofcylinders":
MSTSNumCylinders = stf.ReadIntBlock(null); break;
case "engine(ortsmaxtracksandersteamconsumptionforward":
Me3.FromFt3(MaxTrackSanderSteamConsumptionForwardLbpS = stf.ReadFloatBlock(STFReader.UNITS.Mass, null));
break;
case "engine(ortsmaxtracksandersteamconsumptionreverse":
Me3.FromFt3(MaxTrackSanderSteamConsumptionReverseLbpS = stf.ReadFloatBlock(STFReader.UNITS.Mass, null));
break;
case "engine(cylinderstroke": MSTSCylinderStrokeM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
case "engine(cylinderdiameter": MSTSCylinderDiameterM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
case "engine(lpnumcylinders": MSTSLPNumCylinders = stf.ReadIntBlock(null); break;
Expand Down Expand Up @@ -1014,6 +1020,8 @@ public override void Copy(MSTSWagon copy)
MaxSuperheatRefTempF = locoCopy.MaxSuperheatRefTempF;
MaxIndicatedHorsePowerHP = locoCopy.MaxIndicatedHorsePowerHP;
SuperheatCutoffPressureFactor = locoCopy.SuperheatCutoffPressureFactor;
MaxTrackSanderSteamConsumptionForwardLbpS = locoCopy.MaxTrackSanderSteamConsumptionForwardLbpS;
MaxTrackSanderSteamConsumptionReverseLbpS = locoCopy.MaxTrackSanderSteamConsumptionReverseLbpS;
EjectorSmallSteamConsumptionLbpS = locoCopy.EjectorSmallSteamConsumptionLbpS;
EjectorLargeSteamConsumptionLbpS = locoCopy.EjectorLargeSteamConsumptionLbpS;
ShovelMassKG = locoCopy.ShovelMassKG;
Expand Down Expand Up @@ -1111,6 +1119,7 @@ public override void Save(BinaryWriter outf)
outf.Write(EvaporationLBpS);
outf.Write(FireMassKG);
outf.Write(FlueTempK);
outf.Write(SandingSteamUsageLBpS);
outf.Write(SteamGearPosition);
ControllerFactory.Save(CutoffController, outf);
ControllerFactory.Save(Injector1Controller, outf);
Expand Down Expand Up @@ -1174,6 +1183,7 @@ public override void Restore(BinaryReader inf)
EvaporationLBpS = inf.ReadSingle();
FireMassKG = inf.ReadSingle();
FlueTempK = inf.ReadSingle();
SandingSteamUsageLBpS = inf.ReadSingle();
SteamGearPosition = inf.ReadSingle();
ControllerFactory.Restore(CutoffController, inf);
ControllerFactory.Restore(Injector1Controller, inf);
Expand Down Expand Up @@ -8003,17 +8013,35 @@ public override string GetDebugStatus()
SteamEngines[i].CalculatedFactorOfAdhesion);
}

status.AppendFormat("{0}\t{1}\t{2:N2}\t{3}\t{4:N8}/{9}\t\t{5}\t{6:N3}/{9}\t{7}\t{8:N1}\n",
if (SandingSystemType == SandingSystemTypes.Steam)
{
status.AppendFormat("{0}\t{1}\t{22}\t{3}\t{4}/{7}\t\t{5}\t{6}/{7}\n",
Simulator.Catalog.GetString("Sand:"),
Simulator.Catalog.GetString("S/Box"),
FormatStrings.FormatVolume(CurrentTrackSandBoxCapacityM3, IsMetric),
Simulator.Catalog.GetString("S/Use"),
FormatStrings.FormatSmallVolume(pS.TopH(CurrentTrackSanderSandConsumptionM3pS), IsMetric),
Simulator.Catalog.GetString("St/Use"),
FormatStrings.FormatMass(pS.TopH(SandingSteamUsageLBpS), IsMetric),
FormatStrings.h);

}
else
{

status.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}/{9}\t\t{5}\t{6}/{9}\t\t{7}\t{8:N1}\n",
Simulator.Catalog.GetString("Sand:"),
Simulator.Catalog.GetString("S/Box"),
FormatStrings.FormatVolume(CurrentTrackSandBoxCapacityM3, IsMetric),
Simulator.Catalog.GetString("S/Use"),
FormatStrings.FormatVolume(pS.TopM(CurrentTrackSanderSandConsumptionM3pS), IsMetric),
FormatStrings.FormatSmallVolume(pS.TopH(CurrentTrackSanderSandConsumptionM3pS), IsMetric),
Simulator.Catalog.GetString("A/Use"),
FormatStrings.FormatVolume(pS.TopM(CurrentTrackSanderAirConsumptionM3pS), IsMetric),
FormatStrings.FormatSmallVolume(pS.TopH(CurrentTrackSanderAirConsumptionM3pS), IsMetric),
Simulator.Catalog.GetString("M/Press"),
MainResPressurePSI,
FormatStrings.min);
FormatStrings.h);

}

status.AppendFormat("\n{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\n",
Simulator.Catalog.GetString("CylE:"),
Expand Down

0 comments on commit f29be1e

Please sign in to comment.