Compare commits

..

No commits in common. "4f32ecf538ed43c80eaec89094ac448db09017c2" and "be091a57841a46fe5f0e0d519fb368cb1cb17730" have entirely different histories.

2 changed files with 21 additions and 38 deletions

View file

@ -84,7 +84,7 @@ namespace OpenbveFcmbTrainPlugin
private readonly bool AtoAvailable; private readonly bool AtoAvailable;
/// <summary>The delay before ATO changes notches.</summary> /// <summary>The delay before ATO changes notches.</summary>
private readonly double AtoNotchDelay = 250; private readonly double AtoNotchDelay = 500;
/// <summary>The counter for the ATO notch delay.</summary> /// <summary>The counter for the ATO notch delay.</summary>
private double AtoNotchDelayCounter; private double AtoNotchDelayCounter;
@ -483,8 +483,6 @@ namespace OpenbveFcmbTrainPlugin
{ {
if (AtoState == AtoStates.AwaitingStartup) if (AtoState == AtoStates.AwaitingStartup)
{ {
// Release brakes to start ATO
AtoBrakeNotch = 0;
AtoState = AtoStates.IncreaseSpeed; AtoState = AtoStates.IncreaseSpeed;
} }
} }
@ -708,9 +706,6 @@ namespace OpenbveFcmbTrainPlugin
Speed target = CurrentSpeedCode.TargetLimit; Speed target = CurrentSpeedCode.TargetLimit;
double distance = CurrentSpeedCode.TargetPosition - TrainLocation; double distance = CurrentSpeedCode.TargetPosition - TrainLocation;
// Pitch multiplier, used to alter when state changes occur
double pitchMulti = train.State.Pitch / 20;
// Update notch delay counter // Update notch delay counter
AtoNotchDelayCounter += elapsedTime.Milliseconds; AtoNotchDelayCounter += elapsedTime.Milliseconds;
@ -737,42 +732,31 @@ namespace OpenbveFcmbTrainPlugin
AtoStartupPosition = TrainLocation; AtoStartupPosition = TrainLocation;
break; break;
case AtoStates.IncreaseSpeed: case AtoStates.IncreaseSpeed:
if (train.Acceleration < 0.5 && AtoNotchDelayCounter >= AtoNotchDelay) AtoBrakeNotch = 0;
{ if (train.Acceleration < 0.2 && AtoPowerNotch < train.Specs.PowerNotches && AtoNotchDelayCounter >= AtoNotchDelay)
if (AtoBrakeNotch > 0)
{
AtoBrakeNotch--;
}
else if (AtoPowerNotch < train.Specs.PowerNotches)
{ {
AtoPowerNotch++; AtoPowerNotch++;
}
AtoNotchDelayCounter = 0; AtoNotchDelayCounter = 0;
} }
if (train.State.Speed.KilometersPerHour >= target.KilometersPerHour - 5 + pitchMulti) if (train.State.Speed.KilometersPerHour >= target.KilometersPerHour - 5)
{ {
AtoState = AtoStates.MaintainSpeed; AtoState = AtoStates.MaintainSpeed;
} }
break; break;
case AtoStates.MaintainSpeed: case AtoStates.MaintainSpeed:
if ((train.Acceleration > 0 || (AtoPowerNotch > 0 && train.State.Pitch <= 0)) && AtoNotchDelayCounter >= AtoNotchDelay) AtoBrakeNotch = 0;
if (train.Acceleration > 0 && AtoNotchDelayCounter >= AtoNotchDelay)
{ {
// Train is accelerating, try to reduce speed
if (AtoPowerNotch > 0) if (AtoPowerNotch > 0)
{ {
AtoPowerNotch--; AtoPowerNotch--;
AtoNotchDelayCounter = 0;
} }
else if (AtoBrakeNotch < train.Specs.BrakeNotches && train.State.Pitch < 0 && train.State.Speed.KilometersPerHour >= target.KilometersPerHour - 3 + pitchMulti) else if (AtoBrakeNotch < train.Specs.BrakeNotches)
{ {
AtoBrakeNotch++; AtoBrakeNotch++;
}
AtoNotchDelayCounter = 0; AtoNotchDelayCounter = 0;
} }
}
if (train.State.Speed.KilometersPerHour <= target.KilometersPerHour - 7 + pitchMulti)
{
AtoState = AtoStates.IncreaseSpeed;
}
break; break;
} }
@ -783,8 +767,8 @@ namespace OpenbveFcmbTrainPlugin
// ATO is driving but does not know the position of the train, unselect driving mode and set alarm state // ATO is driving but does not know the position of the train, unselect driving mode and set alarm state
if (TrainLocation - AtoStartupPosition > 400 && !AtoPositionKnown) if (TrainLocation - AtoStartupPosition > 400 && !AtoPositionKnown)
{ {
//AtoState = AtoStates.Alarm; AtoState = AtoStates.Alarm;
//DeviceState = DeviceStates.NoMode; DeviceState = DeviceStates.NoMode;
} }
} }
} }

View file

@ -54,11 +54,8 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>The current acceleration of the train.</summary> /// <summary>The current acceleration of the train.</summary>
internal double Acceleration { get; private set; } internal double Acceleration { get; private set; }
/// <summary>The time elapsed since acceleration was last calculated.</summary> /// <summary>The time when acceleration was calculated.</summary>
private double AccelerationTimer; private Time AccelerationTime = new Time(0);
/// <summary>The maximum time elapsed between acceleration calculations.</summary>
private const double AccelerationMaximumTimer = 100;
/// <summary>The speed when acceleration was calculated.</summary> /// <summary>The speed when acceleration was calculated.</summary>
private Speed AccelerationSpeed = new Speed(0); private Speed AccelerationSpeed = new Speed(0);
@ -136,14 +133,16 @@ namespace OpenbveFcmbTrainPlugin
data.Handles.BrakeNotch = data.Handles.BrakeNotch; data.Handles.BrakeNotch = data.Handles.BrakeNotch;
// Calculate acceleration // Calculate acceleration
AccelerationTimer += data.ElapsedTime.Milliseconds; if (OpenbveFcmbTrainPlugin.Initializing)
if (AccelerationTimer >= AccelerationMaximumTimer)
{ {
Acceleration = Math.Round((data.Vehicle.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / AccelerationTimer * 1000, 4); AccelerationTime = data.TotalTime;
AccelerationTimer = 0; }
AccelerationSpeed = data.Vehicle.Speed; if (data.TotalTime.Milliseconds - AccelerationTime.Milliseconds > 200)
{
Acceleration = Math.Round((State.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / (data.TotalTime.Seconds - AccelerationTime.Seconds), 4);
AccelerationTime = data.TotalTime;
AccelerationSpeed = State.Speed;
} }
data.DebugMessage = Acceleration.ToString();
// Retrieve data from all devices // Retrieve data from all devices
foreach (Device dev in Devices) foreach (Device dev in Devices)