ATC Dimetronic: ATO acceleration
This commit is contained in:
parent
be7003669e
commit
1b04090ef1
1 changed files with 56 additions and 11 deletions
|
@ -57,6 +57,7 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
private enum AtoStates
|
private enum AtoStates
|
||||||
{
|
{
|
||||||
Inactive,
|
Inactive,
|
||||||
|
Alarm,
|
||||||
AwaitingStartup,
|
AwaitingStartup,
|
||||||
IncreaseSpeed,
|
IncreaseSpeed,
|
||||||
MaintainSpeed,
|
MaintainSpeed,
|
||||||
|
@ -70,6 +71,18 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
/// <summary>Whether ATO knows the precise position of the train or not.</summary>
|
/// <summary>Whether ATO knows the precise position of the train or not.</summary>
|
||||||
private bool AtoPositionKnown;
|
private bool AtoPositionKnown;
|
||||||
|
|
||||||
|
/// <summary>The distance travelled in ATO mode since the latest startup.</summary>
|
||||||
|
private double AtoStartupPosition;
|
||||||
|
|
||||||
|
/// <summary>The power notch to be applied by ATO.</summary>
|
||||||
|
private int AtoPowerNotch;
|
||||||
|
|
||||||
|
/// <summary>The brake notch to be applied by ATO.</summary>
|
||||||
|
private int AtoBrakeNotch;
|
||||||
|
|
||||||
|
/// <summary>Whether ATO is available or not on the train.</summary>
|
||||||
|
private readonly bool AtoAvailable;
|
||||||
|
|
||||||
/// <summary>The current position of the train.</summary>
|
/// <summary>The current position of the train.</summary>
|
||||||
private double TrainLocation;
|
private double TrainLocation;
|
||||||
|
|
||||||
|
@ -94,9 +107,6 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
/// <summary>The distance after which the rollforward protection is triggered.</summary>
|
/// <summary>The distance after which the rollforward protection is triggered.</summary>
|
||||||
private readonly double RollforwardDistance;
|
private readonly double RollforwardDistance;
|
||||||
|
|
||||||
/// <summary>Whether ATO is available or not on the train.</summary>
|
|
||||||
private readonly bool AtoAvailable;
|
|
||||||
|
|
||||||
/// <summary>The index of the alarm sound.</summary>
|
/// <summary>The index of the alarm sound.</summary>
|
||||||
private readonly int AlarmSoundIndex;
|
private readonly int AlarmSoundIndex;
|
||||||
|
|
||||||
|
@ -241,15 +251,15 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
RollforwardLocation = train.State.Location;
|
RollforwardLocation = train.State.Location;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update train location
|
// Reset ATO status outside ATO mode
|
||||||
TrainLocation = train.State.Location;
|
|
||||||
|
|
||||||
// If ATO is not the current mode, it should be in inactive state
|
|
||||||
if (DeviceState != DeviceStates.ATO)
|
if (DeviceState != DeviceStates.ATO)
|
||||||
{
|
{
|
||||||
AtoState = AtoStates.Inactive;
|
AtoState = AtoState == AtoStates.Alarm ? AtoStates.Alarm : AtoStates.Inactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update train location
|
||||||
|
TrainLocation = train.State.Location;
|
||||||
|
|
||||||
double speed = train.State.Speed.KilometersPerHour;
|
double speed = train.State.Speed.KilometersPerHour;
|
||||||
bool stopped = speed < 0.05;
|
bool stopped = speed < 0.05;
|
||||||
|
|
||||||
|
@ -285,7 +295,7 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rollforward protection
|
// Rollforward protection
|
||||||
if (train.PhysicalHandles.BrakeNotch > 0 || train.PhysicalHandles.PowerNotch > 0)
|
if (train.PhysicalHandles.BrakeNotch > 0 || train.PhysicalHandles.PowerNotch > 0 || RequestedBrakeNotch > 0 || RequestedPowerNotch > 0)
|
||||||
{
|
{
|
||||||
// The train has a power/brake notch applied, movement is expected
|
// The train has a power/brake notch applied, movement is expected
|
||||||
RollforwardTrigger = false;
|
RollforwardTrigger = false;
|
||||||
|
@ -339,6 +349,9 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
train.VigilanceOverride = false;
|
train.VigilanceOverride = false;
|
||||||
// Release control of the brakes and power
|
// Release control of the brakes and power
|
||||||
AtcControlState = AtcControlStates.Released;
|
AtcControlState = AtcControlStates.Released;
|
||||||
|
// Reset ATO data
|
||||||
|
AtoPositionKnown = false;
|
||||||
|
AtoState = AtoStates.Inactive;
|
||||||
break;
|
break;
|
||||||
// ATC device is initialized and a driving mode is required
|
// ATC device is initialized and a driving mode is required
|
||||||
case DeviceStates.NoMode:
|
case DeviceStates.NoMode:
|
||||||
|
@ -462,6 +475,10 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
// ATO start button
|
// ATO start button
|
||||||
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
||||||
{
|
{
|
||||||
|
if (AtoState == AtoStates.AwaitingStartup)
|
||||||
|
{
|
||||||
|
AtoState = AtoStates.IncreaseSpeed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VirtualKeys.B1:
|
case VirtualKeys.B1:
|
||||||
|
@ -683,12 +700,14 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
Speed target = CurrentSpeedCode.TargetLimit;
|
Speed target = CurrentSpeedCode.TargetLimit;
|
||||||
double distance = CurrentSpeedCode.TargetPosition - TrainLocation;
|
double distance = CurrentSpeedCode.TargetPosition - TrainLocation;
|
||||||
|
|
||||||
|
// Calculate notches according to state
|
||||||
switch (AtoState)
|
switch (AtoState)
|
||||||
{
|
{
|
||||||
case AtoStates.Inactive:
|
case AtoStates.Inactive:
|
||||||
// Keep train still
|
// Keep train still
|
||||||
RequestedPowerNotch = 0;
|
AtoPowerNotch = 0;
|
||||||
RequestedBrakeNotch = train.Specs.BrakeNotches + 1;
|
AtoBrakeNotch = train.Specs.BrakeNotches + 1;
|
||||||
|
AtoStartupPosition = TrainLocation;
|
||||||
|
|
||||||
// If the train is stopped, doors are closed and signal is clear, change to startup state
|
// If the train is stopped, doors are closed and signal is clear, change to startup state
|
||||||
if (stopped && train.DoorState == DoorStates.None && target.KilometersPerHour > 0)
|
if (stopped && train.DoorState == DoorStates.None && target.KilometersPerHour > 0)
|
||||||
|
@ -696,6 +715,32 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
AtoState = AtoStates.AwaitingStartup;
|
AtoState = AtoStates.AwaitingStartup;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AtoStates.Alarm:
|
||||||
|
case AtoStates.AwaitingStartup:
|
||||||
|
// Keep train still
|
||||||
|
AtoPowerNotch = 0;
|
||||||
|
AtoBrakeNotch = train.Specs.BrakeNotches + 1;
|
||||||
|
AtoStartupPosition = TrainLocation;
|
||||||
|
break;
|
||||||
|
case AtoStates.IncreaseSpeed:
|
||||||
|
AtoBrakeNotch = 0;
|
||||||
|
if (train.Acceleration < 0.2 && AtoPowerNotch < train.Specs.PowerNotches)
|
||||||
|
{
|
||||||
|
// TODO: Add delay
|
||||||
|
AtoPowerNotch++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply notches
|
||||||
|
RequestedPowerNotch = AtoPowerNotch;
|
||||||
|
RequestedBrakeNotch = AtoBrakeNotch;
|
||||||
|
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue