Skip to content

Commit

Permalink
Allow independent powered axles
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarBLG committed Apr 11, 2023
1 parent 3047d0a commit 18fd051
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 147 deletions.
2 changes: 1 addition & 1 deletion Source/Orts.Simulation/Simulation/AIs/AITrain.cs
Expand Up @@ -6297,7 +6297,7 @@ public bool SwitchToPlayerControl()
if (car is MSTSLocomotive)
{
var loco = car as MSTSLocomotive;
loco.LocomotiveAxle.Reset(Simulator.GameTime, SpeedMpS);
loco.LocomotiveAxles.InitializeMoving();
loco.AntiSlip = false; // <CSComment> TODO Temporary patch until AntiSlip is re-implemented
}
if (car == Simulator.PlayerLocomotive) { leadLocomotiveIndex = j; }
Expand Down
Expand Up @@ -676,11 +676,6 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
if (TractionMotorType == TractionMotorTypes.AC)
{
AbsTractionSpeedMpS = AbsSpeedMpS;
if (AbsWheelSpeedMpS > 1.1 * MaxSpeedMpS)
{
AverageForceN = TractiveForceN = 0;
return;
}
}
else
{
Expand Down Expand Up @@ -771,6 +766,53 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
SignalEvent(Event.EnginePowerOff);
DieselEngines.HandleEvent(PowerSupplyEvent.StopEngine);
}

ApplyDirectionToTractiveForce();

// Calculate the total tractive force for the locomotive - ie Traction + Dynamic Braking force.
// Note typically only one of the above will only ever be non-zero at the one time.
// For flipped locomotives the force is "flipped" elsewhere, whereas dynamic brake force is "flipped" below by the direction of the speed.

if (DynamicBrakePercent > 0 && DynamicBrakeForceCurves != null && AbsSpeedMpS > 0)
{
float f = DynamicBrakeForceCurves.Get(.01f * DynamicBrakePercent, AbsTractionSpeedMpS);
if (f > 0 && LocomotivePowerSupply.DynamicBrakeAvailable)
{
DynamicBrakeForceN = f * (1 - PowerReduction);
TractiveForceN -= (SpeedMpS > 0 ? 1 : SpeedMpS < 0 ? -1 : Direction == Direction.Reverse ? -1 : 1) * DynamicBrakeForceN;
}
else
{
DynamicBrakeForceN = 0f;
}
}
else
DynamicBrakeForceN = 0; // Set dynamic brake force to zero if in Notch 0 position

foreach (var motor in TractionMotors)
{
motor.UpdateTractiveForce(elapsedClockSeconds, t);
}

if (Simulator.UseAdvancedAdhesion && !Simulator.Settings.SimpleControlPhysics)
{
UpdateAxleDriveForce();
}
}

protected override void UpdateAxleDriveForce()
{
/* TODO: connect different engines to different axles
if (DieselEngines.HasGearBox && DieselTransmissionType == MSTSDieselLocomotive.DieselTransmissionTypes.Mechanic)
{
foreach (var de in DieselEngines)
{
}
}
else */
{
base.UpdateAxleDriveForce();
}
}

/// <summary>
Expand Down Expand Up @@ -1088,7 +1130,7 @@ public string GetDPDebugStatus()
if (FilteredMotiveForceN != 0)
data = Math.Abs(this.FilteredMotiveForceN);
else
data = Math.Abs(this.LocomotiveAxle.DriveForceN);
data = Math.Abs(TractiveForceN);
if (DynamicBrakePercent > 0)
{
data = -Math.Abs(DynamicBrakeForceN);
Expand Down

0 comments on commit 18fd051

Please sign in to comment.