mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 09:27:10 +01:00
89258eb72c
The rest of the electrics of physics::Vehicle beside the traction motors
becomes components, with English names:
lowVoltage (LowVoltageSupply, Battery batteryOn, BatteryVoltage,
physics/components/lowvoltage.h) NominalBatteryVoltage, BatteryStart,
Power110vIsAvailable / Power24vIsAvailable /
Power24vVoltage power110vAvailable /
power24vAvailable / power24vVoltage, the
battery button of the cab: batteryButtonFired,
batteryButtonImpulse, batteryButtonHeld,
batteryButtonHoldTime
trainHeating (TrainHeating) Heating on, HeatingAllow allow,
HeatingSwitchImpulse switchImpulse,
HeatingPower power, EngineHeatingRPM engineRpm
brakes.electrodynamic the DynamicBrake* fields: type, ammeters,
(ElectrodynamicBrake, controllerPositions, controllerPosition,
physics/components/braking.h) resistance(1, 2), on, emuWorking;
SplitEDPneumaticBrake splitFromPneumatic;
the fans of the braking resistor (BRVentilators,
BRVto, BRVtimer, Imaxrpc): resistorFansRunning,
resistorFansSustain, resistorFansTimer,
resistorPassiveMaxCurrent
The diesel-electric dynamic brake (DEDynamicBrake) and the currents of the
traction circuit (Im, Itot, EngineVoltage ...) stay for the traction stage.
No string literal changed (checked over all the changed files).
No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
1429 lines
43 KiB
C++
1429 lines
43 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
// the master and the secondary controllers, the automatic relay and the camshaft, the integrated controller, the speed control
|
|
|
|
#include "stdafx.h"
|
|
#include "physics/vehicle.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "physics/oerlikonest.h"
|
|
#include "utilities/Globals.h"
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/Timer.h"
|
|
#include "utilities/parser.h"
|
|
#include "simulation/simulation.h"
|
|
#include "vehicle/fieldshunting.h"
|
|
#include <algorithm>
|
|
#include <charconv>
|
|
#include <cmath>
|
|
#include <format>
|
|
#include <functional>
|
|
#include <limits>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include "physics/components/internal.h"
|
|
#include "physics/components/drive.h"
|
|
|
|
|
|
// *************************************************************************************************
|
|
// queuedEU
|
|
// *************************************************************************************************
|
|
|
|
// *************************************************************************************************
|
|
// Q: 20160710
|
|
// zwiększenie nastawinika
|
|
// *************************************************************************************************
|
|
|
|
bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
|
|
{
|
|
// basic fail conditions:
|
|
if (MainCtrlPosNo <= 0 || CabActive == 0)
|
|
{
|
|
// nie ma sterowania
|
|
return false;
|
|
}
|
|
if (TrainType == train_type::et22 && ScndCtrlPos != 0)
|
|
{
|
|
// w ET22 nie da się kręcić nastawnikiem przy włączonym boczniku
|
|
return false;
|
|
}
|
|
if (TrainType == train_type::emu && DirActive == 0)
|
|
{
|
|
// w EZT nie da się załączyć pozycji bez ustawienia kierunku
|
|
return false;
|
|
}
|
|
|
|
bool OK = false;
|
|
if (MainCtrlPos < MainCtrlPosNo)
|
|
{
|
|
OK = IncMainCtrlByEngine(CtrlSpeed);
|
|
}
|
|
else
|
|
{ // MainCtrlPos>=MainCtrlPosNo
|
|
if (true == CoupledCtrl)
|
|
{
|
|
// wspólny wał nastawnika jazdy i bocznikowania
|
|
if (ScndCtrlPos < ScndCtrlPosNo)
|
|
{ // 3<3 -> false
|
|
++ScndCtrlPos;
|
|
OK = true;
|
|
}
|
|
else
|
|
{
|
|
OK = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (true == OK)
|
|
{
|
|
ScndCtrlResistiveLockCheck(); // e.g. from the last series position on to the resistive parallel ones
|
|
SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); //???
|
|
SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
|
|
}
|
|
|
|
// hunter-101012: poprawka
|
|
// poprzedni warunek byl niezbyt dobry, bo przez to przy trzymaniu +
|
|
// styczniki tkwily na tej samej pozycji (LastRelayTime byl caly czas 0 i rosl
|
|
// po puszczeniu plusa)
|
|
|
|
if (OK)
|
|
{
|
|
if (DelayCtrlFlag)
|
|
{
|
|
if (lineContactors.lastSwitchTime >= InitialCtrlDelay && MainCtrlPos == 1)
|
|
lineContactors.lastSwitchTime = 0;
|
|
}
|
|
else if (lineContactors.lastSwitchTime > CtrlDelay)
|
|
lineContactors.lastSwitchTime = 0;
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// a notch up, as the kind of the engine takes it; returns whether the controller moved
|
|
bool physics::Vehicle::IncMainCtrlByEngine(int const CtrlSpeed)
|
|
{
|
|
return Drive().IncreaseMainController(*this, CtrlSpeed);
|
|
}
|
|
|
|
// a notch up of the series motors' controller: CtrlSpeed over 1 runs it to the first position without resistors;
|
|
// returns whether it moved as asked
|
|
bool physics::Vehicle::IncMainCtrlSeriesMotor(int const CtrlSpeed)
|
|
{
|
|
bool OK = false;
|
|
if (DirActive == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (CtrlSpeed > 1)
|
|
{
|
|
// szybkie przejœcie na bezoporow¹
|
|
if (TrainType == train_type::et40)
|
|
{
|
|
return false; // this means ET40 won't react at all to fast acceleration command. should it issue just IncMainCtrl(1) instead?
|
|
}
|
|
while (RList[MainCtrlPos].R > 0.0 && IncMainCtrl(1))
|
|
{
|
|
// all work is done in the loop header
|
|
}
|
|
OK = false; // shouldn't this be part of the loop above?
|
|
// if (TrainType=train_type::et40) then
|
|
// while Abs (Im)>IminHi do
|
|
// dec(MainCtrlPos);
|
|
// OK:=false ;
|
|
}
|
|
else
|
|
{ // CtrlSpeed == 1
|
|
++MainCtrlPos;
|
|
OK = true;
|
|
if (Imax == ImaxHi && RList[MainCtrlPos].Bn > 1)
|
|
{
|
|
/* NOTE: disabled, relay configuration was moved to compute_movement_
|
|
if( true == MaxCurrentSwitch( false )) {
|
|
// wylaczanie wysokiego rozruchu
|
|
SetFlag( SoundFlag, sound::relay );
|
|
}
|
|
*/
|
|
if (TrainType == train_type::et42)
|
|
{
|
|
--MainCtrlPos;
|
|
OK = false;
|
|
}
|
|
}
|
|
//
|
|
// if (TrainType == "et40")
|
|
// if (Abs(Im) > IminHi)
|
|
// {
|
|
// MainCtrlPos--; //Blokada nastawnika po przekroczeniu minimalnego pradu
|
|
// OK = false;
|
|
// }
|
|
//}
|
|
}
|
|
|
|
if (TrainType == train_type::et42 && true == brakes.electrodynamic.on && MainCtrlPos > 20)
|
|
{
|
|
MainCtrlPos = 20;
|
|
OK = false;
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// *****************************************************************************
|
|
// Q: 20160710
|
|
// zmniejszenie nastawnika
|
|
// *****************************************************************************
|
|
bool physics::Vehicle::DecMainCtrl(int CtrlSpeed)
|
|
{
|
|
bool OK = false;
|
|
// basic fail conditions:
|
|
if (MainCtrlPosNo <= 0 || CabActive == 0)
|
|
{
|
|
// nie ma sterowania
|
|
OK = false;
|
|
}
|
|
else if (CtrlSpeed == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
// TBD, TODO: replace with mainctrlpowerpos() check?
|
|
if (MainCtrlPos > 0)
|
|
{
|
|
if (TrainType != train_type::et22 || ScndCtrlPos == 0) // Ra: ET22 blokuje nastawnik przy boczniku
|
|
{
|
|
if (CoupledCtrl && ScndCtrlPos > 0)
|
|
{
|
|
ScndCtrlPos--; // wspolny wal
|
|
OK = true;
|
|
}
|
|
else
|
|
OK = DecMainCtrlByEngine(CtrlSpeed);
|
|
}
|
|
}
|
|
else if (EngineType == TEngineType::WheelsDriven)
|
|
OK = AddPulseForce(-CtrlSpeed);
|
|
else
|
|
OK = false;
|
|
|
|
if (OK)
|
|
{
|
|
ScndCtrlResistiveLockCheck(); // the shunt drops when the master controller leaves a resistance-free position
|
|
/*OK:=*/SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); // hmmmm...???!!!
|
|
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
|
|
}
|
|
}
|
|
// if OK then LastRelayTime:=0;
|
|
// hunter-101012: poprawka
|
|
if (OK)
|
|
{
|
|
if (DelayCtrlFlag)
|
|
{
|
|
if (lineContactors.lastSwitchTime >= InitialCtrlDelay)
|
|
lineContactors.lastSwitchTime = 0;
|
|
}
|
|
else if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
|
lineContactors.lastSwitchTime = 0;
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// a notch down, as the kind of the engine takes it; returns whether the controller moved
|
|
bool physics::Vehicle::DecMainCtrlByEngine(int const CtrlSpeed)
|
|
{
|
|
return Drive().DecreaseMainController(*this, CtrlSpeed);
|
|
}
|
|
|
|
// a notch down of the series motors' controller: CtrlSpeed over 1 runs it down to the first position without resistors
|
|
bool physics::Vehicle::DecMainCtrlSeriesMotor(int const CtrlSpeed)
|
|
{
|
|
bool OK = false;
|
|
if (CtrlSpeed == 1) /*and (ScndCtrlPos=0)*/
|
|
{
|
|
MainCtrlPos--;
|
|
// if (MainCtrlPos=0) and (ScndCtrlPos=0) and
|
|
// (TrainType<>train_type::et40)and(TrainType<>train_type::ep05) then
|
|
// StLinFlag:=false;
|
|
// if (MainCtrlPos=0) and (TrainType<>train_type::et40) and
|
|
// (TrainType<>train_type::ep05) then
|
|
// MainCtrlActualPos:=0; //yBARC: co to tutaj robi? ;)
|
|
OK = true;
|
|
}
|
|
else if (CtrlSpeed > 1) /*and (ScndCtrlPos=0)*/
|
|
{
|
|
OK = true;
|
|
if (RList[MainCtrlPos].R == 0) // Q: tu zrobilem = ;]
|
|
DecMainCtrl(1);
|
|
while (RList[MainCtrlPos].R > 0 && DecMainCtrl(1))
|
|
; // takie chamskie, potem poprawie}
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
bool physics::Vehicle::IsMainCtrlActualNoPowerPos() const
|
|
{
|
|
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
|
|
return MainCtrlActualPos <= MainCtrlNoPowerPos();
|
|
}
|
|
|
|
bool physics::Vehicle::IsMainCtrlNoPowerPos() const
|
|
{
|
|
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
|
|
return MainCtrlPos <= MainCtrlNoPowerPos();
|
|
}
|
|
|
|
bool physics::Vehicle::IsMainCtrlMaxPowerPos() const
|
|
{
|
|
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
|
|
return MainCtrlPos == MainCtrlPosNo;
|
|
}
|
|
|
|
int physics::Vehicle::MainCtrlNoPowerPos() const
|
|
{
|
|
|
|
switch (EIMCtrlType)
|
|
{
|
|
case 1:
|
|
{
|
|
return 3;
|
|
}
|
|
case 2:
|
|
{
|
|
return 3 + EIMCtrlEmergencyPositions();
|
|
}
|
|
case 3:
|
|
{
|
|
return UniCtrlNoPowerPos;
|
|
}
|
|
default:
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
int physics::Vehicle::MainCtrlActualPowerPos() const
|
|
{
|
|
|
|
return MainCtrlActualPos - MainCtrlNoPowerPos();
|
|
}
|
|
|
|
int physics::Vehicle::MainCtrlPowerPos() const
|
|
{
|
|
|
|
return MainCtrlPos - MainCtrlNoPowerPos();
|
|
}
|
|
|
|
int physics::Vehicle::EIMCtrlEmergencyPositions() const
|
|
{
|
|
return (EIMCtrlType == 2 && EIMCtrlMainEmergency) ? 1 : 0;
|
|
}
|
|
|
|
bool physics::Vehicle::IsMainCtrlEmergencyPos() const
|
|
{
|
|
return MainCtrlPos < EIMCtrlEmergencyPositions();
|
|
}
|
|
|
|
int physics::Vehicle::MainCtrlPosForCoupled() const
|
|
{
|
|
// the emergency brake itself reaches the train through the brake pipe, vented by the vehicle driven from
|
|
return std::max(0, MainCtrlPos - EIMCtrlEmergencyPositions());
|
|
}
|
|
|
|
int physics::Vehicle::MainCtrlPosFromCoupled(int const Position) const
|
|
{
|
|
return Position + EIMCtrlEmergencyPositions();
|
|
}
|
|
|
|
// *************************************************************************************************
|
|
// Q: 20160710
|
|
// zwiększenie bocznika
|
|
// *************************************************************************************************
|
|
bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
|
|
{
|
|
bool OK = false;
|
|
|
|
if (brakes.electrodynamic.on && TrainType == train_type::et42 && CabActive != 0 && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0)
|
|
{
|
|
OK = DynamicBrakeSwitch(false);
|
|
}
|
|
else if (ScndCtrlPosNo > 0 && CabActive != 0 && !(TrainType == train_type::et42 && (Imax == ImaxHi || (brakes.electrodynamic.on && MainCtrlPowerPos() > 0))))
|
|
{
|
|
// if (RList[MainCtrlPos].R=0) and (MainCtrlPos>0) and (ScndCtrlPos<ScndCtrlPosNo) and
|
|
// (not CoupledCtrl) then
|
|
if (ScndCtrlPos < ScndCtrlPosNo && !CoupledCtrl && !IsScndCtrlLockedByMainCtrl())
|
|
{
|
|
// TBD, TODO: refactor this validation as part of relay check routine (currently in tractionforce()
|
|
// TBD, TODO: diesel electric engine utilize scndctrlactualpos like the other types?
|
|
if (EngineType == TEngineType::DieselElectric &&
|
|
(IsMainCtrlNoPowerPos() || fieldshunting::diesel_electric(AutoRelayType, FieldShuntSwitch, AutoRelayFlag) != fieldshunting::control::manual || ShuntMode || false == lineBreaker.closed))
|
|
{
|
|
OK = false;
|
|
}
|
|
else
|
|
{
|
|
if (CtrlSpeed == 1)
|
|
{
|
|
ScndCtrlPos++;
|
|
}
|
|
else if (CtrlSpeed > 1)
|
|
{
|
|
ScndCtrlPos = ScndCtrlPosNo; // takie chamskie, potem poprawie
|
|
}
|
|
OK = true;
|
|
}
|
|
}
|
|
else // nie mozna zmienic
|
|
OK = false;
|
|
if (OK)
|
|
{
|
|
/*OK:=*/SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); //???
|
|
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
|
|
}
|
|
}
|
|
else // nie ma sterowania
|
|
OK = false;
|
|
// if OK then LastRelayTime:=0;
|
|
// hunter-101012: poprawka
|
|
if (OK && lineContactors.lastSwitchTime > CtrlDelay)
|
|
lineContactors.lastSwitchTime = 0;
|
|
|
|
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1 && MainCtrlPos > 0)
|
|
{
|
|
SpeedCtrlValue = Vel;
|
|
if (EIMCtrlType == 0 && (SpeedCtrlAutoTurnOffFlag & 1) == 1)
|
|
{
|
|
MainCtrlActualPos = MainCtrlPos;
|
|
}
|
|
SpeedCtrlUnit.IsActive = true;
|
|
}
|
|
|
|
if (OK && SpeedCtrl && ScndCtrlPos == 1 && EngineType == TEngineType::DieselEngine)
|
|
{
|
|
// NOTE: round() already adds 0.5, are the ones added here as well correct?
|
|
SpeedCtrlValue = static_cast<double>(Round(Vel));
|
|
SpeedCtrlUnit.IsActive = true;
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
// *************************************************************************************************
|
|
// Q: 20160710
|
|
// zmniejszenie bocznika
|
|
// *************************************************************************************************
|
|
bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
|
|
{
|
|
bool OK = false;
|
|
|
|
if (IsMainCtrlNoPowerPos() && CabActive != 0 && TrainType == train_type::et42 && ScndCtrlPos == 0 && !brakes.electrodynamic.on && CtrlSpeed == 1)
|
|
{
|
|
// Ra: AI wywołuje z CtrlSpeed=2 albo gdy ScndCtrlPos>0
|
|
OK = DynamicBrakeSwitch(true);
|
|
}
|
|
else if (ScndCtrlPosNo > 0 && CabActive != 0)
|
|
{
|
|
if (ScndCtrlPos > 0 && !CoupledCtrl && (EngineType != TEngineType::DieselElectric || !AutoRelayFlag) && !IsScndCtrlLockedByMainCtrl())
|
|
{
|
|
if (CtrlSpeed == 1)
|
|
{
|
|
ScndCtrlPos--;
|
|
}
|
|
else if (CtrlSpeed > 1)
|
|
{
|
|
ScndCtrlPos = 0; // takie chamskie, potem poprawie
|
|
}
|
|
OK = true;
|
|
}
|
|
else
|
|
OK = false;
|
|
if (OK)
|
|
{
|
|
/*OK:=*/SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); //???
|
|
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
|
|
}
|
|
}
|
|
else
|
|
OK = false;
|
|
// if OK then LastRelayTime:=0;
|
|
// hunter-101012: poprawka
|
|
if (OK && lineContactors.lastSwitchTime > CtrlDownDelay)
|
|
lineContactors.lastSwitchTime = 0;
|
|
|
|
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1)
|
|
{
|
|
SpeedCtrlValue = 0;
|
|
SpeedCtrlUnit.IsActive = false;
|
|
if (SpeedCtrlUnit.ManualStateOverride)
|
|
{
|
|
eimic = 0.0;
|
|
}
|
|
}
|
|
|
|
if (OK && SpeedCtrl && ScndCtrlPos == 0 && EngineType == TEngineType::DieselEngine)
|
|
{
|
|
SpeedCtrlValue = 0;
|
|
SpeedCtrlUnit.IsActive = false;
|
|
if (SpeedCtrlUnit.ManualStateOverride)
|
|
{
|
|
eimic = 0.0;
|
|
}
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
bool physics::Vehicle::IsScndCtrlLockedByMainCtrl() const
|
|
{
|
|
// ET21, ET22, EP09: the field shunting engages only on the resistance-free positions of the master controller (eu07/maszyna#402)
|
|
return ScndCtrlResistiveLock && (IsMainCtrlNoPowerPos() || RList[MainCtrlPos].R >= 0.01);
|
|
}
|
|
|
|
void physics::Vehicle::ScndCtrlResistiveLockCheck()
|
|
{
|
|
// the shunt controller, locked in both directions on zero and the resistive positions, would otherwise stay engaged there once the
|
|
// master controller is taken back (or set from elsewhere, e.g. by the AI or another vehicle of the consist) with the shunt on
|
|
if (ScndCtrlPos > 0 && !CoupledCtrl && IsScndCtrlLockedByMainCtrl())
|
|
{
|
|
ScndCtrlPos = 0;
|
|
}
|
|
}
|
|
|
|
int physics::Vehicle::GetVirtualScndPos() const
|
|
{
|
|
if (TrainType == train_type::et42 && brakes.electrodynamic.on && !ScndCtrlPos)
|
|
return -1;
|
|
return ScndCtrlPos;
|
|
}
|
|
|
|
bool physics::Vehicle::IsScndCtrlNoPowerPos() const
|
|
{
|
|
// TODO: refine the check on account of potential electric series vehicles with speed control
|
|
return ScndCtrlPos == 0 || true == SpeedCtrl;
|
|
}
|
|
|
|
bool physics::Vehicle::IsScndCtrlMaxPowerPos() const
|
|
{
|
|
// TODO: refine the check on account of potential electric series vehicles with speed control
|
|
return ScndCtrlPos == ScndCtrlPosNo || true == SpeedCtrl;
|
|
}
|
|
|
|
// *************************************************************************************************
|
|
// Q: 20160713
|
|
// Włączenie / wyłączenie automatycznego rozruchu
|
|
// *************************************************************************************************
|
|
bool physics::Vehicle::AutoRelaySwitch(bool State)
|
|
{
|
|
bool ARS;
|
|
if (AutoRelayType == 2 && AutoRelayFlag != State)
|
|
{
|
|
AutoRelayFlag = State;
|
|
ARS = true;
|
|
SendCtrlToNext(VehicleCommand::autoRelaySwitch, int(State), CabActive);
|
|
}
|
|
else
|
|
ARS = false;
|
|
|
|
return ARS;
|
|
}
|
|
|
|
// *************************************************************************************************
|
|
// Q: 20160724
|
|
// Sprawdzenie warunków pracy automatycznego rozruchu
|
|
// *************************************************************************************************
|
|
|
|
bool physics::Vehicle::AutoRelayCheck(void)
|
|
{
|
|
bool OK = false; // b:int;
|
|
|
|
auto const motorconnectorsoff{false == MotorConnectorsCheck()};
|
|
|
|
// Ra 2014-06: dla SN61 nie działa prawidłowo
|
|
// yBARC - rozlaczenie stycznikow liniowych
|
|
if (motorconnectorsoff || (HasCamshaft ? IsMainCtrlActualNoPowerPos() : IsMainCtrlNoPowerPos()))
|
|
{
|
|
lineContactors.closed = false;
|
|
if (false == brakes.electrodynamic.on)
|
|
{
|
|
Im = 0;
|
|
Itot = 0;
|
|
ResistorsFlag = false;
|
|
}
|
|
}
|
|
|
|
// sprawdzenie wszystkich warunkow (AutoRelayFlag, AutoSwitch, Im<Imin)
|
|
auto const ARFASI2{(false == AutoRelayFlag || (motor_param(ScndCtrlActualPos).AutoSwitch && abs(Im) < Imin))};
|
|
auto const ARFASI{
|
|
(false == AutoRelayFlag || (RList[MainCtrlActualPos].AutoSwitch && abs(Im) < Imin) || (!RList[MainCtrlActualPos].AutoSwitch && RList[MainCtrlActualPos].Relay < MainCtrlPos))};
|
|
// brak PSR na tej pozycji działa PSR i prąd poniżej progu
|
|
// na tej pozycji nie działa PSR i pozycja walu ponizej
|
|
// chodzi w tym wszystkim o to, żeby można było zatrzymać rozruch na
|
|
// jakiejś pozycji wpisując Autoswitch=0 i wymuszać
|
|
// przejście dalej przez danie nastawnika na dalszą pozycję - tak to do
|
|
// tej pory działało i na tym się opiera fizyka ET22-2k
|
|
{
|
|
if (lineContactors.closed)
|
|
{
|
|
if (RList[MainCtrlActualPos].R == 0 && (ScndCtrlActualPos > 0 || ScndCtrlPos > 0) && (!CoupledCtrl || RList[MainCtrlActualPos].Relay == MainCtrlPos))
|
|
{ // zmieniaj scndctrlactualpos
|
|
OK = AutoRelayShuntStep(ARFASI2);
|
|
}
|
|
else
|
|
{ // zmieniaj mainctrlactualpos
|
|
OK = AutoRelayMainStep(ARFASI);
|
|
}
|
|
}
|
|
else // not StLinFlag
|
|
{
|
|
OK = AutoRelayLineContactorsStep(motorconnectorsoff);
|
|
}
|
|
if (OK)
|
|
lineContactors.lastSwitchTime = 0;
|
|
|
|
return OK;
|
|
}
|
|
}
|
|
|
|
// a step of the shunt field on a position without resistors, up or down to the second controller
|
|
bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2)
|
|
{
|
|
bool OK = false;
|
|
// scnd bez samoczynnego rozruchu
|
|
if (ScndCtrlActualPos < ScndCtrlPos)
|
|
{
|
|
if (lineContactors.lastSwitchTime > CtrlDelay && ARFASI2)
|
|
{
|
|
++ScndCtrlActualPos;
|
|
SetFlag(SoundFlag, sound::shuntfield);
|
|
OK = true;
|
|
}
|
|
}
|
|
else if (ScndCtrlActualPos > ScndCtrlPos)
|
|
{
|
|
if (lineContactors.lastSwitchTime > CtrlDownDelay && TrainType != train_type::emu)
|
|
{
|
|
--ScndCtrlActualPos;
|
|
SetFlag(SoundFlag, sound::shuntfield);
|
|
OK = true;
|
|
}
|
|
}
|
|
else
|
|
OK = false;
|
|
return OK;
|
|
}
|
|
|
|
// a step of the main controller's relays, up or down to its position, or the shunt field off on the resistors
|
|
bool physics::Vehicle::AutoRelayMainStep(bool const ARFASI)
|
|
{
|
|
bool OK = false;
|
|
// running backwards, the motors don't get joined in more branches than allowed (the series connection
|
|
// alone, usually); the camshaft still goes back down from there (eu07/maszyna#393: it stayed where it
|
|
// was, the line contactors closed, whatever the driver did with the master controller)
|
|
auto const backwardslimit{DirActive < 0 && TrainType != train_type::pseudodiesel && RList[MainCtrlActualPos + 1].Bn > BackwardsBranchesAllowed};
|
|
// main bez samoczynnego rozruchu
|
|
if (false == backwardslimit && MainCtrlActualPos < std::size(RList) - 1 // crude guard against running out of current fixed table
|
|
&& (RList[MainCtrlActualPos].Relay < MainCtrlPos || (RList[MainCtrlActualPos + 1].Relay == MainCtrlPos && MainCtrlActualPos < RlistSize) ||
|
|
(TrainType == train_type::et22 && DelayCtrlFlag)))
|
|
{
|
|
OK = AutoRelayMainUp(ARFASI);
|
|
}
|
|
else if (RList[MainCtrlActualPos].Relay > MainCtrlPos)
|
|
{
|
|
OK = AutoRelayMainDown();
|
|
}
|
|
else if (RList[MainCtrlActualPos].R > 0 && ScndCtrlActualPos > 0)
|
|
{
|
|
if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
|
{
|
|
--ScndCtrlActualPos; // boczniki nie dzialaja na poz. oporowych
|
|
SetFlag(SoundFlag, sound::shuntfield);
|
|
OK = true;
|
|
}
|
|
}
|
|
else
|
|
OK = false;
|
|
return OK;
|
|
}
|
|
|
|
// a step of the main relays up to the controller's position, at once to the parallel position without resistors
|
|
// on a fast serial circuit (303E); returns whether the relays moved, never into parallel with the overload relay high
|
|
bool physics::Vehicle::AutoRelayMainUp(bool const ARFASI)
|
|
{
|
|
bool OK = false;
|
|
// prevent switch to parallel mode if motor overload relay is set to high threshold mode
|
|
if (IsMotorOverloadRelayHighThresholdOn() && RList[MainCtrlActualPos + 1].Bn > 1)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (RList[MainCtrlPos].R == 0 && MainCtrlPos > 0 && MainCtrlPos != MainCtrlPosNo && FastSerialCircuit == 1)
|
|
{
|
|
// szybkie wchodzenie na bezoporowa (303E)
|
|
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
|
|
++MainCtrlActualPos;
|
|
if (MainCtrlPos - MainCtrlActualPos == 1)
|
|
{
|
|
// HACK: ensure we play only single sound of basic relays for entire trasition; return false
|
|
// for all but last step despite configuration change, to prevent playback of the basic relay sound
|
|
// TBD, TODO: move the basic sound event here and enable it with call parameter
|
|
OK = true;
|
|
}
|
|
if (RList[MainCtrlActualPos].R == 0)
|
|
{
|
|
SetFlag(SoundFlag, sound::parallel | sound::loud);
|
|
OK = true;
|
|
}
|
|
}
|
|
else if (lineContactors.lastSwitchTime > CtrlDelay && ARFASI)
|
|
{
|
|
OK = AutoRelayMainNotchUp();
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// a notch up of the main relays after their delay, through the group switch of the ET22, and the sounds of the
|
|
// parallel positions; returns whether they moved
|
|
bool physics::Vehicle::AutoRelayMainNotchUp()
|
|
{
|
|
bool OK = false;
|
|
// WriteLog("LRT = " + FloatToStr(LastRelayTime) + ", " +
|
|
// FloatToStr(CtrlDelay));
|
|
if (TrainType == train_type::et22 && MainCtrlPos > 1 && (RList[MainCtrlActualPos].Bn < RList[MainCtrlActualPos + 1].Bn || DelayCtrlFlag))
|
|
{
|
|
// et22 z walem grupowym
|
|
if (!DelayCtrlFlag) // najpierw przejscie
|
|
{
|
|
++MainCtrlActualPos;
|
|
DelayCtrlFlag = true; // tryb przejscia
|
|
OK = true;
|
|
}
|
|
else if (lineContactors.lastSwitchTime > 4 * CtrlDelay) // przejscie
|
|
{
|
|
|
|
DelayCtrlFlag = false;
|
|
OK = true;
|
|
}
|
|
/*
|
|
else
|
|
;
|
|
*/
|
|
}
|
|
else // nie ET22 z wałem grupowym
|
|
{
|
|
++MainCtrlActualPos;
|
|
OK = true;
|
|
}
|
|
//---------
|
|
// hunter-111211: poprawki
|
|
if (MainCtrlActualPos > 0)
|
|
{
|
|
if (RList[MainCtrlActualPos].R == 0 && MainCtrlActualPos != MainCtrlPosNo)
|
|
{
|
|
// wejscie na bezoporowa
|
|
SetFlag(SoundFlag, sound::parallel | sound::loud);
|
|
}
|
|
else if (RList[MainCtrlActualPos].R > 0 && RList[MainCtrlActualPos - 1].R == 0)
|
|
{
|
|
// wejscie na drugi uklad
|
|
SetFlag(SoundFlag, sound::parallel);
|
|
}
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// a step of the main relays down to the controller's position; returns whether they moved
|
|
bool physics::Vehicle::AutoRelayMainDown()
|
|
{
|
|
bool OK = false;
|
|
if (RList[MainCtrlPos].R == 0 && MainCtrlPos > 0 && !(MainCtrlPos == MainCtrlPosNo) && FastSerialCircuit == 1)
|
|
{
|
|
// szybkie wchodzenie na bezoporowa (303E)
|
|
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
|
|
--MainCtrlActualPos;
|
|
OK = true;
|
|
if (RList[MainCtrlActualPos].R == 0)
|
|
{
|
|
SetFlag(SoundFlag, sound::parallel);
|
|
}
|
|
}
|
|
else if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
|
{
|
|
if (TrainType != train_type::emu) // tutaj powinien być tryb sterowania wałem
|
|
{
|
|
--MainCtrlActualPos;
|
|
OK = true;
|
|
}
|
|
// hunter-111211: poprawki
|
|
if (MainCtrlActualPos > 0 && RList[MainCtrlActualPos].R == 0)
|
|
{
|
|
// dzwieki schodzenia z bezoporowej}
|
|
SetFlag(SoundFlag, sound::parallel);
|
|
}
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// the line contactors closed at the first position, or, open, the camshaft run back to zero
|
|
bool physics::Vehicle::AutoRelayLineContactorsStep(bool const motorconnectorsoff)
|
|
{
|
|
bool OK = false;
|
|
// ybARC - zalaczenie stycznikow liniowych
|
|
if (false == motorconnectorsoff && MainCtrlActualPos == 0 && (TrainType == train_type::emu || HasCamshaft ? MainCtrlPowerPos() > 0 : MainCtrlPowerPos() == 1))
|
|
{
|
|
|
|
DelayCtrlFlag = true;
|
|
if (lineContactors.lastSwitchTime >= InitialCtrlDelay)
|
|
{
|
|
lineContactors.closed = true;
|
|
MainCtrlActualPos = 1;
|
|
DelayCtrlFlag = false;
|
|
SetFlag(SoundFlag, sound::relay | sound::loud);
|
|
OK = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DelayCtrlFlag = false;
|
|
}
|
|
|
|
if (false == lineContactors.closed && (MainCtrlActualPos > 0 || ScndCtrlActualPos > 0))
|
|
{
|
|
OK |= CamshaftRunDown();
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// the camshaft, the line contactors open, run back to its zero position a step at a time, or at once without one;
|
|
// returns whether it moved
|
|
bool physics::Vehicle::CamshaftRunDown()
|
|
{
|
|
bool OK = false;
|
|
|
|
if (CoupledCtrl)
|
|
{
|
|
|
|
if (TrainType == train_type::emu)
|
|
{
|
|
OK = CamshaftRunDownEMU();
|
|
}
|
|
else if (lineContactors.lastSwitchTime > CtrlDownDelay) // wal kulakowy dwukierunkowy
|
|
{
|
|
if (ScndCtrlActualPos > 0)
|
|
{
|
|
--ScndCtrlActualPos;
|
|
SetFlag(SoundFlag, sound::shuntfield);
|
|
}
|
|
else
|
|
{
|
|
--MainCtrlActualPos;
|
|
}
|
|
OK = true;
|
|
}
|
|
}
|
|
else if (HasCamshaft)
|
|
{
|
|
// wal kulakowy dwukierunkowy
|
|
if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
|
{
|
|
if (MainCtrlActualPos > 0)
|
|
{
|
|
--MainCtrlActualPos;
|
|
}
|
|
ScndCtrlActualPos = 0;
|
|
OK = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MainCtrlActualPos = 0;
|
|
ScndCtrlActualPos = 0;
|
|
OK = true;
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
// the one way camshaft of the EN57 run on to its end and round to zero; returns whether it moved
|
|
bool physics::Vehicle::CamshaftRunDownEMU()
|
|
{
|
|
bool OK = false;
|
|
// EN57 wal jednokierunkowy calosciowy
|
|
if (MainCtrlActualPos == 1)
|
|
{
|
|
|
|
MainCtrlActualPos = 0;
|
|
OK = true;
|
|
}
|
|
else
|
|
{
|
|
|
|
if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
|
{
|
|
|
|
if (MainCtrlActualPos < RlistSize)
|
|
{
|
|
// dojdz do konca
|
|
++MainCtrlActualPos;
|
|
}
|
|
else if (ScndCtrlActualPos < ScndCtrlPosNo)
|
|
{
|
|
// potem boki
|
|
++ScndCtrlActualPos;
|
|
SetFlag(SoundFlag, sound::shuntfield);
|
|
}
|
|
else
|
|
{
|
|
// i sie przewroc na koniec
|
|
MainCtrlActualPos = 0;
|
|
ScndCtrlActualPos = 0;
|
|
}
|
|
OK = true;
|
|
}
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
bool physics::Vehicle::MotorConnectorsCheck()
|
|
{
|
|
|
|
// hunter-111211: wylacznik cisnieniowy
|
|
// (on some vehicles it watches the brake pipe alone)
|
|
protection.pressureSwitch = protection.hasPressureSwitch && ((protection.pressureSwitchWatchesCylinders && brakes.cylinderPressure > 2.0) || brakePipe.pressure < 3.6);
|
|
|
|
if (true == protection.pressureSwitch)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// a line breaker closed ahead of the pantographs holds without voltage; what cuts the motors off there is its
|
|
// undervoltage relay, which elsewhere opens the line breaker
|
|
auto const undervoltage{lineBreaker.pantographsRequireIt && false == protection.noVoltage};
|
|
|
|
auto const connectorsoff{false == lineBreaker.closed || undervoltage || true == FuseFlag || true == lineContactors.forcedOpen || DirActive == 0};
|
|
|
|
return false == connectorsoff && LineContactorsInterlockReleased();
|
|
}
|
|
|
|
bool physics::Vehicle::LineContactorsInterlockReleased() const
|
|
{
|
|
switch (lineContactors.interlock)
|
|
{
|
|
case line_contactors_interlock::converter:
|
|
// the converter of this very vehicle, not the 110 V of the trainset: a section with its fans off doesn't start
|
|
return converter.running;
|
|
case line_contactors_interlock::motor_blowers:
|
|
return std::ranges::all_of(MotorBlowers, [this](auto const &Blower) {
|
|
if (Blower.min_start_velocity < 0)
|
|
{
|
|
return Blower.is_active;
|
|
}
|
|
// a blower which starts with the speed and the motor current (MotorBlowersStartVelocity) can't run before
|
|
// the contactors close, nor after a stop longer than it keeps running for: it's enough that it's
|
|
// switched on and has power, so it starts once the vehicle moves
|
|
return MotorBlowerPowerIsAvailable(Blower) && false == Blower.is_disabled && (Blower.start_type == start_t::manual ? Blower.is_enabled : true);
|
|
});
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
namespace
|
|
{
|
|
|
|
// the setting of the universal controller one UniCtrlValStep further from Value towards Limit, never past it
|
|
double next_uc_step(double const Value, double const Limit, double const Step)
|
|
{
|
|
constexpr double epsilon{1e-6};
|
|
if (Limit > Value)
|
|
{
|
|
return std::min((std::floor(Value / Step + epsilon) + 1.0) * Step, Limit);
|
|
}
|
|
return std::max((std::ceil(Value / Step - epsilon) - 1.0) * Step, Limit);
|
|
}
|
|
|
|
// the universal controller with UniCtrlValStep: the setting the continuous ramp got to (Ramped) turned into whole steps.
|
|
// a move of the controller onto a position which changes the setting makes one step at once, the ramp then one step each
|
|
// time it covers a step's length; the steps stop at the position's set value (or its bound, past which the ramp doesn't go)
|
|
double stepped_uc_value(double const Current, double const Ramped, TUniversalCtrl const &Position, double const Step, bool const Moved, double &Progress)
|
|
{
|
|
if (Moved)
|
|
{
|
|
Progress = 0.0;
|
|
}
|
|
double const delta{Ramped - Current};
|
|
if (std::abs(delta) < 1e-9)
|
|
{
|
|
Progress = 0.0;
|
|
return Ramped;
|
|
}
|
|
double limit{0.0};
|
|
if (delta > 0.0)
|
|
{
|
|
limit = Position.SetCtrlVal > Current ? Position.SetCtrlVal : Position.MaxCtrlVal;
|
|
}
|
|
else
|
|
{
|
|
limit = Position.SetCtrlVal < Current ? Position.SetCtrlVal : Position.MinCtrlVal;
|
|
}
|
|
Progress = Moved ? Step : Progress + std::abs(delta);
|
|
double value{Current};
|
|
bool reached{std::abs(value - limit) < 1e-9};
|
|
while (!reached && Progress >= Step - 1e-9)
|
|
{
|
|
value = next_uc_step(value, limit, Step);
|
|
Progress -= Step;
|
|
reached = std::abs(value - limit) < 1e-9;
|
|
}
|
|
if (reached)
|
|
{
|
|
Progress = 0.0;
|
|
}
|
|
// added after the move to std::clamp: bounds given the other way round are put in order, as master did it
|
|
auto const [lowest, highest] = std::minmax(Position.MinCtrlVal, Position.MaxCtrlVal);
|
|
return std::clamp(value, lowest, highest);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void physics::Vehicle::CheckEIMIC(double dt)
|
|
{
|
|
double offset = EIMCtrlAdditionalZeros ? 1.0 : 0.0;
|
|
double multiplier = (EIMCtrlEmergency ? 1.0 : 0.0) + offset;
|
|
// gdy SplitEDPneumaticBrake jest wlaczone, sterowanie ujemne (hamowanie ED) bierzemy
|
|
// z osobnego nastawnika DynamicBrakeCtrl, a nie z hamulca pomocniczego (LocalBrake).
|
|
// Dodatkowo zapotrzebowanie ED jest ograniczone przez strefe Vh0..Vh1: powyzej Vh1 - pelny ED,
|
|
// pomiedzy Vh1 a Vh0 - liniowe zanikanie, ponizej Vh0 - zerowe (brak hamowania pneumatycznego
|
|
// jako uzupelnienia, poniewaz LocalBrake jest oddzielny i operuje wylacznie pneumatyka).
|
|
double brakeDemand = brakes.electrodynamic.splitFromPneumatic ? DynamicBrakeRatio() : LocalBrakeRatio();
|
|
if (brakes.electrodynamic.splitFromPneumatic)
|
|
{
|
|
double const vh0 = inductionMotor.braking.offSpeed;
|
|
double const vh1 = inductionMotor.braking.fullSpeed;
|
|
if (vh1 > vh0 + 0.001)
|
|
{
|
|
double const vhRamp = std::clamp((Vel - vh0) / (vh1 - vh0), 0.0, 1.0);
|
|
brakeDemand *= vhRamp;
|
|
}
|
|
}
|
|
switch (EIMCtrlType)
|
|
{
|
|
case 0:
|
|
EIMICFromController(brakeDemand, offset, multiplier);
|
|
break;
|
|
case 1:
|
|
EIMICFromSteps(dt);
|
|
break;
|
|
case 2:
|
|
EIMICFromFourPositions(dt);
|
|
break;
|
|
case 3:
|
|
EIMICFromUniversalController(dt, brakeDemand);
|
|
break;
|
|
}
|
|
if (brakes.independentTraxx)
|
|
{
|
|
EIMICTraxxLocalBrake(dt);
|
|
}
|
|
|
|
EIMICLimit();
|
|
}
|
|
|
|
// the controller (EIMCtrlType 0): the position of the main controller, or the analog one, or the brake asked
|
|
void physics::Vehicle::EIMICFromController(double const brakeDemand, double const offset, double const multiplier)
|
|
{
|
|
eimic = brakeDemand > 0.01 ? -brakeDemand : eimic_analog > 0.01 ? eimic_analog : (double)MainCtrlPos / (double)MainCtrlPosNo;
|
|
if (EIMCtrlAdditionalZeros || EIMCtrlEmergency)
|
|
{
|
|
if (eimic > 0.001)
|
|
eimic = std::max(0.002, eimic * (double)MainCtrlPosNo / ((double)MainCtrlPosNo - offset) - offset / ((double)MainCtrlPosNo - offset));
|
|
if (eimic < -0.001 && brakes.driverValveType != TBrakeHandle::MHZ_EN57)
|
|
eimic = std::min(-0.002, eimic * (double)LocalBrakePosNo / ((double)LocalBrakePosNo - multiplier) + offset / ((double)LocalBrakePosNo - multiplier));
|
|
}
|
|
if (eimic > 0.001 && SpeedCtrlUnit.IsActive)
|
|
eimic = std::max(eimic, SpeedCtrlUnit.MinPower);
|
|
}
|
|
|
|
// EIMCtrlType 1: the positions B+ to TMax move the value at a steady pace
|
|
void physics::Vehicle::EIMICFromSteps(double dt)
|
|
{
|
|
switch (MainCtrlPos)
|
|
{
|
|
case 0: // B+
|
|
eimic -= std::clamp(1.0 + eimic, 0.0, dt * 0.14); // odejmuj do -1
|
|
break;
|
|
case 1: // B
|
|
eimic -= std::clamp(0.0 + eimic, 0.0, dt * 0.14); // odejmuj do 0
|
|
break;
|
|
case 2: // B-
|
|
case 3: // 0
|
|
case 4: // T-
|
|
eimic -= std::clamp(0.0 + eimic, 0.0, dt * 0.14); // odejmuj do 0
|
|
eimic += std::clamp(0.0 - eimic, 0.0, dt * 0.14); // dodawaj do 0
|
|
break;
|
|
case 5: // T
|
|
eimic += std::clamp(0.0 - eimic, 0.0, dt * 0.14); // dodawaj do 0
|
|
break;
|
|
case 6: // T+
|
|
eimic += std::clamp(1.0 - eimic, 0.0, dt * 0.14); // dodawaj do 1
|
|
break;
|
|
case 7: // TMax
|
|
eimic += std::clamp(1.0 - eimic, 0.0, dt * 0.14); // dodawaj do 1, max
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (MainCtrlPos >= 3 && eimic < 0)
|
|
eimic = 0;
|
|
if (MainCtrlPos <= 3 && eimic > 0)
|
|
eimic = 0;
|
|
}
|
|
|
|
// EIMCtrlType 2: the positions 0 to 4 move the value towards -1, 0 or 1, from the controller's delay on; the
|
|
// emergency brake position below them, where the controller has one, brakes in full at once
|
|
void physics::Vehicle::EIMICFromFourPositions(double dt)
|
|
{
|
|
if (IsMainCtrlEmergencyPos())
|
|
{
|
|
// hamowanie nagle: pelne hamowanie od razu, przewod glowny oproznia UpdatePipePressure()
|
|
eimic = -1.0;
|
|
}
|
|
else if (MainCtrlActualPos != MainCtrlPos || lineContactors.lastSwitchTime > InitialCtrlDelay)
|
|
{
|
|
double delta = MainCtrlActualPos == MainCtrlPos ? dt * CtrlDelay : 0.01;
|
|
// the positions below are those of the controller without the emergency brake position
|
|
switch (MainCtrlPos - EIMCtrlEmergencyPositions())
|
|
{
|
|
case 0:
|
|
case 1:
|
|
eimic -= safe_clamp(1.0 + eimic, 0.0, delta); // odejmuj do -1
|
|
if (eimic > 0)
|
|
eimic = 0;
|
|
break;
|
|
case 2:
|
|
eimic -= safe_clamp(0.0 + eimic, 0.0, delta); // odejmuj do 0
|
|
break;
|
|
case 3:
|
|
eimic += safe_clamp(0.0 - eimic, 0.0, delta); // dodawaj do 0
|
|
break;
|
|
case 4:
|
|
eimic += safe_clamp(1.0 - eimic, 0.0, delta); // dodawaj do 1
|
|
if (eimic < 0)
|
|
eimic = 0;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if (MainCtrlActualPos == MainCtrlPos)
|
|
lineContactors.lastSwitchTime += dt;
|
|
else
|
|
{
|
|
lineContactors.lastSwitchTime = 0;
|
|
MainCtrlActualPos = MainCtrlPos;
|
|
}
|
|
}
|
|
|
|
// EIMCtrlType 3: the universal controller of UniCtrlList, with the train brake built in or not
|
|
void physics::Vehicle::EIMICFromUniversalController(double dt, double const brakeDemand)
|
|
{
|
|
if (UniCtrlIntegratedBrakePNCtrl)
|
|
{
|
|
UniversalControllerTrainBrake();
|
|
}
|
|
|
|
if (MainCtrlActualPos != MainCtrlPos || lineContactors.lastSwitchTime > InitialCtrlDelay)
|
|
{
|
|
auto const &position{UniCtrlList[MainCtrlPos]};
|
|
double ramped{eimic};
|
|
ramped -= safe_clamp(-position.SetCtrlVal + ramped, 0.0,
|
|
MainCtrlActualPos == MainCtrlPos ? dt * position.SpeedDown : sign(position.SpeedDown) * 0.01); // odejmuj do X
|
|
ramped += safe_clamp(position.SetCtrlVal - ramped, 0.0,
|
|
MainCtrlActualPos == MainCtrlPos ? dt * position.SpeedUp : sign(position.SpeedUp) * 0.01); // dodawaj do X
|
|
ramped = safe_clamp(ramped, position.MinCtrlVal, position.MaxCtrlVal);
|
|
eimic = UniCtrlValStep > 0.0 ? stepped_uc_value(eimic, ramped, position, UniCtrlValStep, MainCtrlActualPos != MainCtrlPos, eimic_step_progress) : ramped;
|
|
}
|
|
if (MainCtrlActualPos == MainCtrlPos)
|
|
lineContactors.lastSwitchTime += dt;
|
|
else
|
|
{
|
|
lineContactors.lastSwitchTime = 0;
|
|
MainCtrlActualPos = MainCtrlPos;
|
|
}
|
|
if (brakes.distributor->GetEDBCP() > 0.3 && eimic < 0 && !UniCtrlIntegratedLocalBrakeCtrl) // when braking with pneumatic brake
|
|
eimic = 0; // shut off retarder
|
|
if (UniCtrlIntegratedBrakeCtrl == false && UniCtrlIntegratedLocalBrakeCtrl == false)
|
|
{
|
|
// w trybie SplitEDPneumaticBrake hamowanie ED przychodzi z osobnego nastawnika,
|
|
// LocalBrake operuje wylacznie pneumatycznym hamulcem lokomotywy
|
|
eimic = brakeDemand > 0.01 ? -brakeDemand : eimic;
|
|
}
|
|
}
|
|
|
|
// the train brake built into the universal controller: the handle set to the controller's position, or the
|
|
// controller, at a brake handle moved alone, to the nearest position of the handle's
|
|
void physics::Vehicle::UniversalControllerTrainBrake()
|
|
{
|
|
if (UniCtrlList[MainCtrlPos].mode != brakes.handlePosition && MainCtrlActualPos == MainCtrlPos) // there was no move of controller, but brake only
|
|
{
|
|
if (brakes.handlePosition < UniCtrlList[MainCtrlPosNo].mode)
|
|
BrakeLevelSet(UniCtrlList[MainCtrlPosNo].mode); // bottom clamping
|
|
if (brakes.handlePosition > UniCtrlList[0].mode)
|
|
BrakeLevelSet(UniCtrlList[0].mode); // top clamping
|
|
if (IsCabMaster())
|
|
{
|
|
while (brakes.handlePosition > UniCtrlList[MainCtrlPos].mode)
|
|
DecMainCtrl(1); // find nearest position
|
|
while (brakes.handlePosition < UniCtrlList[MainCtrlPos].mode)
|
|
IncMainCtrl(1); // find nearest position
|
|
}
|
|
}
|
|
else // controller was moved
|
|
BrakeLevelSet(UniCtrlList[MainCtrlPos].mode);
|
|
}
|
|
|
|
// the local brake of the TRAXX locomotives, by time: released, held or applied, which cuts the drive off
|
|
void physics::Vehicle::EIMICTraxxLocalBrake(double dt)
|
|
{
|
|
if (LocalBrakeRatio() < 0.4) // pozycja 0, odhamowywanie
|
|
{
|
|
eim_localbrake -= dt * 0.17;
|
|
}
|
|
|
|
if (LocalBrakeRatio() > 0.6) // pozycja 2, zahamowywanie
|
|
{
|
|
eim_localbrake += dt * 0.17;
|
|
eim_localbrake = std::max(eim_localbrake, brakes.cylinderPressure / brakes.maxCylinderPressure[0]);
|
|
}
|
|
else // pozycja 1, utrzymanie cisnienia
|
|
{
|
|
if (eim_localbrake < brakes.distributor->GetEDBCP() / brakes.maxCylinderPressure[0])
|
|
eim_localbrake = 0;
|
|
}
|
|
eim_localbrake = std::clamp(eim_localbrake, 0.0, 1.0);
|
|
if (eim_localbrake > 0.04 && eimic > 0)
|
|
eimic = 0;
|
|
}
|
|
|
|
// the value limited by the power, the spring brake, the pipe lock, the direction and the doors' permits
|
|
void physics::Vehicle::EIMICLimit()
|
|
{
|
|
auto const eimicpowerenabled{(MainCircuitPowered() || Power == 0.0) && (!brakes.spring.isActive || !brakes.spring.cutsOffDrive) && !brakes.pipeLock.locked && DirAbsolute != 0};
|
|
auto const eimicdoorenabled{(brakes.spring.isActive && brakes.spring.releasesParkingWithDoorOpen)};
|
|
double eimic_max = 0.0;
|
|
if (Doors.instances[VehicleSide::left].open_permit == false && Doors.instances[VehicleSide::right].open_permit == false)
|
|
{
|
|
if (eimicpowerenabled)
|
|
{
|
|
eimic_max = 1.0;
|
|
}
|
|
else
|
|
{
|
|
eimic_max = 0.001;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (eimicdoorenabled)
|
|
{
|
|
eimic_max = 0.001;
|
|
}
|
|
}
|
|
eimic = safe_clamp(eimic, -1.0, eimicpowerenabled ? eimic_max : 0.0);
|
|
}
|
|
|
|
void physics::Vehicle::CheckSpeedCtrl(double dt)
|
|
{
|
|
if (EIMCtrlType == 0)
|
|
{
|
|
SpeedCtrlUnit.DesiredPower = std::max(eimic, 0.0);
|
|
}
|
|
double accfactor = SpeedCtrlUnit.DesiredPower;
|
|
if (EIMCtrlType >= 2)
|
|
{
|
|
if (MainCtrlPos < MainCtrlPosNo - 2)
|
|
{
|
|
SpeedCtrlUnit.Standby = true;
|
|
}
|
|
if (MainCtrlPos > MainCtrlPosNo - 1)
|
|
{
|
|
SpeedCtrlUnit.Standby = false;
|
|
}
|
|
if (!SpeedCtrlUnit.BrakeIntervention && (brakes.distributor->GetEDBCP() > 0.4 || brakePipe.pressure < brakes.pipeHighPressure - 0.2))
|
|
SpeedCtrlUnit.Standby = true;
|
|
if (EIMCtrlType >= 3 && UniCtrlList[MainCtrlPos].SpeedUp <= 0)
|
|
{
|
|
accfactor = 0.0;
|
|
eimicSpeedCtrl = 0;
|
|
}
|
|
}
|
|
if (SpeedCtrlUnit.IsActive)
|
|
{ // speed control
|
|
if (true)
|
|
{
|
|
if (!SpeedCtrlUnit.Standby)
|
|
{
|
|
SpeedCtrlRegulator(dt, accfactor);
|
|
}
|
|
else
|
|
{
|
|
eimicSpeedCtrl = 0;
|
|
eimicSpeedCtrlIntegral = 0;
|
|
}
|
|
SpeedCtrlUnit.Parking = Vel == 0.0 && eimic <= 0 && EngineType != TEngineType::ElectricInductionMotor;
|
|
SendCtrlToNext(VehicleCommand::speedControlParking, SpeedCtrlUnit.Parking, CabActive);
|
|
}
|
|
else
|
|
{
|
|
if (Vmax < 250)
|
|
eimicSpeedCtrl = std::clamp(0.5 * (SpeedCtrlValue - Vel), -1.0, 1.0);
|
|
else
|
|
eimicSpeedCtrl = std::clamp(0.5 * (SpeedCtrlValue * 2 - Vel), -1.0, 1.0);
|
|
}
|
|
if ((SpeedCtrlAutoTurnOffFlag & 2) == 2 && brakes.distributor->GetEDBCP() > 0.25)
|
|
{
|
|
SpeedCtrlSwitch(false);
|
|
SpeedCtrlUnit.IsActive = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
eimicSpeedCtrl = 1;
|
|
eimicSpeedCtrlIntegral = 0;
|
|
SpeedCtrlUnit.Parking = false;
|
|
SendCtrlToNext(VehicleCommand::speedControlParking, SpeedCtrlUnit.Parking, CabActive);
|
|
}
|
|
}
|
|
|
|
// the PI regulator of the speed control: the power asked of the drive, or its brake intervention, from the error of
|
|
// the speed; accfactor, the most power it may ask
|
|
void physics::Vehicle::SpeedCtrlRegulator(double dt, double const accfactor)
|
|
{
|
|
if (SpeedCtrlUnit.ManualStateOverride && eimic > 0.0009)
|
|
eimic = 1.0;
|
|
double error = std::max(SpeedCtrlValue + SpeedCtrlUnit.Offset, 0.0) - Vel;
|
|
double factorP = error > 0 ? SpeedCtrlUnit.FactorPpos : SpeedCtrlUnit.FactorPneg;
|
|
double eSCP = std::clamp(factorP * error, -1.2, 1.0); // P module
|
|
bool retarder_not_work = EngineType != TEngineType::DieselEngine || Vel < SpeedCtrlUnit.BrakeInterventionVel;
|
|
if (eSCP < -1.0)
|
|
{
|
|
SpeedCtrlUnit.BrakeInterventionBraking = eSCP < -1.1 && retarder_not_work && eimicSpeedCtrl < -0.99 * SpeedCtrlUnit.DesiredPower;
|
|
eSCP = -1.0;
|
|
}
|
|
SpeedCtrlUnit.BrakeInterventionUnbraking = eSCP > 0.0 || Vel == 0.0;
|
|
if (abs(eSCP) < 0.999)
|
|
{
|
|
// TODO: check how to disable integral part when braking in smart way
|
|
// double factorI = eimicSpeedCtrlIntegral >= 0 ? SpeedCtrlUnit.FactorIpos : SpeedCtrlUnit.FactorIneg;
|
|
double factorI = eimicSpeedCtrlIntegral >= 0 ? SpeedCtrlUnit.FactorIpos : SpeedCtrlUnit.FactorIneg;
|
|
eimicSpeedCtrlIntegral = safe_clamp(eimicSpeedCtrlIntegral + factorI * eSCP * dt, -1.0 + eSCP, 1.0 - eSCP);
|
|
}
|
|
else
|
|
{
|
|
eimicSpeedCtrlIntegral = 0;
|
|
}
|
|
auto const DesiredeimicSpeedCtrl{safe_clamp(eimicSpeedCtrlIntegral + eSCP, -SpeedCtrlUnit.DesiredPower, accfactor)};
|
|
eimicSpeedCtrl = safe_clamp(DesiredeimicSpeedCtrl, eimicSpeedCtrl - SpeedCtrlUnit.PowerDownSpeed * dt, eimicSpeedCtrl + SpeedCtrlUnit.PowerUpSpeed * dt);
|
|
if (Vel < SpeedCtrlUnit.FullPowerVelocity)
|
|
{
|
|
eimicSpeedCtrl = std::min(eimicSpeedCtrl, SpeedCtrlUnit.InitialPower);
|
|
}
|
|
if (Vel < SpeedCtrlUnit.StartVelocity && MainCtrlPos < MainCtrlPosNo)
|
|
{
|
|
eimicSpeedCtrl = 0;
|
|
eimic = 0;
|
|
}
|
|
}
|
|
|
|
bool physics::Vehicle::IsSpeedCtrlSeparate() const
|
|
{
|
|
// no secondary controller, or one of these engines', which shunts the field of the traction motors (eu07/maszyna#69)
|
|
return SpeedCtrl && (ScndCtrlPosNo == 0 || EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric);
|
|
}
|
|
|
|
bool physics::Vehicle::IsSpeedCtrlEngaged() const
|
|
{
|
|
return IsSpeedCtrlSeparate() ? SpeedCtrlUnit.IsActive : ScndCtrlPos > 0;
|
|
}
|
|
|
|
bool physics::Vehicle::SpeedCtrlSwitch(bool const State)
|
|
{
|
|
if (false == IsSpeedCtrlSeparate())
|
|
{
|
|
return State ? IncScndCtrl(1) : DecScndCtrl(2);
|
|
}
|
|
// its own switch, the secondary controller left to the field shunting
|
|
if (State)
|
|
{
|
|
if (CabActive == 0 || SpeedCtrlUnit.IsActive)
|
|
{
|
|
return false;
|
|
}
|
|
SpeedCtrlValue = static_cast<double>(Round(Vel));
|
|
SpeedCtrlUnit.IsActive = true;
|
|
return true;
|
|
}
|
|
auto const wasactive{SpeedCtrlUnit.IsActive};
|
|
SpeedCtrlValue = 0;
|
|
SpeedCtrlUnit.IsActive = false;
|
|
if (wasactive && SpeedCtrlUnit.ManualStateOverride)
|
|
{
|
|
eimic = 0.0;
|
|
}
|
|
return wasactive;
|
|
}
|
|
|
|
void physics::Vehicle::SpeedCtrlButton(int button)
|
|
{
|
|
if (SpeedCtrl && IsSpeedCtrlEngaged())
|
|
{
|
|
SpeedCtrlValue = SpeedCtrlButtons[button];
|
|
}
|
|
}
|
|
|
|
void physics::Vehicle::SpeedCtrlInc()
|
|
{
|
|
if (SpeedCtrl && IsSpeedCtrlEngaged())
|
|
{
|
|
double x = floor(SpeedCtrlValue / SpeedCtrlUnit.VelocityStep) + 1.0;
|
|
SpeedCtrlValue = std::min(x * SpeedCtrlUnit.VelocityStep, SpeedCtrlUnit.MaxVelocity);
|
|
}
|
|
}
|
|
|
|
void physics::Vehicle::SpeedCtrlDec()
|
|
{
|
|
if (SpeedCtrl && IsSpeedCtrlEngaged())
|
|
{
|
|
double x = ceil(SpeedCtrlValue / SpeedCtrlUnit.VelocityStep) - 1.0;
|
|
SpeedCtrlValue = std::max(x * SpeedCtrlUnit.VelocityStep, SpeedCtrlUnit.MinVelocity);
|
|
}
|
|
}
|
|
|
|
bool physics::Vehicle::SpeedCtrlPowerInc()
|
|
{
|
|
if (!(SpeedCtrl && IsSpeedCtrlEngaged()))
|
|
return false;
|
|
|
|
if (SpeedCtrlUnit.DesiredPower == SpeedCtrlUnit.MaxPower)
|
|
return false;
|
|
|
|
SpeedCtrlUnit.DesiredPower = std::min(SpeedCtrlUnit.DesiredPower + SpeedCtrlUnit.PowerStep, SpeedCtrlUnit.MaxPower);
|
|
return true;
|
|
}
|
|
|
|
bool physics::Vehicle::SpeedCtrlPowerDec()
|
|
{
|
|
if (!(SpeedCtrl && IsSpeedCtrlEngaged()))
|
|
return false;
|
|
|
|
if (SpeedCtrlUnit.DesiredPower == SpeedCtrlUnit.MinPower)
|
|
return false;
|
|
|
|
SpeedCtrlUnit.DesiredPower = std::max(SpeedCtrlUnit.DesiredPower - SpeedCtrlUnit.PowerStep, SpeedCtrlUnit.MinPower);
|
|
return true;
|
|
}
|