diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs
index 1060fe6..32428b9 100644
--- a/src/Devices/AtcDimetronic.cs
+++ b/src/Devices/AtcDimetronic.cs
@@ -84,7 +84,7 @@ namespace OpenbveFcmbTrainPlugin
private readonly bool AtoAvailable;
/// The delay before ATO changes notches.
- private readonly double AtoNotchDelay = 250;
+ private readonly double AtoNotchDelay = 500;
/// The counter for the ATO notch delay.
private double AtoNotchDelayCounter;
@@ -483,8 +483,6 @@ namespace OpenbveFcmbTrainPlugin
{
if (AtoState == AtoStates.AwaitingStartup)
{
- // Release brakes to start ATO
- AtoBrakeNotch = 0;
AtoState = AtoStates.IncreaseSpeed;
}
}
@@ -708,9 +706,6 @@ namespace OpenbveFcmbTrainPlugin
Speed target = CurrentSpeedCode.TargetLimit;
double distance = CurrentSpeedCode.TargetPosition - TrainLocation;
- // Pitch multiplier, used to alter when state changes occur
- double pitchMulti = train.State.Pitch / 20;
-
// Update notch delay counter
AtoNotchDelayCounter += elapsedTime.Milliseconds;
@@ -737,41 +732,30 @@ namespace OpenbveFcmbTrainPlugin
AtoStartupPosition = TrainLocation;
break;
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;
}
- if (train.State.Speed.KilometersPerHour >= target.KilometersPerHour - 5 + pitchMulti)
+ if (train.State.Speed.KilometersPerHour >= target.KilometersPerHour - 5)
{
AtoState = AtoStates.MaintainSpeed;
}
break;
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)
{
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++;
- AtoNotchDelayCounter = 0;
}
- }
- if (train.State.Speed.KilometersPerHour <= target.KilometersPerHour - 7 + pitchMulti)
- {
- AtoState = AtoStates.IncreaseSpeed;
+ AtoNotchDelayCounter = 0;
}
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
if (TrainLocation - AtoStartupPosition > 400 && !AtoPositionKnown)
{
- //AtoState = AtoStates.Alarm;
- //DeviceState = DeviceStates.NoMode;
+ AtoState = AtoStates.Alarm;
+ DeviceState = DeviceStates.NoMode;
}
}
}
diff --git a/src/Train/Train.cs b/src/Train/Train.cs
index 4b67e22..3bcd09c 100644
--- a/src/Train/Train.cs
+++ b/src/Train/Train.cs
@@ -54,11 +54,8 @@ namespace OpenbveFcmbTrainPlugin
/// The current acceleration of the train.
internal double Acceleration { get; private set; }
- /// The time elapsed since acceleration was last calculated.
- private double AccelerationTimer;
-
- /// The maximum time elapsed between acceleration calculations.
- private const double AccelerationMaximumTimer = 100;
+ /// The time when acceleration was calculated.
+ private Time AccelerationTime = new Time(0);
/// The speed when acceleration was calculated.
private Speed AccelerationSpeed = new Speed(0);
@@ -136,14 +133,16 @@ namespace OpenbveFcmbTrainPlugin
data.Handles.BrakeNotch = data.Handles.BrakeNotch;
// Calculate acceleration
- AccelerationTimer += data.ElapsedTime.Milliseconds;
- if (AccelerationTimer >= AccelerationMaximumTimer)
+ if (OpenbveFcmbTrainPlugin.Initializing)
{
- Acceleration = Math.Round((data.Vehicle.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / AccelerationTimer * 1000, 4);
- AccelerationTimer = 0;
- AccelerationSpeed = data.Vehicle.Speed;
+ AccelerationTime = data.TotalTime;
+ }
+ 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
foreach (Device dev in Devices)