Skip to content

Commit

Permalink
Separate default and new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewell committed Oct 29, 2021
1 parent d4d3256 commit 781b35d
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public override void LoadFromWagFile(string wagFilePath)
if (DieselEngines.HasGearBox)
{
Trace.TraceInformation("==================================================== Locomotive has Gearbox =========================================================");
Trace.TraceInformation("Gearbox Type: {0}, Number of Gears: {1}, Idle RpM: {2}, Max RpM: {3}, Gov RpM: {4}", DieselEngines[0].GearBox.GearBoxOperation, DieselEngines[0].GearBox.NumOfGears, DieselEngines[0].IdleRPM, DieselEngines[0].MaxRPM, DieselEngines[0].GovenorRPM);
Trace.TraceInformation("Gearbox Type: {0}, Number of Gears: {1}, Idle RpM: {2}, Max RpM: {3}, Gov RpM: {4}, GearBoxType: {5}", DieselEngines[0].GearBox.GearBoxOperation, DieselEngines[0].GearBox.NumOfGears, DieselEngines[0].IdleRPM, DieselEngines[0].MaxRPM, DieselEngines[0].GovenorRPM, DieselEngines[0].GearBox.Gears[0].TypeGearBox);

Trace.TraceInformation("Gear\t Ratio\t Max Speed\t Max TE\t Chg Up RpM\t Chg Dwn RpM\t Coast Force\t Back Force\t");

Expand Down
55 changes: 49 additions & 6 deletions Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3360,20 +3360,43 @@ public virtual void StartGearBoxIncrease()
{
if (GearBoxController != null)
{

if (this is MSTSDieselLocomotive)
{
var dieselloco = this as MSTSDieselLocomotive;
if (ThrottlePercent == 0)

// default gear
if (dieselloco.DieselEngines[0].GearBox.Gears[0].TypeGearBox == 1)
{
GearBoxController.StartIncrease();
Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Increase, GearBoxController.CurrentNotch);
AlerterReset(TCSEvent.GearBoxChanged);
SignalGearBoxChangeEvents();
}
else if (dieselloco.DieselEngines[0].GearBox.Gears[0].TypeGearBox == 2)
{
GearBoxController.StartIncrease();
Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Increase, GearBoxController.CurrentNotch);
AlerterReset(TCSEvent.GearBoxChanged);
SignalGearBoxChangeEvents();
dieselloco.DieselEngines[0].GearBox.clutchOn = false;

}
else
else if (dieselloco.DieselEngines[0].GearBox.Gears[0].TypeGearBox == 3)
{
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Throttle must be reduced to Idle before gear change can happen."));

if (ThrottlePercent == 0)
{
GearBoxController.StartIncrease();
Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Increase, GearBoxController.CurrentNotch);
AlerterReset(TCSEvent.GearBoxChanged);
SignalGearBoxChangeEvents();
dieselloco.DieselEngines[0].GearBox.clutchOn = false;
}
else
{
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Throttle must be reduced to Idle before gear change can happen."));
}
}
}
}
Expand All @@ -3400,17 +3423,37 @@ public virtual void StartGearBoxDecrease()
if (this is MSTSDieselLocomotive)
{
var dieselloco = this as MSTSDieselLocomotive;
if (ThrottlePercent == 0)

// default gear
if (dieselloco.DieselEngines[0].GearBox.Gears[0].TypeGearBox == 1)
{
GearBoxController.StartDecrease();
Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Decrease, GearBoxController.CurrentNotch);
AlerterReset(TCSEvent.GearBoxChanged);
SignalGearBoxChangeEvents();
}
else if (dieselloco.DieselEngines[0].GearBox.Gears[0].TypeGearBox == 2)
{
GearBoxController.StartDecrease();
Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Decrease, GearBoxController.CurrentNotch);
AlerterReset(TCSEvent.GearBoxChanged);
SignalGearBoxChangeEvents();
dieselloco.DieselEngines[0].GearBox.clutchOn = false;
}
else
else if (dieselloco.DieselEngines[0].GearBox.Gears[0].TypeGearBox == 3)
{
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Throttle must be reduced to Idle before gear change can happen."));
if (ThrottlePercent == 0)
{
GearBoxController.StartDecrease();
Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Decrease, GearBoxController.CurrentNotch);
AlerterReset(TCSEvent.GearBoxChanged);
SignalGearBoxChangeEvents();
dieselloco.DieselEngines[0].GearBox.clutchOn = false;
}
else
{
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Throttle must be reduced to Idle before gear change can happen."));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void Parse(string lowercasetoken, STFReader stf)
break;
case "engine(gearboxnumberofgears":
case "engine(gearboxdirectdrivegear":
case "engine(ortsgearboxtype":
case "engine(gearboxoperation":
case "engine(gearboxenginebraking":
case "engine(gearboxmaxspeedforgears":
Expand Down Expand Up @@ -1028,6 +1029,28 @@ public void Update(float elapsedClockSeconds)

RealRPM = Math.Max(RealRPM + dRPM * elapsedClockSeconds, 0);

if (HasGearBox && GearBox.GearBoxOperation == GearBoxOperation.Manual && GearBox.Gears[0].TypeGearBox == 2)
{

if (GearBox != null)
{

if (RealRPM > IdleRPM && GearBox.IsClutchOn)
{
RealRPM = GearBox.ShaftRPM;
}
}
}

// Govenor limits engine rpm
if (GovenorRPM != 0)
{
if (RealRPM > GovenorRPM)
{
RealRPM = GovenorRPM;
}
}

// Calculate the apparent throttle setting based upon the current rpm of the diesel prime mover. This allows the Tractive effort to increase with rpm to the throttle setting selected.
// This uses the reverse Tab of the Throttle vs rpm Tab.
if ((ReverseThrottleRPMTab != null) && (State == DieselEngineState.Running))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class MSTSGearBoxParams
{
public int GearBoxNumberOfGears = 1;
public int GearBoxDirectDriveGear = 1;
public int GearBoxType = 1;
public GearBoxOperation GearBoxOperation = GearBoxOperation.Manual;
public GearBoxEngineBraking GearBoxEngineBraking = GearBoxEngineBraking.None;
public List<float> GearBoxMaxSpeedForGearsMpS = new List<float>();
Expand Down Expand Up @@ -41,6 +42,7 @@ public void Parse(string lowercasetoken, STFReader stf)
{
case "engine(gearboxnumberofgears": GearBoxNumberOfGears = stf.ReadIntBlock(1); initLevel++; break;
case "engine(gearboxdirectdrivegear": GearBoxDirectDriveGear = stf.ReadIntBlock(1); break; // initLevel++; break;
case "engine(ortsgearboxtype": GearBoxType = stf.ReadIntBlock(1); break; // default = 1
case "engine(gearboxoperation":
temp = stf.ReadStringBlock("manual");
switch (temp)
Expand Down Expand Up @@ -126,6 +128,7 @@ public void Copy(MSTSGearBoxParams copy)
{
GearBoxNumberOfGears = copy.GearBoxNumberOfGears;
GearBoxDirectDriveGear = copy.GearBoxDirectDriveGear;
GearBoxType = copy.GearBoxType;
GearBoxOperation = copy.GearBoxOperation;
GearBoxEngineBraking = copy.GearBoxEngineBraking;
GearBoxMaxSpeedForGearsMpS = new List<float>(copy.GearBoxMaxSpeedForGearsMpS);
Expand Down Expand Up @@ -284,7 +287,20 @@ public float ShaftRPM
if (CurrentGear == null)
return DieselEngine.RealRPM;
else
return CurrentSpeedMpS / CurrentGear.Ratio;
{
if (Gears[0].TypeGearBox == 1)
{
return CurrentSpeedMpS / CurrentGear.Ratio;
}
else
{
const float perSectoPerMin = 60;
var driveWheelCircumferenceM = 2 * Math.PI * Locomotive.DriverWheelRadiusM;
var driveWheelRpm = Locomotive.AbsSpeedMpS * perSectoPerMin / driveWheelCircumferenceM;
var shaftRPM = driveWheelRpm * CurrentGear.Ratio;
return (float)(shaftRPM);
}
}
}
}

Expand Down Expand Up @@ -325,25 +341,46 @@ public float TractiveForceN
{
if (CurrentGear != null)
{
if (ClutchPercent >= -20)

if (Gears[0].TypeGearBox == 1)
{
if (ClutchPercent >= -20)
{
float tractiveForceN = DieselEngine.DieselTorqueTab[DieselEngine.RealRPM] * DieselEngine.DemandedThrottlePercent / DieselEngine.DieselTorqueTab.MaxY() * 0.01f * CurrentGear.MaxTractiveForceN;
if (CurrentSpeedMpS > 0)
{
if (tractiveForceN > (DieselEngine.CurrentDieselOutputPowerW / CurrentSpeedMpS))
tractiveForceN = DieselEngine.CurrentDieselOutputPowerW / CurrentSpeedMpS;
}
return tractiveForceN;
}
else
return -CurrentGear.CoastingForceN * (100f + ClutchPercent) / 100f;
}
else if (Gears[0].TypeGearBox == 2 || Gears[0].TypeGearBox == 3)
{
//float motiveForceN = DieselEngine.DemandedThrottlePercent / 100f * CurrentGear.MaxTractiveForceN;
//if (CurrentSpeedMpS > 0)
//{
// if (motiveForceN > (DieselEngine.MaxOutputPowerW / CurrentSpeedMpS))
// motiveForceN = DieselEngine.MaxOutputPowerW / CurrentSpeedMpS;
//}

float tractiveForceN = DieselEngine.DieselTorqueTab[DieselEngine.RealRPM] * DieselEngine.DemandedThrottlePercent / DieselEngine.DieselTorqueTab.MaxY() * 0.01f * CurrentGear.MaxTractiveForceN;
if (CurrentSpeedMpS > 0)

if (ClutchPercent >= -20)
{
if (tractiveForceN > (DieselEngine.CurrentDieselOutputPowerW/ CurrentSpeedMpS))
tractiveForceN = DieselEngine.CurrentDieselOutputPowerW / CurrentSpeedMpS;
float tractiveForceN = DieselEngine.DieselTorqueTab[DieselEngine.RealRPM] / DieselEngine.DieselTorqueTab.MaxY() * CurrentGear.MaxTractiveForceN;

if (CurrentSpeedMpS > 0)
{
if (tractiveForceN > (DieselEngine.RailPowerTab[DieselEngine.RealRPM] / CurrentSpeedMpS))
{
tractiveForceN = DieselEngine.RailPowerTab[DieselEngine.RealRPM] / CurrentSpeedMpS;
}

}

return tractiveForceN;

}
return tractiveForceN;
else
return -CurrentGear.CoastingForceN * (100f + ClutchPercent) / 100f;
}
else
return -CurrentGear.CoastingForceN * (100f + ClutchPercent) / 100f;
return 0;
}
else
return 0;
Expand Down Expand Up @@ -392,6 +429,7 @@ public void Initialize()
Gears.Add(new Gear(this));
Gears[i].DownGearProportion = GearBoxParams.GearBoxDownGearProportion;
Gears[i].IsDirectDriveGear = (GearBoxParams.GearBoxDirectDriveGear == GearBoxParams.GearBoxNumberOfGears);
Gears[i].TypeGearBox = GearBoxParams.GearBoxType;
Gears[i].MaxSpeedMpS = GearBoxParams.GearBoxMaxSpeedForGearsMpS[i];

// Maximum torque (tractive effort) actually occurs at less then the maximum engine rpm, so this section uses either
Expand All @@ -413,7 +451,15 @@ public void Initialize()
var driveWheelCircumferenceM = 2 * Math.PI * Locomotive.DriverWheelRadiusM;
var driveWheelRpm = pS.TopM(Gears[i].MaxSpeedMpS) / driveWheelCircumferenceM;
float apparentGear = (float)(DieselEngine.MaxRPM / driveWheelRpm);
Gears[i].Ratio = apparentGear;

if (Gears[0].TypeGearBox == 1) // Legacy default operation
{
Gears[i].Ratio = GearBoxParams.GearBoxMaxSpeedForGearsMpS[i] / DieselEngine.MaxRPM;
}
else
{
Gears[i].Ratio = apparentGear;
}

Gears[i].BackLoadForceN = Gears[i].Ratio * GearBoxParams.GearBoxBackLoadForceN;
Gears[i].CoastingForceN = Gears[i].Ratio * GearBoxParams.GearBoxCoastingForceN;
Expand Down Expand Up @@ -473,7 +519,12 @@ public void Update(float elapsedClockSeconds)
switch (GearBoxOperation)
{
case GearBoxOperation.Manual:
if (DieselEngine.Locomotive.ThrottlePercent == 0)
if (DieselEngine.GearBox.Gears[1].TypeGearBox == 3 && DieselEngine.Locomotive.ThrottlePercent == 0)
{
clutchOn = false;
ClutchPercent = 0f;
}
else
{
clutchOn = false;
ClutchPercent = 0f;
Expand Down Expand Up @@ -549,6 +600,7 @@ public enum GearBoxEngineBraking
public class Gear
{
public bool IsDirectDriveGear;
public int TypeGearBox;
public float MaxSpeedMpS;
public float ChangeUpSpeedRpM;
public float ChangeDownSpeedRpM;
Expand Down

0 comments on commit 781b35d

Please sign in to comment.