Skip to content

Commit 962630f

Browse files
authored
Merge pull request #506 from openrails/release/1.4
Merge pull request #498 from Sharpe49/power-supply-fix-cabview-controls
2 parents 757410a + e873707 commit 962630f

File tree

4 files changed

+26
-42
lines changed

4 files changed

+26
-42
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/CircuitBreaker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public abstract class CircuitBreaker : TractionCutOffSubsystem
4646

4747
public enum CircuitBreakerState
4848
{
49-
[GetString("Unavailable")] Unavailable,
49+
[GetString("Unavailable")] Unavailable = -1,
5050
[GetParticularString("CircuitBreaker", "Open")] Open,
5151
[GetParticularString("CircuitBreaker", "Closing")] Closing,
5252
[GetParticularString("CircuitBreaker", "Closed")] Closed

Source/Orts.Simulation/Common/Scripting/PowerSupply/PowerSupply.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ public enum PowerSupplyType
160160

161161
public enum PowerSupplyState
162162
{
163-
[GetString("Unavailable")] Unavailable,
163+
[GetString("Unavailable")] Unavailable = -1,
164164
[GetParticularString("PowerSupply", "Off")] PowerOff,
165165
[GetParticularString("PowerSupply", "On ongoing")] PowerOnOngoing,
166166
[GetParticularString("PowerSupply", "On")] PowerOn
167167
}
168168

169169
public enum PantographState
170170
{
171-
[GetString("Unavailable")] Unavailable,
171+
[GetString("Unavailable")] Unavailable = -1,
172172
[GetParticularString("Pantograph", "Down")] Down,
173173
[GetParticularString("Pantograph", "Lowering")] Lowering,
174174
[GetParticularString("Pantograph", "Raising")] Raising,
@@ -177,7 +177,7 @@ public enum PantographState
177177

178178
public enum DieselEngineState
179179
{
180-
[GetString("Unavailable")] Unavailable,
180+
[GetString("Unavailable")] Unavailable = -1,
181181
[GetParticularString("Engine", "Stopped")] Stopped,
182182
[GetParticularString("Engine", "Stopping")] Stopping,
183183
[GetParticularString("Engine", "Starting")] Starting,

Source/Orts.Simulation/Common/Scripting/PowerSupply/TractionCutOffRelay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class TractionCutOffRelay : TractionCutOffSubsystem
4444

4545
public enum TractionCutOffRelayState
4646
{
47-
[GetString("Unavailable")] Unavailable,
47+
[GetString("Unavailable")] Unavailable = -1,
4848
[GetParticularString("TractionCutOffRelay", "Open")] Open,
4949
[GetParticularString("TractionCutOffRelay", "Closing")] Closing,
5050
[GetParticularString("TractionCutOffRelay", "Closed")] Closed

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)