// Train Brake Controllers public override void UpdatePressure(ref float pressureBar, float elapsedClockSeconds, ref float epControllerState) { var epState = -1f; if (EmergencyBrakingPushButton() || TCSEmergencyBraking()) { pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; } else if (TCSFullServiceBraking()) { if (pressureBar > MaxPressureBar() - FullServReductionBar()) { pressureBar -= ApplyRateBarpS() * elapsedClockSeconds; } else if (pressureBar < MaxPressureBar() - FullServReductionBar()) { pressureBar = MaxPressureBar() - FullServReductionBar(); } } else { MSTSNotch notch = NotchController.GetCurrentNotch(); if (!BrakeControllerInitialised) // The first time around loop, PreviousNotchPosition will be set up front with current value, this will stop crashes due to vsalue not being initialised. { PreviousNotchPosition = NotchController.GetCurrentNotch(); BrakeControllerInitialised = true; } if (notch == null) { pressureBar = MaxPressureBar() - FullServReductionBar() * CurrentValue(); } else { epState = 0; float x = NotchController.GetNotchFraction(); switch (notch.Type) { case ControllerState.Release: pressureBar += x * ReleaseRateBarpS() * elapsedClockSeconds; epState = -1; break; case ControllerState.FullQuickRelease: pressureBar += x * QuickReleaseRateBarpS() * elapsedClockSeconds; epState = -1; break; case ControllerState.Apply: case ControllerState.FullServ: if (notch.Type == ControllerState.FullServ) { epState = x; } pressureBar -= x * ApplyRateBarpS() * elapsedClockSeconds; break; case ControllerState.Lap: // Lap position applies min service reduction when first selected, and previous contoller position was Running, then no change in pressure occurs if (PreviousNotchPosition.Type == ControllerState.Running) { pressureBar -= MinReductionBar(); epState = -1; } break; case ControllerState.MinimalReduction: // Lap position applies min service reduction when first selected, and previous contoller position was Running or Release, then no change in pressure occurs if (PreviousNotchPosition.Type == ControllerState.Running || PreviousNotchPosition.Type == ControllerState.Release || PreviousNotchPosition.Type == ControllerState.FullQuickRelease) { pressureBar -= MinReductionBar(); epState = -1; } break; case ControllerState.VacContServ: case ControllerState.VacApplyContServ: // Continuous service position for vacuum brakes - allows brake to be adjusted up and down continuously between the ON and OFF position pressureBar = (1 - x) * MaxPressureBar(); epState = -1; break; case ControllerState.EPApply: case ControllerState.GSelfLapH: case ControllerState.Suppression: case ControllerState.ContServ: case ControllerState.GSelfLap: if (notch.Type == ControllerState.EPApply || notch.Type == ControllerState.ContServ) { epState = x; } x = MaxPressureBar() - MinReductionBar() * (1 - x) - FullServReductionBar() * x; DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); if (ForceControllerReleaseGraduated) { IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); } break; case ControllerState.Emergency: pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; epState = 1; break; case ControllerState.Dummy: x *= MaxPressureBar() - FullServReductionBar(); IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); epState = -1; break; } PreviousNotchPosition = NotchController.GetCurrentNotch(); } } if (pressureBar > MaxPressureBar()) { pressureBar = MaxPressureBar(); } if (pressureBar < 0) { pressureBar = 0; } epControllerState = epState; }
public override void UpdatePressure(ref float pressureBar, float elapsedClockSeconds, ref float epControllerState) { var epState = -1f; if (EmergencyBrakingPushButton() || TCSEmergencyBraking()) { pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; } else if (TCSFullServiceBraking()) { if (pressureBar > MaxPressureBar() - FullServReductionBar()) { pressureBar -= ApplyRateBarpS() * elapsedClockSeconds; } else if (pressureBar < MaxPressureBar() - FullServReductionBar()) { pressureBar = MaxPressureBar() - FullServReductionBar(); } } else { MSTSNotch notch = NotchController.GetCurrentNotch(); if (notch == null) { pressureBar = MaxPressureBar() - FullServReductionBar() * CurrentValue(); } else { epState = 0; float x = NotchController.GetNotchFraction(); switch (notch.Type) { case ControllerState.Release: pressureBar += x * ReleaseRateBarpS() * elapsedClockSeconds; epState = -1; break; case ControllerState.FullQuickRelease: pressureBar += x * QuickReleaseRateBarpS() * elapsedClockSeconds; epState = -1; break; case ControllerState.Apply: case ControllerState.FullServ: if (notch.Type == ControllerState.FullServ) { epState = x; } pressureBar -= x * ApplyRateBarpS() * elapsedClockSeconds; break; case ControllerState.EPApply: case ControllerState.GSelfLapH: case ControllerState.Suppression: case ControllerState.ContServ: case ControllerState.GSelfLap: if (notch.Type == ControllerState.EPApply || notch.Type == ControllerState.ContServ) { epState = x; } x = MaxPressureBar() - MinReductionBar() * (1 - x) - FullServReductionBar() * x; DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); if (ForceControllerReleaseGraduated) { IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); } break; case ControllerState.Emergency: pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; epState = 1; break; case ControllerState.Dummy: x *= MaxPressureBar() - FullServReductionBar(); IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); epState = -1; break; } } } if (pressureBar > MaxPressureBar()) { pressureBar = MaxPressureBar(); } if (pressureBar < 0) { pressureBar = 0; } epControllerState = epState; }
// Train Brake Controllers public override Tuple <double, double> UpdatePressure(double pressureBar, double epPressureBar, double elapsedClockSeconds) { double epState = -1.0; if (EmergencyBrakingPushButton() || TCSEmergencyBraking()) { pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; } else if (TCSFullServiceBraking()) { if (pressureBar > MaxPressureBar() - FullServReductionBar()) { pressureBar -= ApplyRateBarpS() * elapsedClockSeconds; } else if (pressureBar < MaxPressureBar() - FullServReductionBar()) { pressureBar = MaxPressureBar() - FullServReductionBar(); } } else { INotchController notch = NotchController.GetCurrentNotch(); if (!brakeControllerInitialised) // The first time around loop, PreviousNotchPosition will be set up front with current value, this will stop crashes due to vsalue not being initialised. { previousNotchPosition = NotchController.GetCurrentNotch(); brakeControllerInitialised = true; } if (notch == null) { pressureBar = MaxPressureBar() - FullServReductionBar() * CurrentValue(); } else { epState = 0; double x = NotchController.GetNotchFraction(); ControllerState notchType = notch.NotchStateType; if (OverchargeButtonPressed()) { notchType = ControllerState.Overcharge; } else if (QuickReleaseButtonPressed()) { notchType = ControllerState.FullQuickRelease; } switch (notchType) { case ControllerState.Release: pressureBar = IncreasePressure(pressureBar, MaxPressureBar(), ReleaseRateBarpS(), elapsedClockSeconds); pressureBar = DecreasePressure(pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds); epState = -1; break; case ControllerState.FullQuickRelease: pressureBar = IncreasePressure(pressureBar, MaxPressureBar(), QuickReleaseRateBarpS(), elapsedClockSeconds); pressureBar = DecreasePressure(pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds); epState = -1; break; case ControllerState.Overcharge: pressureBar = IncreasePressure(pressureBar, Math.Min(MaxOverchargePressureBar(), MainReservoirPressureBar()), QuickReleaseRateBarpS(), elapsedClockSeconds); epState = -1; break; case ControllerState.SlowService: if (pressureBar > MaxPressureBar() - MinReductionBar()) { pressureBar = MaxPressureBar() - MinReductionBar(); } pressureBar = DecreasePressure(pressureBar, MaxPressureBar() - FullServReductionBar(), SlowApplicationRateBarpS(), elapsedClockSeconds); break; case ControllerState.Apply: pressureBar -= x * ApplyRateBarpS() * elapsedClockSeconds; break; case ControllerState.FullServ: epState = x; if (pressureBar > MaxPressureBar() - MinReductionBar()) { pressureBar = MaxPressureBar() - MinReductionBar(); } pressureBar = DecreasePressure(pressureBar, MaxPressureBar() - FullServReductionBar(), ApplyRateBarpS(), elapsedClockSeconds); break; case ControllerState.Lap: // Lap position applies min service reduction when first selected, and previous contoller position was Running, then no change in pressure occurs if (previousNotchPosition.NotchStateType == ControllerState.Running) { pressureBar -= MinReductionBar(); epState = -1; } break; case ControllerState.MinimalReduction: // Lap position applies min service reduction when first selected, and previous contoller position was Running or Release, then no change in pressure occurs if (previousNotchPosition.NotchStateType == ControllerState.Running || previousNotchPosition.NotchStateType == ControllerState.Release || previousNotchPosition.NotchStateType == ControllerState.FullQuickRelease) { pressureBar -= MinReductionBar(); epState = -1; } break; case ControllerState.ManualBraking: case ControllerState.VacContServ: // Continuous service positions for vacuum brakes - allows brake to be adjusted up and down continuously between the ON and OFF position pressureBar = (1 - x) * MaxPressureBar(); epState = -1; break; case ControllerState.EPApply: case ControllerState.EPOnly: case ControllerState.ContServ: case ControllerState.EPFullServ: epState = x; if (notch.NotchStateType == ControllerState.EPApply || notch.NotchStateType == ControllerState.ContServ) { x = MaxPressureBar() - MinReductionBar() * (1 - x) - FullServReductionBar() * x; if (pressureBar > MaxPressureBar() - MinReductionBar()) { pressureBar = MaxPressureBar() - MinReductionBar(); } pressureBar = DecreasePressure(pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); if (ForceControllerReleaseGraduated || notch.NotchStateType == ControllerState.EPApply) { pressureBar = IncreasePressure(pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); } } break; case ControllerState.GSelfLapH: case ControllerState.Suppression: case ControllerState.GSelfLap: x = MaxPressureBar() - MinReductionBar() * (1 - x) - FullServReductionBar() * x; if (pressureBar > MaxPressureBar() - MinReductionBar()) { pressureBar = MaxPressureBar() - MinReductionBar(); } pressureBar = DecreasePressure(pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); if (ForceControllerReleaseGraduated || notch.NotchStateType == ControllerState.GSelfLap) { pressureBar = IncreasePressure(pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); } break; case ControllerState.Emergency: pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; epState = 1; break; case ControllerState.Dummy: x = MaxPressureBar() - FullServReductionBar() * (notch.Smooth ? x : CurrentValue()); pressureBar = IncreasePressure(pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); pressureBar = DecreasePressure(pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); epState = -1; break; } previousNotchPosition = NotchController.GetCurrentNotch(); } } if (pressureBar < 0) { pressureBar = 0; } return(new Tuple <double, double>(pressureBar, epState)); }
// Train Brake Controllers public override void UpdatePressure(ref float pressureBar, float elapsedClockSeconds, ref float epControllerState) { var epState = -1f; if (EmergencyBrakingPushButton() || TCSEmergencyBraking()) { pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; } else if (TCSFullServiceBraking()) { if (pressureBar > MaxPressureBar() - FullServReductionBar()) { pressureBar -= ApplyRateBarpS() * elapsedClockSeconds; } else if (pressureBar < MaxPressureBar() - FullServReductionBar()) { pressureBar = MaxPressureBar() - FullServReductionBar(); } } else { MSTSNotch notch = NotchController.GetCurrentNotch(); if (!BrakeControllerInitialised) // The first time around loop, PreviousNotchPosition will be set up front with current value, this will stop crashes due to vsalue not being initialised. { PreviousNotchPosition = NotchController.GetCurrentNotch(); BrakeControllerInitialised = true; } if (notch == null) { pressureBar = MaxPressureBar() - FullServReductionBar() * CurrentValue(); } else { epState = 0; float x = NotchController.GetNotchFraction(); var type = notch.Type; if (OverchargeButtonPressed()) { type = ControllerState.Overcharge; } else if (QuickReleaseButtonPressed()) { type = ControllerState.FullQuickRelease; } switch (type) { case ControllerState.Hold: case ControllerState.Lap: case ControllerState.MinimalReduction: if (EnforceMinimalReduction) { DecreasePressure(ref pressureBar, MaxPressureBar() - MinReductionBar(), ApplyRateBarpS(), elapsedClockSeconds); } break; default: EnforceMinimalReduction = false; break; } switch (type) { case ControllerState.Release: IncreasePressure(ref pressureBar, MaxPressureBar(), ReleaseRateBarpS(), elapsedClockSeconds); DecreasePressure(ref pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds); epState = -1; break; case ControllerState.FullQuickRelease: case ControllerState.SMEReleaseStart: IncreasePressure(ref pressureBar, MaxPressureBar(), QuickReleaseRateBarpS(), elapsedClockSeconds); DecreasePressure(ref pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds); epState = -1; break; case ControllerState.Overcharge: IncreasePressure(ref pressureBar, Math.Min(MaxOverchargePressureBar(), MainReservoirPressureBar()), QuickReleaseRateBarpS(), elapsedClockSeconds); epState = -1; break; case ControllerState.SlowService: DecreasePressure(ref pressureBar, MaxPressureBar() - FullServReductionBar(), SlowApplicationRateBarpS(), elapsedClockSeconds); break; case ControllerState.StrBrkLap: case ControllerState.StrBrkApply: case ControllerState.StrBrkApplyAll: case ControllerState.StrBrkEmergency: // Nothing is done in these positions, instead they are controlled by the steam ejector in straight brake module break; case ControllerState.StrBrkRelease: case ControllerState.StrBrkReleaseOn: // This position is an on position so pressure will be zero (reversed due to vacuum brake operation) pressureBar = 0; break; case ControllerState.StrBrkReleaseOff: //(reversed due to vacuum brake operation) case ControllerState.Apply: pressureBar -= x * ApplyRateBarpS() * elapsedClockSeconds; break; case ControllerState.FullServ: epState = x; EnforceMinimalReduction = true; DecreasePressure(ref pressureBar, MaxPressureBar() - FullServReductionBar(), ApplyRateBarpS(), elapsedClockSeconds); break; case ControllerState.Lap: // Lap position applies min service reduction when first selected, and previous contoller position was Running, then no change in pressure occurs if (PreviousNotchPosition.Type == ControllerState.Running) { EnforceMinimalReduction = true; epState = -1; } break; case ControllerState.MinimalReduction: // Lap position applies min service reduction when first selected, and previous contoller position was Running or Release, then no change in pressure occurs if (PreviousNotchPosition.Type == ControllerState.Running || PreviousNotchPosition.Type == ControllerState.Release || PreviousNotchPosition.Type == ControllerState.FullQuickRelease) { EnforceMinimalReduction = true; epState = -1; } break; case ControllerState.ManualBraking: case ControllerState.VacContServ: case ControllerState.VacApplyContServ: // Continuous service position for vacuum brakes - allows brake to be adjusted up and down continuously between the ON and OFF position pressureBar = (1 - x) * MaxPressureBar(); epState = -1; break; case ControllerState.EPApply: case ControllerState.EPOnly: case ControllerState.SMEOnly: case ControllerState.ContServ: case ControllerState.EPFullServ: case ControllerState.SMEFullServ: epState = x; if (notch.Type == ControllerState.EPApply || notch.Type == ControllerState.ContServ) { EnforceMinimalReduction = true; x = MaxPressureBar() - MinReductionBar() * (1 - x) - FullServReductionBar() * x; DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); if (ForceControllerReleaseGraduated || notch.Type == ControllerState.EPApply) { IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); } } break; case ControllerState.GSelfLapH: case ControllerState.Suppression: case ControllerState.GSelfLap: EnforceMinimalReduction = true; x = MaxPressureBar() - MinReductionBar() * (1 - x) - FullServReductionBar() * x; DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); if (ForceControllerReleaseGraduated || notch.Type == ControllerState.GSelfLap) { IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); } break; case ControllerState.Emergency: pressureBar -= EmergencyRateBarpS() * elapsedClockSeconds; epState = 1; break; case ControllerState.Dummy: x = MaxPressureBar() - FullServReductionBar() * (notch.Smooth ? x : CurrentValue()); IncreasePressure(ref pressureBar, x, ReleaseRateBarpS(), elapsedClockSeconds); DecreasePressure(ref pressureBar, x, ApplyRateBarpS(), elapsedClockSeconds); epState = -1; break; } PreviousNotchPosition = NotchController.GetCurrentNotch(); } } if (pressureBar < 0) { pressureBar = 0; } epControllerState = epState; }