Skip to content

Commit e873707

Browse files
authored
Merge pull request #505 from peternewell/air-compressor#1
Set compressor to only operate on electric compressor code for v1.4
2 parents 39557af + 5eb3892 commit e873707

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,14 +2310,21 @@ protected virtual void UpdateVacuumExhauster(float elapsedClockSeconds)
23102310
protected virtual void UpdateCompressor(float elapsedClockSeconds)
23112311
{
23122312

2313+
var reservoirChargingRate = MainResChargingRatePSIpS;
2314+
2315+
// For a mechanical compressor (typically fitted to a diesel locomotive) the charging rate will be related to the RpM of the diesel engine, and therefore
2316+
// derated by an amount equivalent to the diesel RpM.
2317+
// All other locomotive types it will be the full charging rate for the reservoir
2318+
2319+
// TO DO - For v1.4 this code uses the "electric" compressor code to control the compressor. The only additional feature is the addition of a variable
2320+
// charging rate based upon the diesel engine rpm. Note that the diesel compressor code operates regardless of whether the engine is running or not.
2321+
// This needs to be corrected in a future implementation.
2322+
2323+
// If mechanical compressor then calculate charging rate based upon engine rpm
23132324
if (CompressorIsMechanical && (EngineType == EngineTypes.Control || EngineType == EngineTypes.Diesel))
23142325
{
2315-
// For a mechanical compressor (typically fitted to a diesel locomotive) the charging rate will be related to the RpM of the diesel engine, and therefore
2316-
// derated by an amount equivalent to the diesel RpM.
2317-
// All other locomotive types it will be the full charging rate for the reservoir
2318-
var reservoirChargingRate = MainResChargingRatePSIpS;
23192326

2320-
// Control car uses the attached active locomotive
2327+
// Control car uses the attached active locomotive to set the charging rate
23212328
if (EngineType == EngineTypes.Control)
23222329
{
23232330
FindControlActiveLocomotive();
@@ -2326,51 +2333,28 @@ protected virtual void UpdateCompressor(float elapsedClockSeconds)
23262333
{
23272334
var activeloco = ControlActiveLocomotive as MSTSDieselLocomotive;
23282335

2329-
// Compressors only operate when the diesel engine is running, otherwise they are off
2330-
if (activeloco.DieselEngines[0].State == DieselEngineState.Running && !CompressorIsOn)
2331-
SignalEvent(Event.CompressorOn);
2332-
else if (activeloco.DieselEngines[0].State != DieselEngineState.Running && CompressorIsOn)
2333-
SignalEvent(Event.CompressorOff);
2334-
23352336
// Set charging rate depending upon compressor rpm
23362337
reservoirChargingRate = (activeloco.DieselEngines[0].RealRPM / activeloco.DieselEngines[0].MaxRPM) * MainResChargingRatePSIpS;
23372338
}
23382339
}
23392340
else
23402341
{
2341-
// Powered locomotive use thereselves
2342+
// Powered locomotive use themselves
23422343
var mstsDieselLocomotive = this as MSTSDieselLocomotive;
23432344

2344-
// Compressors only operate when the diesel engine is running, otherwise they are off
2345-
if (mstsDieselLocomotive.DieselEngines[0].State == DieselEngineState.Running && !CompressorIsOn)
2346-
SignalEvent(Event.CompressorOn);
2347-
else if (mstsDieselLocomotive.DieselEngines[0].State != DieselEngineState.Running && CompressorIsOn)
2348-
SignalEvent(Event.CompressorOff);
2349-
23502345
// Set charging rate depending upon compressor rpm
23512346
reservoirChargingRate = (mstsDieselLocomotive.DieselEngines[0].RealRPM / mstsDieselLocomotive.DieselEngines[0].MaxRPM) * MainResChargingRatePSIpS;
23522347
}
2353-
2354-
// Only change reservoir pressure if compressor is running
2355-
if (CompressorIsOn)
2356-
{
2357-
MainResPressurePSI += elapsedClockSeconds * reservoirChargingRate;
2358-
}
2359-
2360-
// Compressor runs continuously, and excess air pressure is exhausted to atmosphere once max pressure is reached.
2361-
MainResPressurePSI = MathHelper.Clamp(MainResPressurePSI, 0.0f, MaxMainResPressurePSI);
2362-
23632348
}
2364-
else // Non-mechanical compressors
2365-
{
2366-
if (MainResPressurePSI < CompressorRestartPressurePSI && LocomotivePowerSupply.AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn && !CompressorIsOn)
2367-
SignalEvent(Event.CompressorOn);
2368-
else if ((MainResPressurePSI > MaxMainResPressurePSI || LocomotivePowerSupply.AuxiliaryPowerSupplyState != PowerSupplyState.PowerOn) && CompressorIsOn)
2369-
SignalEvent(Event.CompressorOff);
23702349

2371-
if (CompressorIsOn)
2372-
MainResPressurePSI += elapsedClockSeconds * MainResChargingRatePSIpS;
2373-
}
2350+
// Turn compressor on and off
2351+
if (MainResPressurePSI < CompressorRestartPressurePSI && LocomotivePowerSupply.AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn && !CompressorIsOn)
2352+
SignalEvent(Event.CompressorOn);
2353+
else if ((MainResPressurePSI > MaxMainResPressurePSI || LocomotivePowerSupply.AuxiliaryPowerSupplyState != PowerSupplyState.PowerOn) && CompressorIsOn)
2354+
SignalEvent(Event.CompressorOff);
2355+
2356+
if (CompressorIsOn)
2357+
MainResPressurePSI += elapsedClockSeconds * reservoirChargingRate;
23742358
}
23752359

23762360
/// <summary>

0 commit comments

Comments
 (0)