diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 1458c632e..f70f577af 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1480,6 +1480,28 @@ class TMoverParameters float pressure{0.f}; // current pressure }; + // the diesel generator set of a dual-mode vehicle: a second source of the traction circuit, next to the + // pantographs (eu07/maszyna#536). none unless the .fiz gives GensetPower + struct genset_device : public basic_device + { + // config (Power: Genset*), revolutions in rev/s, the .fiz gives rpm + double power{0.0}; // GensetPower, electric output at full revolutions [kW]; 0 = no genset + double voltage_nominal{0.0}; // GensetVoltage, regulated DC voltage from the idle revolutions up [V] + double revolutions_idle{0.0}; // GensetIdleRPM + double revolutions_max{0.0}; // GensetMaxRPM + double start_time{8.0}; // GensetStartTime, from the start request to running at idle [s] + double spinup_time{3.0}; // GensetSpinUpTime, time constant of the revolutions [s] + double traction_share{1.0}; // GensetPmaxRatio, part of the power the traction may take + // state + double timer{0.0}; // of the start [s] + bool is_cranking{false}; + // ld outputs + double revolutions{0.0}; // [rev/s] + double voltage{0.0}; // [V] + bool fitted() const { return power > 0.0; } + // the power the genset gives at its present revolutions [kW] + double available_power() const { return revolutions_max > 0.0 ? power * std::clamp(revolutions / revolutions_max, 0.0, 1.0) : 0.0; } + }; // basic approximation of a water pump struct water_pump : public basic_device { @@ -2212,6 +2234,11 @@ class TMoverParameters bool ConverterOverloadRelayOffWhenMainIsOff{false}; fuel_pump FuelPump; oil_pump OilPump; + genset_device Genset; // of a dual-mode vehicle, fitted() only with GensetPower + // the source the traction circuit takes its voltage from (the traction selector of a dual-mode vehicle) + enum class traction_mode { catenary, genset }; + traction_mode TractionMode{traction_mode::catenary}; + bool GensetSelected() const { return TractionMode == traction_mode::genset; } water_pump WaterPump; water_heater WaterHeater; bool WaterCircuitsLink{false}; // optional connection between water circuits @@ -2950,6 +2977,13 @@ class TMoverParameters bool HeatingSwitch(bool const State, range_t const Notify = range_t::consist); void HeatingSwitch_(bool const State); double EnginePowerSourceVoltage() const; // returns voltage of defined main engine power source + bool TractionModeSwitch(traction_mode const Mode, range_t const Notify = range_t::consist); // traction selector of a dual-mode vehicle + bool GensetSwitch(bool const State, range_t const Notify = range_t::consist); // genset start/stop request + double TractionSourceVoltage() const; // of the vehicle's own source the traction selector picks: the pantographs' or the genset's + double TractionSupplyVoltage() const; // what the traction circuit gets: the own source's, or the train's high voltage line's + double TractionSupplyMinVoltage() const; // below it the line breaker opens (undervoltage) + double GensetTractionPowerLimit() const; // [kW] at the wheels, the largest double unless running on the genset + double CatenaryCurrent() const; // [A] what the vehicle draws through its pantographs, if they touch the wire // whether the main circuit feeds what runs on it (the converter, a compressor, the heating, the motor and resistor // blowers, the traction motors): the line breaker closed, and where it closes ahead of the pantographs and holds // without traction voltage (PantographsRequireMains) also the voltage there, at least the one the undervoltage @@ -2975,6 +3009,7 @@ class TMoverParameters // whether the circuit a traction motor blower runs off has power: the battery, the converter or the main circuit, by its start type bool MotorBlowerPowerIsAvailable(cooling_fan const &Blower) const; void PantographsCheck(double const Timestep); + void GensetCheck(double const Deltatime); void LightsCheck(double const Timestep); bool FuseOn(range_t const Notify = range_t::consist); // bezpiecznik nadamiary bool FuseFlagCheck(void) const; // sprawdzanie flagi nadmiarowego @@ -3142,6 +3177,7 @@ class TMoverParameters void LoadFIZ_Headlights(std::string const &Line); void LoadFIZ_Clima(std::string const &line); void LoadFIZ_Power(std::string const &Line); + void LoadFIZ_Genset(std::string const &Line); void LoadFIZ_SpeedControl(std::string const &Line); void LoadFIZ_Engine(std::string const &Input); void LoadFIZ_EngineDiesel(std::string const &Input); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 037e52fee..6b9c8dfa3 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -1016,7 +1016,8 @@ void TMoverParameters::PantPressureSwitchTrip() if (TrainType != dt_EZT) { // pressure switch safety measure -- open the line breaker, unless there's alternate source of traction voltage - if (GetTrainsetHighVoltage() < EnginePowerSource.CollectorParameters.MinV) + // (the genset of a dual-mode vehicle, when the selector is on it, doesn't need the pantographs) + if (GetTrainsetHighVoltage() < EnginePowerSource.CollectorParameters.MinV && false == GensetSelected()) { // TODO: check whether line breaker should be open EMU-wide MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); @@ -2527,6 +2528,7 @@ void TMoverParameters::compute_movement_(double const Deltatime) LowVoltagePowerCheck(Deltatime); // power sources PantographsCheck(Deltatime); + GensetCheck(Deltatime); // main circuit MainsCheck(Deltatime); // traction motors @@ -2613,6 +2615,11 @@ void TMoverParameters::MainsCheck(double const Deltatime) break; } } + if (GensetSelected()) + { + // the traction selector of a dual-mode vehicle on the genset isolates the pantographs + localvoltage = Genset.voltage; + } // a line breaker closed ahead of the pantographs gets ready on the low voltage circuits auto const maincircuitpowersupply{std::abs(localvoltage) > 0.1 || GetTrainsetHighVoltage() > 0.1 || (PantographsRequireMains && (Power24vIsAvailable || Power110vIsAvailable))}; @@ -2730,7 +2737,8 @@ double TMoverParameters::LocalPowerVoltage(coupling const Coupling) case TPowerSource::Main: { // HACK: main circuit can be fed through couplers, so we explicitly check pantograph supply here - localvoltage = MainCircuitPowered() ? PantographVoltage : 0.0; + // (or the genset's, where the traction selector of a dual-mode vehicle is on it) + localvoltage = MainCircuitPowered() ? TractionSourceVoltage() : 0.0; break; } default: @@ -2739,10 +2747,10 @@ double TMoverParameters::LocalPowerVoltage(coupling const Coupling) } } } - // high voltage power sources + // high voltage power sources: the pantographs, or the genset of a dual-mode vehicle, by its traction selector if (EnginePowerSource.SourceType == TPowerSource::CurrentCollector) { - localvoltage = std::max(localvoltage, PantographVoltage); + localvoltage = std::max(localvoltage, TractionSourceVoltage()); } break; } @@ -3049,7 +3057,7 @@ void TMoverParameters::HeatingCheck(double const /*Timestep*/) } case TPowerSource::Main: { - voltage = MainCircuitPowered() ? std::max(GetTrainsetHighVoltage(), PantographVoltage) : 0.0; + voltage = MainCircuitPowered() ? TractionSupplyVoltage() : 0.0; break; } default: @@ -3241,6 +3249,63 @@ void TMoverParameters::PantographsCheck(double const /*Timestep*/) } } +// the genset of a dual-mode vehicle: started on request with the battery on, it cranks for start_time, then runs at +// idle and up to full revolutions with the traction demand; stopped, it coasts down. regulated voltage from idle up +void TMoverParameters::GensetCheck(double const Deltatime) +{ + if (false == Genset.fitted()) + { + return; + } + auto &genset{Genset}; + auto const wasactive{genset.is_active}; + auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; + auto const requested{lowvoltagepower && false == genset.is_disabled && (genset.start_type == start_t::automatic ? GensetSelected() : genset.is_enabled)}; + if (false == requested) + { + genset.is_active = false; + genset.is_cranking = false; + genset.timer = 0.0; + } + else if (false == genset.is_active) + { + genset.is_cranking = true; + genset.timer += Deltatime; + if (genset.timer >= genset.start_time) + { + genset.is_cranking = false; + genset.is_active = true; + } + } + // revolutions: the start brings them up to idle in start_time; running they follow the traction demand, stopped + // they coast down to 0, both with the time constant spinup_time + if (genset.is_cranking) + { + genset.revolutions = std::max(genset.revolutions, genset.revolutions_idle * std::min(1.0, genset.timer / std::max(genset.start_time, 0.01))); + } + else if (genset.is_active && false == wasactive) + { + genset.revolutions = std::max(genset.revolutions, genset.revolutions_idle); + } + else + { + auto const demand{GensetSelected() && Mains ? std::clamp(eimv_pr, 0.0, 1.0) : 0.0}; + auto const target{genset.is_active ? genset.revolutions_idle + (genset.revolutions_max - genset.revolutions_idle) * demand : 0.0}; + genset.revolutions += (target - genset.revolutions) * std::min(1.0, Deltatime / genset.spinup_time); + if (genset.revolutions < 0.001) + { + genset.revolutions = 0.0; + } + } + // no excitation while cranking; running or coasting down, regulated from idle up, proportional below it + genset.voltage = genset.is_cranking ? 0.0 : genset.voltage_nominal * std::clamp(genset.revolutions / genset.revolutions_idle, 0.0, 1.0); + + if (genset.is_active != wasactive) + { + WriteLog("Genset of " + Name + (genset.is_active ? ": running" : ": stopped")); + } +} + void TMoverParameters::LightsCheck(double const /*Timestep*/) { @@ -4710,6 +4775,11 @@ bool TMoverParameters::MainSwitchCheck() const break; } } + if (GensetSelected()) + { + // on the genset of a dual-mode vehicle the line breaker closes only on a running one, whatever the pantographs give + powerisavailable = Genset.is_active && Genset.voltage >= TractionSupplyMinVoltage(); + } return powerisavailable && (ScndCtrlPos == 0 || EngineType == ElectricInductionMotor) && MainsInitTimeCountdown <= 0.0 && (ConvOvldFlag == false || ConverterOverloadRelayOffWhenMainIsOff) && true == GroundRelay && (true == NoVoltRelay || PantographsRequireMains) && true == OvervoltageRelay && @@ -4809,11 +4879,88 @@ void TMoverParameters::HeatingSwitch_(bool const State) HeatingAllow = State; } +// the traction selector of a dual-mode vehicle: moves only with the line breaker open, and only where a genset is +bool TMoverParameters::TractionModeSwitch(traction_mode const Mode, range_t const Notify) +{ + auto const initialstate{TractionMode}; + // refused with the line breaker closed, and then not passed on either, so the train stays on one source + auto const accepted{false == Mains}; + + if (Genset.fitted() && accepted) + { + TractionMode = Mode; + } + + if (Notify != range_t::local && accepted) + { + SendCtrlToNext("TractionMode", Mode == traction_mode::genset ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + } + + return TractionMode != initialstate; +} + +// the start request of the genset of a dual-mode vehicle; one which starts on its own ignores it, but passes it on to +// the cars behind, which may start theirs on request +bool TMoverParameters::GensetSwitch(bool const State, range_t const Notify) +{ + auto const initialstate{Genset.is_enabled}; + + if (Genset.start_type != start_t::automatic) + { + Genset.is_enabled = State; + } + + if (Notify != range_t::local) + { + SendCtrlToNext("GensetSwitch", State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + } + + return Genset.is_enabled != initialstate; +} + +// the voltage of the vehicle's own source the traction selector picks: the catenary through the pantographs, or the +// genset of a dual-mode vehicle +double TMoverParameters::TractionSourceVoltage() const +{ + return GensetSelected() ? Genset.voltage : PantographVoltage; +} + +// the voltage the traction circuit gets: from the vehicle's own source, or through the train's high voltage line +double TMoverParameters::TractionSupplyVoltage() const +{ + return std::max(GetTrainsetHighVoltage(), TractionSourceVoltage()); +} + +// below it the undervoltage trip opens the line breaker +double TMoverParameters::TractionSupplyMinVoltage() const +{ + return GensetSelected() ? 0.5 * Genset.voltage_nominal : EnginePowerSource.CollectorParameters.MinV; +} + +// the power the traction may take [kW, at the wheels]: the genset's share at its present revolutions on the genset, +// no limit otherwise +double TMoverParameters::GensetTractionPowerLimit() const +{ + return GensetSelected() ? Genset.available_power() * Genset.traction_share : std::numeric_limits::max(); +} + +// the current the vehicle draws through its pantographs [A], if they touch the wire: the traction's (none while +// braking on the resistors) and the heating's. on the genset the genset feeds the traction circuit, so only a heating +// fed straight from the pantographs is left +double TMoverParameters::CatenaryCurrent() const +{ + if (GensetSelected()) + { + return HeatingPowerSource.SourceType == TPowerSource::CurrentCollector ? TotalCurrent : 0.0; + } + return (DynamicBrakeFlag && ResistorsFlag ? 0 : std::abs(Itot) * IsVehicleEIMBrakingFactor()) + TotalCurrent; +} + // returns voltage of defined main engine power source double TMoverParameters::EnginePowerSourceVoltage() const { - return EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? std::max(GetTrainsetHighVoltage(), PantographVoltage) : + return EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? TractionSupplyVoltage() : EnginePowerSource.SourceType == TPowerSource::Accumulator ? Power24vVoltage : 0.0; } @@ -4834,7 +4981,7 @@ bool TMoverParameters::MainCircuitPowered() const } // closed ahead of the pantographs the line breaker holds without the voltage, which the undervoltage trip isn't // there to vouch for - return EnginePowerSourceVoltage() >= EnginePowerSource.CollectorParameters.MinV; + return EnginePowerSourceVoltage() >= TractionSupplyMinVoltage(); } // ************************************************************************************************* @@ -6305,7 +6452,7 @@ void TMoverParameters::ComputeTotalForce(double dt) } // bo nie dzialalo else { - EngineVoltage = Power > 1.0 ? std::max(GetTrainsetHighVoltage(), PantographVoltage) : 0.0; + EngineVoltage = Power > 1.0 ? TractionSupplyVoltage() : 0.0; } FTrain = Power > 0 ? TractionForce(dt) : 0; @@ -7240,8 +7387,9 @@ void TMoverParameters::VoltageRelaysCheck() // TODO: check if we can use instead the code for electricseriesmotor // nie wchodzić w funkcję bez potrzeby // (a line breaker closed ahead of the pantographs holds without voltage) - if (Mains && ((std::max(GetTrainsetHighVoltage(), PantographVoltage) < EnginePowerSource.CollectorParameters.MinV && false == PantographsRequireMains) || - std::max(GetTrainsetHighVoltage(), PantographVoltage) > EnginePowerSource.CollectorParameters.MaxV + 200)) + // (the source by the traction selector of a dual-mode vehicle: the pantographs or the genset) + if (Mains && ((TractionSupplyVoltage() < TractionSupplyMinVoltage() && false == PantographsRequireMains) || + TractionSupplyVoltage() > EnginePowerSource.CollectorParameters.MaxV + 200)) { MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide } @@ -8059,6 +8207,11 @@ void TMoverParameters::InductionMotorDrive(double dt) else { eimv[eimv_Pmax] = std::min(eimc[eimc_p_Pmax], 0.001 * EngineVoltage * (eimc[eimc_p_Imax] - eimc[eimc_f_I0]) * Pirazy2 * eimc[eimc_s_cim] / eimc[eimc_s_p] / eimc[eimc_s_cfu]); + if (GensetSelected()) + { + // on the genset of a dual-mode vehicle the traction takes no more than the genset gives + eimv[eimv_Pmax] = std::min(eimv[eimv_Pmax], GensetTractionPowerLimit()); + } } eimv[eimv_FMAXMAX] = 0.001 * square(std::min(1.0, eimv[eimv_fkr] / std::max(abs(enrot) * eimc[eimc_s_p] + eimc[eimc_s_dfmax] * eimv[eimv_ks], eimc[eimc_s_dfmax])) * f_cfu / eimc[eimc_s_cfu]) * @@ -8091,6 +8244,8 @@ void TMoverParameters::InductionMotorDrive(double dt) Im = eimv[eimv_If]; if (eimv[eimv_Ipoj] >= 0) Vadd *= 1.0 - 2.0 * dt; + else if (GensetSelected()) + Vadd = 1.0; // the genset of a dual-mode vehicle takes nothing back: all the braking energy to the resistors else if (std::abs(EngineVoltage) < EnginePowerSource.CollectorParameters.MaxV) Vadd *= 1.0 - dt; else @@ -13438,6 +13593,11 @@ void TMoverParameters::LoadFIZ_CntrlStarts(std::string const &line) auto lookup = starts.find(extract_value("OilStart", line)); OilPump.start_type = lookup != starts.end() ? lookup->second : manual; } + // genset of a dual-mode vehicle: Manual (the default) needs GensetSwitch, Automatic runs whenever the selector is on it + { + auto lookup = starts.find(extract_value("GensetStart", line)); + Genset.start_type = lookup != starts.end() ? lookup->second : manual; + } // water pump { auto lookup = starts.find(extract_value("WaterStart", line)); @@ -13565,11 +13725,40 @@ void TMoverParameters::LoadFIZ_Power(std::string const &Line) // jeśli nie ma mocy, np. rozrządcze EZT EnginePowerSource.SourceType = TPowerSource::NotDefined; } + else + { + LoadFIZ_Genset(Line); + } SystemPowerSource.SourceType = LoadFIZ_SourceDecode(extract_value("SystemPower", Line)); LoadFIZ_PowerParamsDecode(SystemPowerSource, "", Line); } +// the genset of a dual-mode vehicle (eu07/maszyna#536), on the Power: line; all optional, no genset without GensetPower +void TMoverParameters::LoadFIZ_Genset(std::string const &Line) +{ + extract_value(Genset.power, "GensetPower", Line, ""); + if (false == Genset.fitted()) + { + return; + } + extract_value(Genset.voltage_nominal, "GensetVoltage", Line, ""); + if (Genset.voltage_nominal <= 0.0) + { + Genset.voltage_nominal = EnginePowerSource.MaxVoltage > 0.0 ? 0.65 * EnginePowerSource.MaxVoltage : 3000.0; + } + extract_value(Genset.revolutions_idle, "GensetIdleRPM", Line, "600"); + extract_value(Genset.revolutions_max, "GensetMaxRPM", Line, "1800"); + Genset.revolutions_max = std::max(Genset.revolutions_max, 1.0) / 60.0; + Genset.revolutions_idle = std::clamp(Genset.revolutions_idle / 60.0, 1.0 / 60.0, Genset.revolutions_max); + extract_value(Genset.start_time, "GensetStartTime", Line, "8"); + extract_value(Genset.spinup_time, "GensetSpinUpTime", Line, "3"); + extract_value(Genset.traction_share, "GensetPmaxRatio", Line, "1"); + Genset.start_time = std::max(Genset.start_time, 0.0); + Genset.spinup_time = std::max(Genset.spinup_time, 0.01); + Genset.traction_share = std::clamp(Genset.traction_share, 0.0, 1.0); +} + void TMoverParameters::LoadFIZ_SpeedControl(std::string const &Line) { // speed control @@ -14332,6 +14521,13 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/) if (CompressorListPosNo > 0) CompressorListPos = CompressorListDefPos; + // the genset of a dual-mode vehicle is a second source of the traction circuit of an induction motor vehicle + if (Genset.fitted() && (EngineType != TEngineType::ElectricInductionMotor || EnginePowerSource.SourceType != TPowerSource::CurrentCollector)) + { + WriteLog("GensetPower ignored: a genset works only with EngineType=ElectricInductionMotor and EnginePower=CurrentCollector"); + Genset = genset_device{}; + } + // NOTE: legacy compatibility behaviour for vehicles without defined heating power source if (EnginePowerSource.SourceType == TPowerSource::CurrentCollector && HeatingPowerSource.SourceType == TPowerSource::NotDefined) { @@ -15289,6 +15485,16 @@ bool TMoverParameters::RunPowerCommand(std::string const &Command, double CValue DropAllPantographs(CValue1 == 1, range_t::local); OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } + else if (Command == "TractionMode") + { + TractionModeSwitch(CValue1 > 0.5 ? traction_mode::genset : traction_mode::catenary, range_t::local); + OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); + } + else if (Command == "GensetSwitch") + { + GensetSwitch(CValue1 > 0.5, range_t::local); + OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); + } else { return false; diff --git a/input/command.cpp b/input/command.cpp index add272473..2c1cbd6e8 100644 --- a/input/command.cpp +++ b/input/command.cpp @@ -446,6 +446,12 @@ commanddescription_sequence Commands_descriptions = { {"genericset27", command_target::vehicle, command_mode::oneoff}, {"genericset28", command_target::vehicle, command_mode::oneoff}, {"genericset29", command_target::vehicle, command_mode::oneoff}, + {"tractionmodetoggle", command_target::vehicle, command_mode::oneoff}, + {"tractionmodecatenary", command_target::vehicle, command_mode::oneoff}, + {"tractionmodegenset", command_target::vehicle, command_mode::oneoff}, + {"gensettoggle", command_target::vehicle, command_mode::oneoff}, + {"gensetenable", command_target::vehicle, command_mode::oneoff}, + {"gensetdisable", command_target::vehicle, command_mode::oneoff}, }; // Maps of command and coresponding strings @@ -871,6 +877,12 @@ std::unordered_map const commandMap = { {"genericset27", user_command::genericset27}, {"genericset28", user_command::genericset28}, {"genericset29", user_command::genericset29}, + {"tractionmodetoggle", user_command::tractionmodetoggle}, + {"tractionmodecatenary", user_command::tractionmodecatenary}, + {"tractionmodegenset", user_command::tractionmodegenset}, + {"gensettoggle", user_command::gensettoggle}, + {"gensetenable", user_command::gensetenable}, + {"gensetdisable", user_command::gensetdisable}, {"none", user_command::none}}; } // namespace simulation diff --git a/input/command.h b/input/command.h index 9fb6021d0..7a9909686 100644 --- a/input/command.h +++ b/input/command.h @@ -445,6 +445,13 @@ enum class user_command genericset27, genericset28, genericset29, + // the traction selector and the genset of a dual-mode vehicle (eu07/maszyna#536) + tractionmodetoggle, + tractionmodecatenary, + tractionmodegenset, + gensettoggle, + gensetenable, + gensetdisable, none = -1 }; diff --git a/input/driverkeyboardinput.cpp b/input/driverkeyboardinput.cpp index 047f3678c..566a07192 100644 --- a/input/driverkeyboardinput.cpp +++ b/input/driverkeyboardinput.cpp @@ -103,6 +103,12 @@ driverkeyboard_input::default_bindings() { { fuelpumptoggle, {GLFW_KEY_F, ""} }, // fuelpumpenable, // fuelpumpdisable, + { tractionmodetoggle, {GLFW_KEY_G | keymodifier::shift, ""} }, + // tractionmodecatenary, + // tractionmodegenset, + { gensettoggle, {GLFW_KEY_G | keymodifier::control, ""} }, + // gensetenable, + // gensetdisable, { oilpumptoggle, {GLFW_KEY_F | keymodifier::shift, ""} }, // oilpumpenable, // oilpumpdisable, diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 90414d312..788173759 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -640,6 +640,12 @@ drivermouse_input::default_bindings() { { "oilfuelpump_sw:", { oilfuelpumptoggle, none } }, + { "tractionmode_sw:", { + tractionmodetoggle, + none } }, + { "genset_sw:", { + gensettoggle, + none } }, { "motorblowersfront_sw:", { motorblowerstogglefront, none } }, diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 600d8fa14..529fefea6 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -239,7 +239,7 @@ to `logs/`. | `fragment` | `.scn` file in `cases/` added to the scenery: trainsets after `FirstInit` (before it they derail on unlinked track), the rest before it (launchers read after it never fire). Optional when the case keeps the scenery's trainsets | | `vars` | values for `{{name}}` in the fragment; a list becomes one line per item | | `timetable` | a timetable file in `cases/` for a trainset of the fragment, for a train whose timetable no scenery of the game has: copied to the game's `scenery/` dir as `autotest_.txt` for the run and removed after it; the fragment names it `{{timetable}}` | -| `vehicle_variants` | vehicles of the case's own, made from those of the game, e.g. with a `.fiz` key the game's data doesn't have yet: a list of `{ "name": ..., "from": "/", "replace": [[old, new], ...] }`. For the run the vehicle's `.fiz`, with the literal replacements (an `old` it doesn't have is an error), and its `.mmd` are copied beside it in the game's `dynamic/` dir as `autotest__` and removed after it; the fragment names the type `{{variant_}}`, e.g. `dynamic pkp/et42_v2 112e-014-a {{variant_a}} ...`. The copy of the `.mmd` has the name of the vehicle it is made from in place of `(p2)`, the type name the simulator hands it, which some pass on to the include that names the model | +| `vehicle_variants` | vehicles of the case's own, made from those of the game, e.g. with a `.fiz` key the game's data doesn't have yet: a list of `{ "name": ..., "from": "/", "replace": [[old, new], ...] }`. For the run the vehicle's `.fiz`, with the literal replacements (an `old` it doesn't have is an error), and its `.mmd` are copied beside it in the game's `dynamic/` dir as `autotest__` and removed after it; the fragment names the type `{{variant_}}`, e.g. `dynamic pkp/et42_v2 112e-014-a {{variant_a}} ...`. The copy of the `.mmd` has the name of the vehicle it is made from in place of `(p2)`, the type name the simulator hands it, which some pass on to the include that names the model. An optional `"fiz_from": "/"` copies that file instead of the vehicle's own `.fiz`, named in full, e.g. `pkp/e6act_v2/e6acta.fiz.inc` for a vehicle whose `.fiz` only includes it (`e6actad.fiz`); the `.mmd` still comes from `from`. Keys for a section of the included file can't go after the include on a line of their own: a second `Power:` line loads the power source anew | | `expect` | the result the test mode should end with: `pass`, `fail`, `signal_passed_at_danger`, `timeout`, `standstill` or `error`, or `wall_timeout` for the timeout of the real time watchdog (the timeout code with a verdict saying it was the real time; a case expecting `timeout` fails on it). Default `timeout` for a case with `duration`, else `pass` | | `duration` | seconds of simulation to record: the test timeout of the run (`--test-timeout`) | | `timeout` | wall-clock seconds before giving up, loading included: the simulator's `--test-wall-timeout` (default 600) | @@ -299,6 +299,18 @@ starts on the level at the W4 of Gora, stops at the W4 of Dol 1500 m down the gr model), about 1590 m and 2690 m from the start. The three trains are the light EU07, the SN61 alone and the EU07 with three coaches. +`e6actad_genset_td_timetable` (fragment `td_timetable_genset.scn`) is the timetable run of a dual-mode vehicle on its +genset (eu07/maszyna#536): an E6ACTad, the Dragon 2 "last mile" with a 520 kW diesel generator set. The game data has no +genset for it yet, so the case makes its own E6ACTad (`vehicle_variants`, `{{variant_g6}}`): the `.mmd` of `e6actad`, and +as its `.fiz` the `e6acta.fiz.inc` that `e6actad.fiz` includes (`fiz_from`), with `GensetStart=Manual` added to the +`Cntrl.` line and `GensetPower=520 GensetVoltage=3000 GensetIdleRPM=700 GensetMaxRPM=1800 GensetStartTime=8 +GensetSpinUpTime=3 GensetPmaxRatio=0.85` to the `Power:` line. `event0` of the start track gives the standing vehicle, once, +`PutValues` `MainSwitch 0`, `TractionMode 1` (the selector on the genset) and `GensetSwitch 1`, a second apart, as the +vehicle holds one command at a time. The AI knows nothing of the genset: it closes the line breaker once the genset runs +and drives the timetable on it, at most 520 kW x 0.85 = 442 kW at the wheels (`traction_power`). +`e6actad_catenary_td_timetable` is the same variant without the events: it stays on the catenary and takes several +times that, which shows the check tells the two apart. + ### Heavy trains The heavy train cases (#187, #199, #263, #265) run on lines of their own beside the tracks of td.scn, at x = -3000, as @@ -643,6 +655,10 @@ the row instead, logged by builds from this branch on. after moving off, moves no more than `max_distance` metres, e.g. no creeping on locked wheels. - `ends_moving` `min_speed`: the last row of the physicslog is at `min_speed` or faster, e.g. the test ended without waiting for the train to stop. +- `traction_power` `max_kw`, optional `min_peak_kw` (*vehicle speed*): the power at the wheels, the + traction force times the vehicle speed, never goes above `max_kw` and, given `min_peak_kw`, reaches + it at least once; e.g. a dual-mode vehicle running on the power of its genset. The traction force + column is in N, whatever the header says. - `keeps_moving` `moving_speed`, `min_speed`, `until_distance`, optional `from_distance` (*vehicle speed*): once at `moving_speed`, the speed stays at or above `min_speed` between the two distances (metres travelled, from the vehicle speed), e.g. a heavy train doesn't come to a stand on a descent before a restriction. Reports the lowest speed. diff --git a/tests/scenarios/cases/e6actad_catenary_td_timetable.json b/tests/scenarios/cases/e6actad_catenary_td_timetable.json new file mode 100644 index 000000000..9e8ff5f72 --- /dev/null +++ b/tests/scenarios/cases/e6actad_catenary_td_timetable.json @@ -0,0 +1,25 @@ +{ + "description": "GE#536 stage 1, the twin of e6actad_genset_td_timetable without the switching events: the same E6ACTad variant stays on its catenary position and runs the td/rozklad timetable as the plain E6ACT does, on far more than the genset's 442 kW at the wheels, which shows the traction_power check tells the two apart. The same variant g6 as the genset case.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vehicle_variants": [ + { "name": "g6", "from": "pkp/e6act_v2/e6actad", "fiz_from": "pkp/e6act_v2/e6acta.fiz.inc", "replace": [ + ["InactiveCabFlag=15", "InactiveCabFlag=15 GensetStart=Manual"], + ["PhysicalLayout=3", "PhysicalLayout=3 GensetPower=520 GensetVoltage=3000 GensetIdleRPM=700 GensetMaxRPM=1800 GensetStartTime=8 GensetSpinUpTime=3 GensetPmaxRatio=0.85"] + ] } + ], + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\e6act_v2 e6actad-017 {{variant_g6}} 0 headdriver 0 0 enddynamic" + }, + "ini": ["gfxrenderer null"], + "duration": 240, + "timeout": 600, + "checks": [ + { "type": "log_lacks", "pattern": "Genset of" }, + { "type": "starts", "min_speed": 20, "within": 150 }, + { "type": "max_speed", "limit": 90, "tolerance": 3 }, + { "type": "traction_power", "max_kw": 6000, "min_peak_kw": 1000 }, + { "type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420 } + ] +} diff --git a/tests/scenarios/cases/e6actad_genset_td_timetable.json b/tests/scenarios/cases/e6actad_genset_td_timetable.json new file mode 100644 index 000000000..92338d49d --- /dev/null +++ b/tests/scenarios/cases/e6actad_genset_td_timetable.json @@ -0,0 +1,28 @@ +{ + "description": "GE#536 stage 1: an E6ACTad (Dragon 2 last mile) on the td/rozklad timetable of td.scn, switched to its genset by the scenery before it leaves: PutValues MainSwitch 0, TractionMode 1, GensetSwitch 1 from event0 of its track, 1 s apart. The AI, which knows nothing of the genset, closes the line breaker once the genset runs and drives to Przystanek on at most 442 kW at the wheels (520 kW x 0.85). Makes its own E6ACTad for the run (vehicle_variants g6: e6acta.fiz.inc with the genset keys, the .mmd of e6actad).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable_genset.scn", + "vehicle_variants": [ + { "name": "g6", "from": "pkp/e6act_v2/e6actad", "fiz_from": "pkp/e6act_v2/e6acta.fiz.inc", "replace": [ + ["InactiveCabFlag=15", "InactiveCabFlag=15 GensetStart=Manual"], + ["PhysicalLayout=3", "PhysicalLayout=3 GensetPower=520 GensetVoltage=3000 GensetIdleRPM=700 GensetMaxRPM=1800 GensetStartTime=8 GensetSpinUpTime=3 GensetPmaxRatio=0.85"] + ] } + ], + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\e6act_v2 e6actad-017 {{variant_g6}} 0 headdriver 0 0 enddynamic" + }, + "ini": ["gfxrenderer null"], + "track_events": { + "tdo_n1734": "event0 autotest_genset" + }, + "duration": 300, + "timeout": 600, + "checks": [ + { "type": "log_contains", "pattern": "Genset of autotest_e6actad_genset_td_timetable: running" }, + { "type": "starts", "min_speed": 20, "within": 180 }, + { "type": "max_speed", "limit": 90, "tolerance": 3 }, + { "type": "traction_power", "max_kw": 451, "min_peak_kw": 380 }, + { "type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420 } + ] +} diff --git a/tests/scenarios/cases/td_timetable_genset.scn b/tests/scenarios/cases/td_timetable_genset.scn new file mode 100644 index 000000000..0918dc1bc --- /dev/null +++ b/tests/scenarios/cases/td_timetable_genset.scn @@ -0,0 +1,18 @@ +// td_timetable.scn (the timetable train on track 1 of Stacja1, route out at 10:34) with the train switched to its +// genset by the scenery before it leaves (eu07/maszyna#536, a dual-mode vehicle): event0 of the start track (the +// track_events of the case) runs while the vehicle with a driver stands there and gives it, once, PutValues +// MainSwitch 0, TractionMode 1 and GensetSwitch 1, a second apart, as the vehicle holds one command at a time. +// the AI knows nothing of the genset: it closes the line breaker once the genset runs and drives on its power +trainset td/rozklad tdo_n1734 0.0 0.1 +{{consist}} +endtrainset + +// the way out of track 1, see td_timetable.scn +node -1 0 autotest_route eventlauncher 0 0 0 -1 none 1034 keyctrl04 end + +node -1 0 autotest_genset_done memcell 0 0 0 done 0 0 none endmemcell +event autotest_genset multiple 0 autotest_genset_done autotest_genset_ws autotest_genset_mode autotest_genset_on autotest_genset_mark condition memcompare * 0 * endevent +event autotest_genset_ws PutValues 0 none 0 0 0 MainSwitch 0 0 endevent +event autotest_genset_mode PutValues 1 none 0 0 0 TractionMode 1 0 endevent +event autotest_genset_on PutValues 2 none 0 0 0 GensetSwitch 1 0 endevent +event autotest_genset_mark UpdateValues 0 autotest_genset_done * 1 * endevent diff --git a/tests/scenarios/run.py b/tests/scenarios/run.py index c83899d40..ad7ac5bcb 100644 --- a/tests/scenarios/run.py +++ b/tests/scenarios/run.py @@ -178,11 +178,16 @@ def write_vehicle_variants(case: dict, game_dir: Path, case_name: str) -> None: files = {} for variant in case.get("vehicle_variants", []): source = game_dir / "dynamic" / variant["from"] + # the .fiz to copy: the vehicle's own, or another file named in full (fiz_from), e.g. the .fiz.inc a + # vehicle's .fiz only includes, as keys added after the include on a second line of the same section + # would load that section again + fiz_source = game_dir / "dynamic" / variant["fiz_from"] if "fiz_from" in variant else source.with_name(source.name + ".fiz") + fiz_name = variant.get("fiz_from", f"{variant['from']}.fiz") # .fiz files are cp1250 like the sceneries; latin-1 round-trips every byte - fiz = source.with_name(source.name + ".fiz").read_bytes().decode("latin-1") + fiz = fiz_source.read_bytes().decode("latin-1") for old, new in variant.get("replace", []): if old not in fiz: - sys.exit(f"vehicle_variants: {variant['from']}.fiz has no {old!r}") + sys.exit(f"vehicle_variants: {fiz_name} has no {old!r}") fiz = fiz.replace(old, new) mmd = source.with_name(source.name + ".mmd").read_bytes().decode("latin-1").replace("(p2)", source.name) fiz_path, mmd_path = variant_paths(game_dir, case_name, variant) @@ -794,6 +799,23 @@ def check_master_controller(rows, from_distance, to_distance, at_most): return True, detail +def check_traction_power(rows, max_kw, min_peak_kw=None): + """The power at the wheels, the traction force times the vehicle speed, stays at or below max_kw + and, given min_peak_kw, reaches it, e.g. a dual-mode vehicle on its genset (eu07/maszyna#536).""" + if not rows or len(rows[0]) <= COL_VEHICLE_VELOCITY or rows[0][COL_VEHICLE_VELOCITY] is None: + return False, "the physicslog has no vehicle speed column" + power = [abs(r[COL_TRACTION_FORCE]) * abs(r[COL_VEHICLE_VELOCITY]) / 3.6 / 1000 for r in rows] + peak = max(range(len(rows)), key=power.__getitem__) + r = rows[peak] + detail = (f"peak {power[peak]:.0f} kW at t={r[COL_TIME]:.1f}s, v={r[COL_VEHICLE_VELOCITY]:.1f} km/h, " + f"Ft={r[COL_TRACTION_FORCE] / 1000:.1f} kN") + if power[peak] > max_kw: + return False, f"{detail}, above {max_kw} kW" + if min_peak_kw is not None and power[peak] < min_peak_kw: + return False, f"{detail}, below {min_peak_kw} kW" + return True, detail + + CHECKS = { "master_controller": check_master_controller, "traction": check_traction, @@ -807,6 +829,7 @@ CHECKS = { "stays_stopped": check_stays_stopped, "distance": check_distance, "ends_moving": check_ends_moving, + "traction_power": check_traction_power, "keeps_moving": check_keeps_moving, "starts_again": check_starts_again, } diff --git a/tests/unit/test_genset.cpp b/tests/unit/test_genset.cpp new file mode 100644 index 000000000..c3b4f3015 --- /dev/null +++ b/tests/unit/test_genset.cpp @@ -0,0 +1,662 @@ +#include "stdafx.h" +#include "doctest.h" +#include "consist.h" +#include "drive.h" +#include "golden.h" + +#include "McZapkie/hamulce.h" + +// the genset of a dual-mode vehicle (eu07/maszyna#536): a second source of the traction circuit of an induction +// motor vehicle next to its pantographs, which the traction selector picks. the vehicle is the game's E6ACT +// (Dragon 2) with the genset of the E6ACTad "last mile" set in the test: 520 kW, the rest assumed + +using test::consist; +using test::definition; +using test::track; +using test::vehicle; +using traction_mode = TMoverParameters::traction_mode; + +namespace { + +definition dragon() { + return definition::fiz("e6act_v2/e6acta"); +} + +definition dragon_genset() { + return dragon() + .set("Power", "GensetPower", 520) + .set("Power", "GensetVoltage", 3000) + .set("Power", "GensetIdleRPM", 700) + .set("Power", "GensetMaxRPM", 1800) + .set("Power", "GensetStartTime", 8) + .set("Power", "GensetSpinUpTime", 3) + .set("Power", "GensetPmaxRatio", 0.85); +} + +// the power the traction of dragon_genset() may take at full revolutions [kW] +double const genset_traction_power{520.0 * 0.85}; + +track const no_wire{0.15, 0.0, 0.0}; +track const wire{0.15, 0.0, test::catenary_3kv}; + +// the battery, the cab and a direction, as the driver begins +void wake(TMoverParameters &Cab) { + Cab.BatterySwitch(true); + Cab.CabActivisation(); + for (int i = 0; i < 3 && Cab.DirActive <= 0; ++i) { + Cab.DirectionForward(); + } +} + +// the vigilance and the cab signalling acknowledged, as test::drive() does once a second +void attend(TMoverParameters &Cab) { + if (Cab.SecuritySystem.is_cabsignal_blinking() && Cab.SecuritySystem.has_separate_acknowledge()) { + Cab.SecuritySystem.cabsignal_reset(); + } + if (Cab.SecuritySystem.is_blinking()) { + Cab.SecuritySystemReset(); + } +} + +void run(vehicle &Vehicle, double const Seconds, track const &Track = no_wire) { + test::drive(test::driving(Vehicle), Track, Seconds); +} + +// the line breaker closed, which it does only with the controller at zero, and after the relays are reset +void close_line_breaker(TMoverParameters &Cab) { + while (Cab.DecMainCtrl(2)) { + // down to zero + } + Cab.RelayReset(relay_t::maincircuitground | relay_t::tractionnmotoroverload | relay_t::primaryconverteroverload); + Cab.MainSwitch(true); +} + +// gets the vehicle ready to run on its genset, as test::start_up() does on the pantographs: the selector on the +// genset, the genset started, the line breaker closed once it runs, the converter and the compressor, the air, the +// brakes released. one round of the driver's actions a second; returns whether the vehicle got ready +bool start_on_genset(vehicle &Vehicle, track const &Track = no_wire, double const Seconds = 300.0) { + auto &cab{Vehicle.mover()}; + for (auto second = 0; second < Seconds; ++second) { + wake(cab); + cab.TractionModeSwitch(traction_mode::genset); + cab.GensetSwitch(true); + if (false == cab.Mains) { + if (cab.MainSwitchCheck()) { + close_line_breaker(cab); + } + } + else { + cab.ConverterSwitch(true); + cab.CompressorSwitch(true); + } + run(Vehicle, 1.0, Track); + if (cab.Mains && cab.ConverterFlag && cab.ScndPipePress >= 4.5) { + // and the brakes let go + test::release_brakes(cab); + for (auto wait = 0; wait < 120 && cab.BrakePress > 0.05; ++wait) { + run(Vehicle, 1.0, Track); + } + return cab.BrakePress <= 0.05; + } + } + return false; +} + +// the main controller to its full power position +void notch_up(TMoverParameters &Cab) { + for (int i = 0; i < 60 && false == Cab.IsMainCtrlMaxPowerPos(); ++i) { + Cab.IncMainCtrl(1); + } +} + +// the power at the wheels [kW] +double wheel_power(TMoverParameters const &Vehicle) { + return std::abs(Vehicle.Ft * Vehicle.V) / 1000.0; +} + +// one step of 0.01 s, acknowledging the vigilance once a second +void step(vehicle &Vehicle, long const Step, track const &Track = no_wire) { + if (Step % 100 == 0) { + attend(Vehicle.mover()); + } + Vehicle.step(Track); +} + +} // namespace + +TEST_CASE("genset: a vehicle without the keys has none and stays on the catenary") { + vehicle dragon6{dragon(), 0.0, "plain", 1}; + auto &cab{dragon6.mover()}; + CHECK(cab.Genset.power == 0.0); + CHECK_FALSE(cab.Genset.fitted()); + CHECK_FALSE(cab.TractionModeSwitch(traction_mode::genset)); + CHECK(cab.TractionMode == traction_mode::catenary); + CHECK_FALSE(cab.GensetSelected()); + REQUIRE(test::start_up(test::driving(dragon6), wire)); + CHECK(cab.PantographVoltage > 2900.0); + CHECK(cab.TractionSupplyVoltage() == std::max(cab.GetTrainsetHighVoltage(), cab.PantographVoltage)); + CHECK(cab.TractionSupplyMinVoltage() == cab.EnginePowerSource.CollectorParameters.MinV); + CHECK(cab.GensetTractionPowerLimit() == std::numeric_limits::max()); + // a start request does nothing without a genset + cab.GensetSwitch(true); + run(dragon6, 20.0, wire); + CHECK_FALSE(cab.Genset.is_active); + CHECK(cab.Genset.voltage == 0.0); + CHECK(cab.TractionMode == traction_mode::catenary); +} + +TEST_CASE("genset: the keys reach the vehicle") { + vehicle dragon6{dragon_genset()}; + auto const &genset{dragon6->Genset}; + CHECK(genset.fitted()); + CHECK(genset.power == 520.0); + CHECK(genset.voltage_nominal == 3000.0); + CHECK(genset.revolutions_idle == doctest::Approx(700.0 / 60.0)); + CHECK(genset.revolutions_max == doctest::Approx(30.0)); + CHECK(genset.start_time == 8.0); + CHECK(genset.spinup_time == 3.0); + CHECK(genset.traction_share == 0.85); + CHECK(genset.start_type == start_t::manual); + CHECK(dragon6->TractionMode == traction_mode::catenary); + // the pantographs stay what they were + CHECK(dragon6->EnginePowerSource.SourceType == TPowerSource::CurrentCollector); + CHECK(dragon6->EnginePowerSource.CollectorParameters.MinV == 2000.0); + + SUBCASE("started on its own") { + vehicle automatic{dragon_genset().set("Cntrl", "GensetStart", "Automatic")}; + CHECK(automatic->Genset.start_type == start_t::automatic); + } + SUBCASE("the defaults") { + vehicle defaults{dragon().set("Power", "GensetPower", 520)}; + auto const &plain{defaults->Genset}; + CHECK(plain.fitted()); + CHECK(plain.voltage_nominal == doctest::Approx(0.65 * 4600.0)); // of the pantographs' MaxVoltage + CHECK(plain.revolutions_idle == doctest::Approx(10.0)); + CHECK(plain.revolutions_max == doctest::Approx(30.0)); + CHECK(plain.start_time == 8.0); + CHECK(plain.spinup_time == 3.0); + CHECK(plain.traction_share == 1.0); + } +} + +TEST_CASE("genset: the keys are ignored on other than induction motor vehicles") { + for (auto const *path : {"4e_v1/4e", "br285_v1/br285"}) { + CAPTURE(path); + vehicle other{definition::fiz(path).set("Power", "GensetPower", 520)}; + CHECK_FALSE(other->Genset.fitted()); + CHECK_FALSE(other->TractionModeSwitch(traction_mode::genset)); + CHECK(other->TractionMode == traction_mode::catenary); + } +} + +TEST_CASE("genset: the selector moves only with the line breaker open") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(test::start_up(test::driving(dragon6), wire)); + REQUIRE(cab.Mains); + CHECK_FALSE(cab.TractionModeSwitch(traction_mode::genset)); + CHECK(cab.TractionMode == traction_mode::catenary); + run(dragon6, 2.0, wire); + CHECK(cab.Mains); + cab.MainSwitch(false); + REQUIRE_FALSE(cab.Mains); + CHECK(cab.TractionModeSwitch(traction_mode::genset)); + CHECK(cab.GensetSelected()); + CHECK(cab.TractionModeSwitch(traction_mode::catenary)); + CHECK(cab.TractionMode == traction_mode::catenary); +} + +TEST_CASE("genset: started, it closes the line breaker without a catenary") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + wake(cab); + REQUIRE(cab.TractionModeSwitch(traction_mode::genset)); + cab.GensetSwitch(true); + run(dragon6, 7.0); + CHECK(cab.Genset.is_cranking); + CHECK_FALSE(cab.Genset.is_active); + CHECK(cab.Genset.voltage == 0.0); + CHECK_FALSE(cab.MainSwitchCheck()); + run(dragon6, 2.0); + CHECK(cab.Genset.is_active); + CHECK_FALSE(cab.Genset.is_cranking); + CHECK(cab.Genset.revolutions == cab.Genset.revolutions_idle); + CHECK(cab.Genset.voltage == 3000.0); + // the line breaker gets ready MainInitTime after the voltage came + for (auto second = 0; second < 10 && false == cab.Mains; ++second) { + if (cab.MainSwitchCheck()) { + close_line_breaker(cab); + } + run(dragon6, 1.0); + } + REQUIRE(cab.Mains); + CHECK(cab.PantographVoltage == 0.0); + dragon6.step(no_wire); + CHECK(cab.EngineVoltage == 3000.0); + CHECK(cab.MainCircuitPowered()); + run(dragon6, 5.0); + CHECK(cab.Mains); +} + +TEST_CASE("genset: on the catenary position the genset feeds nothing") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + wake(cab); + cab.GensetSwitch(true); + run(dragon6, 20.0); + REQUIRE(cab.Genset.is_active); + CHECK(cab.TractionMode == traction_mode::catenary); + CHECK_FALSE(cab.MainSwitchCheck()); + close_line_breaker(cab); + CHECK_FALSE(cab.Mains); + dragon6.step(no_wire); + CHECK(cab.EngineVoltage == 0.0); + CHECK(cab.TractionSupplyVoltage() == 0.0); + // running isolated, at idle + CHECK(cab.Genset.revolutions == cab.Genset.revolutions_idle); +} + +TEST_CASE("genset: on the genset position the catenary feeds nothing") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + wake(cab); + REQUIRE(cab.TractionModeSwitch(traction_mode::genset)); + // the pantographs up under the wire, the genset stopped: the line breaker never closes + CHECK_FALSE(test::start_up(test::driving(dragon6), wire, 120.0)); + REQUIRE(cab.PantographVoltage > 2900.0); + CHECK_FALSE(cab.Mains); + CHECK_FALSE(cab.MainSwitchCheck()); + dragon6.step(wire); + CHECK(cab.EngineVoltage == 0.0); + CHECK(cab.TractionSupplyVoltage() == 0.0); +} + +TEST_CASE("genset: the power at the wheels stays within the genset's") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(start_on_genset(dragon6)); + notch_up(cab); + auto peak{0.0}; + auto revolutions{0.0}; + auto over{0L}; + auto step_count{0L}; + for (; step_count < 60000 && cab.Vel < 80.0 && cab.Mains; ++step_count) { + step(dragon6, step_count); + auto const power{wheel_power(cab)}; + peak = std::max(peak, power); + revolutions = std::max(revolutions, cab.Genset.revolutions); + if (power > genset_traction_power * 1.02) { + ++over; + } + } + CAPTURE(step_count); + CAPTURE(peak); + CHECK(cab.Mains); + CHECK(cab.Vel >= 80.0); + CHECK(over == 0); + CHECK(peak <= genset_traction_power * 1.02); + CHECK(peak >= genset_traction_power * 0.95); // the limit bites + CHECK(revolutions >= 0.95 * cab.Genset.revolutions_max); +} + +TEST_CASE("genset: the revolutions follow the demand, so the power builds up") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(start_on_genset(dragon6)); + // at idle with nothing asked of it + CHECK(cab.Genset.revolutions == doctest::Approx(cab.Genset.revolutions_idle)); + CHECK(cab.GensetTractionPowerLimit() == doctest::Approx(genset_traction_power * 700.0 / 1800.0).epsilon(0.001)); + notch_up(cab); + // the demand of the traction builds up at the pace of the inverters, the revolutions follow it + auto step_count{0L}; + for (; step_count < 3000 && cab.eimv_pr < 0.99; ++step_count) { + step(dragon6, step_count); + } + CAPTURE(step_count); + REQUIRE(cab.eimv_pr >= 0.99); + run(dragon6, 3.0); + auto const after3{cab.Genset.available_power()}; + CAPTURE(after3); + // first order: 1 - exp(-1) of the way from idle to full in the time constant at the least + CHECK(after3 > 520.0 * 0.75); + run(dragon6, 9.0); + CHECK(cab.Genset.available_power() > 520.0 * 0.95); + CHECK(cab.GensetTractionPowerLimit() == doctest::Approx(cab.Genset.available_power() * 0.85)); + // notched down it goes back to idle + while (cab.DecMainCtrl(2)) { + // down to zero + } + run(dragon6, 20.0); + CHECK(cab.Genset.revolutions == doctest::Approx(cab.Genset.revolutions_idle).epsilon(0.01)); +} + +TEST_CASE("genset: running from the catenary is the same with the keys") { + // the values of a run of each one, every step + struct values { + std::vector force; + std::vector speed; + std::vector voltage; + std::vector current; + std::vector demand; + }; + auto const record = [](values &Values) { + return std::vector{ + {"Ft", [&Values](TMoverParameters const &Vehicle) { Values.force.push_back(Vehicle.Ft); return Vehicle.Ft; }}, + {"V", [&Values](TMoverParameters const &Vehicle) { Values.speed.push_back(Vehicle.V); return Vehicle.V; }}, + {"EngineVoltage", [&Values](TMoverParameters const &Vehicle) { Values.voltage.push_back(Vehicle.EngineVoltage); return Vehicle.EngineVoltage; }}, + {"Itot", [&Values](TMoverParameters const &Vehicle) { Values.current.push_back(Vehicle.Itot); return Vehicle.Itot; }}, + {"eimv_pr", [&Values](TMoverParameters const &Vehicle) { Values.demand.push_back(Vehicle.eimv_pr); return Vehicle.eimv_pr; }}, + }; + }; + auto const drive = [&record](definition const &Definition, values &Values) { + test::reseed_random(); + vehicle dragon6{Definition, 0.0, "test", 1}; + // not checked against a recorded one: the runs are compared with each other + test::trace trace{"genset/catenary", record(Values), 1, false}; + dragon6.record(trace); + test::drive_cycle(test::driving(dragon6), wire, trace); + }; + values plain; + values genset; + drive(dragon(), plain); + drive(dragon_genset(), genset); + REQUIRE(plain.speed.size() > 10000); + REQUIRE(genset.speed.size() == plain.speed.size()); + CHECK(*std::ranges::max_element(plain.speed) > 10.0); + // the first step they differ in, if any + auto const first_difference = [](std::vector const &Left, std::vector const &Right) { + return std::ranges::mismatch(Left, Right).in1 - Left.begin(); + }; + auto const size{static_cast(plain.speed.size())}; + CHECK(first_difference(plain.force, genset.force) == size); + CHECK(first_difference(plain.speed, genset.speed) == size); + CHECK(first_difference(plain.voltage, genset.voltage) == size); + CHECK(first_difference(plain.current, genset.current) == size); + CHECK(first_difference(plain.demand, genset.demand) == size); +} + +TEST_CASE("genset: stopped, it opens the line breaker") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(start_on_genset(dragon6)); + REQUIRE(cab.Genset.revolutions == doctest::Approx(cab.Genset.revolutions_idle)); + cab.GensetSwitch(false); + auto step_count{0L}; + for (; step_count < 1000 && cab.Mains; ++step_count) { + step(dragon6, step_count); + } + // coasting down from idle, the voltage falls to half, the undervoltage limit, in spinup_time * ln 2 + auto const seconds{step_count * 0.01}; + CAPTURE(seconds); + CHECK_FALSE(cab.Mains); + CHECK(seconds == doctest::Approx(3.0 * std::log(2.0)).epsilon(0.05)); + CHECK_FALSE(cab.Genset.is_active); + // and it doesn't close again + for (auto second = 0; second < 20; ++second) { + close_line_breaker(cab); + run(dragon6, 1.0); + } + CHECK_FALSE(cab.Mains); + // coasting down to a stop, with the time constant spinup_time + CHECK(cab.Genset.revolutions < 0.01 * cab.Genset.revolutions_idle); + CHECK(cab.Genset.voltage < 0.01 * cab.Genset.voltage_nominal); +} + +TEST_CASE("genset: automatic start follows the selector") { + vehicle dragon6{dragon_genset().set("Cntrl", "GensetStart", "Automatic"), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + wake(cab); + run(dragon6, 10.0); + CHECK_FALSE(cab.Genset.is_cranking); + CHECK_FALSE(cab.Genset.is_active); + REQUIRE(cab.TractionModeSwitch(traction_mode::genset)); + run(dragon6, 1.0); + CHECK(cab.Genset.is_cranking); + run(dragon6, 8.0); + CHECK(cab.Genset.is_active); + // the start switch does nothing to it + CHECK_FALSE(cab.GensetSwitch(false)); + run(dragon6, 1.0); + CHECK(cab.Genset.is_active); + REQUIRE(cab.TractionModeSwitch(traction_mode::catenary)); + dragon6.step(no_wire); + CHECK_FALSE(cab.Genset.is_active); +} + +TEST_CASE("genset: no battery, no start") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + cab.BatterySwitch(false); + REQUIRE(cab.TractionModeSwitch(traction_mode::genset)); + cab.GensetSwitch(true); + run(dragon6, 20.0); + CHECK_FALSE(cab.Power24vIsAvailable); + CHECK_FALSE(cab.Genset.is_cranking); + CHECK_FALSE(cab.Genset.is_active); + CHECK(cab.Genset.revolutions == 0.0); + // and with it, it starts + wake(cab); + run(dragon6, 10.0); + CHECK(cab.Genset.is_active); +} + +TEST_CASE("genset: the pantographs' pressure switch leaves the genset's line breaker alone") { + SUBCASE("on the genset") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(start_on_genset(dragon6)); + cab.PantPressSwitchActive = true; + cab.PantPress = 0.0; + cab.PantPressureSwitchCheck(); + CHECK(cab.Mains); + } + SUBCASE("on the pantographs it opens the line breaker, the check the genset is spared") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(test::start_up(test::driving(dragon6), wire)); + REQUIRE(cab.Mains); + // the pressure switch looks at the voltage through the couplers, not the pantographs' + cab.PantPressSwitchActive = true; + cab.PantPress = 0.0; + cab.PantPressureSwitchCheck(); + CHECK_FALSE(cab.Mains); + } +} + +namespace { + +// what braking showed of the current of the traction circuit +struct braking { + double lowest_current{0.0}; // [A], negative going back to the source + bool electrodynamic{false}; // whether the electrodynamic brake took part + double speed_lost{0.0}; // [km/h] in the 20 s of braking +}; + +// up to 60 km/h at full power, then braking with the train brake for 20 s, which the E6ACT blends with the +// electrodynamic one +braking brake_from_60(vehicle &Dragon, track const &Track) { + auto &cab{Dragon.mover()}; + notch_up(cab); + for (auto step_count = 0L; step_count < 60000 && cab.Vel < 60.0; ++step_count) { + step(Dragon, step_count, Track); + } + REQUIRE(cab.Vel >= 60.0); + while (cab.DecMainCtrl(2)) { + // down to zero + } + run(Dragon, 2.0, Track); + cab.DynamicBrakeSwitch(true); + cab.BrakeLevelSet(cab.Handle->GetPos(bh_FB)); + braking result; + auto const speed{cab.Vel}; + for (auto step_count = 0L; step_count < 2000; ++step_count) { + step(Dragon, step_count, Track); + result.lowest_current = std::min(result.lowest_current, cab.Itot); + result.electrodynamic |= cab.eimv_pr < 0.0 && cab.eimv[eimv_Ipoj] < 0.0; + } + result.speed_lost = speed - cab.Vel; + return result; +} + +} // namespace + +TEST_CASE("genset: braking electrodynamically on the genset sends nothing back") { + SUBCASE("on the genset") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + REQUIRE(start_on_genset(dragon6)); + auto const braked{brake_from_60(dragon6, no_wire)}; + REQUIRE(braked.electrodynamic); + CHECK(braked.lowest_current >= -1e-6); + CHECK(braked.speed_lost > 5.0); + CHECK(dragon6->Mains); + } + SUBCASE("on the catenary the same braking feeds the line, the check the genset is spared") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + REQUIRE(test::start_up(test::driving(dragon6), wire)); + test::release_brakes(dragon6.mover()); + run(dragon6, 5.0, wire); + auto const braked{brake_from_60(dragon6, wire)}; + REQUIRE(braked.electrodynamic); + CHECK(braked.lowest_current < -10.0); + CHECK(braked.speed_lost > 5.0); + } +} + +TEST_CASE("genset: one genset feeds the next car through the high voltage coupling") { + // both able to join the control and the high voltage lines: 35 of the E6ACT, + control 4 + high voltage 8 + consist train; + auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 1).mover()}; + auto &second{train.add(dragon().set("BuffCoupl", "AllowedFlag", 47)).mover()}; + REQUIRE((first.Couplers[end::rear].CouplingFlag & coupling::highvoltage) != 0); + wake(first); + REQUIRE(first.TractionModeSwitch(traction_mode::genset)); + first.GensetSwitch(true); + train.run(5.0, no_wire); + CHECK(second.GetTrainsetHighVoltage() == 0.0); + train.run(10.0, no_wire); + REQUIRE(first.Genset.is_active); + CHECK(second.GetTrainsetHighVoltage() > 2900.0); + CHECK(second.PantographVoltage == 0.0); + // the second one, on its catenary position with the pantographs down, takes it as the catenary's + second.BatterySwitch(true); + train.run(10.0, no_wire); + second.RelayReset(relay_t::maincircuitground | relay_t::tractionnmotoroverload | relay_t::primaryconverteroverload, range_t::local); + CHECK(second.MainSwitchCheck()); + second.MainSwitch(true, range_t::local); + CHECK(second.Mains); + // stopped, the genset takes the voltage away + first.GensetSwitch(false); + train.run(30.0, no_wire); + CHECK(second.GetTrainsetHighVoltage() < 1.0); + CHECK_FALSE(second.Mains); +} + +TEST_CASE("genset: the selector command travels along the train") { + // two locomotives in multiple: the control line, no permanent coupling + auto const coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; + consist train; + auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 1).mover()}; + auto &second{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 0, coupling).mover()}; + REQUIRE((first.Couplers[end::rear].CouplingFlag & coupling::control) != 0); + wake(first); + train.run(1.0, no_wire); + CHECK(first.TractionModeSwitch(traction_mode::genset, range_t::consist)); + CHECK(first.GensetSelected()); + CHECK(second.GensetSelected()); + first.GensetSwitch(true, range_t::consist); + CHECK(first.Genset.is_enabled); + CHECK(second.Genset.is_enabled); + first.TractionModeSwitch(traction_mode::catenary, range_t::consist); + CHECK_FALSE(second.GensetSelected()); + // the unit range keeps to the permanent couplings, which locomotives in multiple don't have + first.TractionModeSwitch(traction_mode::genset, range_t::unit); + CHECK(first.GensetSelected()); + CHECK_FALSE(second.GensetSelected()); +} + +TEST_CASE("genset: a selector command refused with the line breaker closed isn't passed on") { + auto const coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; + consist train; + auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 1).mover()}; + auto &second{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 0, coupling).mover()}; + REQUIRE(test::start_up(test::driving(train), wire)); + REQUIRE(first.Mains); + // the second one's line breaker opened by itself, the lead's is closed + second.MainSwitch(false, range_t::local); + REQUIRE_FALSE(second.Mains); + CHECK_FALSE(first.TractionModeSwitch(traction_mode::genset, range_t::consist)); + CHECK_FALSE(first.GensetSelected()); + CHECK_FALSE(second.GensetSelected()); + // with the lead's open it goes along + first.MainSwitch(false, range_t::local); + CHECK(first.TractionModeSwitch(traction_mode::genset, range_t::consist)); + CHECK(first.GensetSelected()); + CHECK(second.GensetSelected()); +} + +TEST_CASE("genset: a lead which starts its genset on its own passes the start switch on") { + auto const coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; + consist train; + auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47).set("Cntrl", "GensetStart", "Automatic"), 1).mover()}; + auto &second{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 0, coupling).mover()}; + wake(first); + train.run(1.0, no_wire); + // ignored by the lead, so its cab switch doesn't move, but the car behind starts on it + CHECK_FALSE(first.GensetSwitch(true, range_t::consist)); + CHECK_FALSE(first.Genset.is_enabled); + CHECK(second.Genset.is_enabled); + CHECK_FALSE(first.GensetSwitch(false, range_t::consist)); + CHECK_FALSE(second.Genset.is_enabled); +} + +TEST_CASE("genset: on the genset the pantographs carry no traction current") { + SUBCASE("on the genset") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(start_on_genset(dragon6)); + notch_up(cab); + run(dragon6, 10.0); + REQUIRE(cab.Itot > 50.0); + CHECK(cab.CatenaryCurrent() == 0.0); + // only a heating fed straight from the pantographs takes from the wire + cab.TotalCurrent = 40.0; + cab.HeatingPowerSource.SourceType = TPowerSource::CurrentCollector; + CHECK(cab.CatenaryCurrent() == 40.0); + cab.HeatingPowerSource.SourceType = TPowerSource::Main; + CHECK(cab.CatenaryCurrent() == 0.0); + } + SUBCASE("on the catenary the traction current goes through them, the check the genset is spared") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + REQUIRE(test::start_up(test::driving(dragon6), wire)); + test::release_brakes(cab); + run(dragon6, 5.0, wire); + notch_up(cab); + for (auto step_count = 0L; step_count < 60000 && cab.Vel < 30.0; ++step_count) { + step(dragon6, step_count, wire); + } + CAPTURE(cab.Vel); + REQUIRE(cab.Itot > 50.0); + CHECK(cab.CatenaryCurrent() == std::abs(cab.Itot) * cab.IsVehicleEIMBrakingFactor() + cab.TotalCurrent); + CHECK(cab.CatenaryCurrent() > 50.0); + } +} + +TEST_CASE("genset: a scenery command reaches the selector") { + vehicle dragon6{dragon_genset(), 0.0, "test", 1}; + auto &cab{dragon6.mover()}; + wake(cab); + // as a scenery's PutValues event gives it, one at a time + cab.PutCommand("TractionMode", 1, 0, cab.Loc); + dragon6.step(no_wire); + CHECK(cab.GensetSelected()); + CHECK(cab.CommandIn.Command.empty()); + cab.PutCommand("GensetSwitch", 1, 0, cab.Loc); + dragon6.step(no_wire); + CHECK(cab.Genset.is_enabled); + run(dragon6, 10.0); + CHECK(cab.Genset.is_active); + cab.PutCommand("TractionMode", 0, 0, cab.Loc); + dragon6.step(no_wire); + CHECK_FALSE(cab.GensetSelected()); +} diff --git a/utilities/translation.cpp b/utilities/translation.cpp index 1048dcfb8..58c9746ab 100644 --- a/utilities/translation.cpp +++ b/utilities/translation.cpp @@ -267,6 +267,8 @@ std::string locale::label_cab_control(std::string const &Label) { "fuelpump_sw:", STRN("fuel pump") }, { "oilpump_sw:", STRN("oil pump") }, { "oilfuelpump_sw:", STRN("oil and fuel pumps") }, + { "tractionmode_sw:", STRN("traction mode selector") }, + { "genset_sw:", STRN("diesel generator") }, { "motorblowersfront_sw:", STRN("motor blowers A") }, { "motorblowersrear_sw:", STRN("motor blowers B") }, { "motorblowersalloff_sw:", STRN("all motor blowers") }, diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index f057ae917..bbaaf9bb7 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -3878,7 +3878,8 @@ bool TDynamicObject::Update(double dt, double dt1) if( MoverParameters->Pantographs[end::front].is_active || MoverParameters->Pantographs[end::rear].is_active ) { if( MoverParameters->Mains // Ra 15-01: logować tylko, jeśli WS załączony - && MoverParameters->GetTrainsetHighVoltage() < 0.1f ) { // yB 16-03: i nie jest to asynchron zasilany z daleka + && MoverParameters->GetTrainsetHighVoltage() < 0.1f // yB 16-03: i nie jest to asynchron zasilany z daleka + && false == MoverParameters->GensetSelected() ) { // nor a dual-mode vehicle running on its genset // Ra 15-01: bezwzględne współrzędne pantografu nie są dostępne więc lepiej się tego nie zaloguje ErrorLog( "Bad traction: " + MoverParameters->Name @@ -4444,12 +4445,9 @@ bool TDynamicObject::Update(double dt, double dt1) double k; // tymczasowy kąt double PantDiff; TAnimPant *p; // wskaźnik do obiektu danych pantografu - double fCurrent = ( - MoverParameters->DynamicBrakeFlag && MoverParameters->ResistorsFlag ? - 0 : - std::abs( MoverParameters->Itot ) * MoverParameters->IsVehicleEIMBrakingFactor() ) - + MoverParameters->TotalCurrent; // prąd pobierany przez pojazd - bez sensu z tym (TotalCurrent) + // prąd pobierany przez pojazd z sieci: trakcyjny (on the genset of a dual-mode vehicle none) i TotalCurrent // TotalCurrent to bedzie prad nietrakcyjny (niezwiazany z napedem) + double fCurrent = MoverParameters->CatenaryCurrent(); // fCurrent+=fabs(MoverParameters->Voltage)*1e-6; //prąd płynący przez woltomierz, rozładowuje kondensator orgromowy 4µF /* double fPantCurrent = fCurrent; // normalnie cały prąd przez jeden pantograf diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 2c5a8d560..2a5634cd7 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -362,6 +362,12 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = { {user_command::oilfuelpumptoggle, &TTrain::OnCommand_oilfuelpumptoggle}, {user_command::oilpumpenable, &TTrain::OnCommand_oilpumpenable}, {user_command::oilpumpdisable, &TTrain::OnCommand_oilpumpdisable}, + {user_command::tractionmodetoggle, &TTrain::OnCommand_tractionmodetoggle}, + {user_command::tractionmodecatenary, &TTrain::OnCommand_tractionmodecatenary}, + {user_command::tractionmodegenset, &TTrain::OnCommand_tractionmodegenset}, + {user_command::gensettoggle, &TTrain::OnCommand_gensettoggle}, + {user_command::gensetenable, &TTrain::OnCommand_gensetenable}, + {user_command::gensetdisable, &TTrain::OnCommand_gensetdisable}, {user_command::waterheaterbreakertoggle, &TTrain::OnCommand_waterheaterbreakertoggle}, {user_command::waterheaterbreakerclose, &TTrain::OnCommand_waterheaterbreakerclose}, {user_command::waterheaterbreakeropen, &TTrain::OnCommand_waterheaterbreakeropen}, @@ -4276,6 +4282,95 @@ void TTrain::OnCommand_oilfuelpumptoggle(TTrain *Train, command_data const &Comm vehicle->OilPumpSwitchOff(false == enable); } +// the traction selector of a dual-mode vehicle (eu07/maszyna#536), a two-state switch +void TTrain::OnCommand_tractionmodetoggle(TTrain *Train, command_data const &Command) +{ + if (Command.action != GLFW_PRESS) + { + return; + } + if (Train->mvControlled->GensetSelected()) + { + OnCommand_tractionmodecatenary(Train, Command); + } + else + { + OnCommand_tractionmodegenset(Train, Command); + } +} + +void TTrain::OnCommand_tractionmodecatenary(TTrain *Train, command_data const &Command) +{ + if (Command.action != GLFW_PRESS) + { + return; + } + // refused with the line breaker closed: then the switch doesn't move + Train->mvControlled->TractionModeSwitch(TMoverParameters::traction_mode::catenary, range_t::consist); + if (false == Train->mvControlled->GensetSelected()) + { + Train->ggTractionModeSwitch.UpdateValue(0.0, Train->dsbSwitch); + } +} + +void TTrain::OnCommand_tractionmodegenset(TTrain *Train, command_data const &Command) +{ + if (Command.action != GLFW_PRESS) + { + return; + } + // refused with the line breaker closed, or without a genset: then the switch doesn't move + Train->mvControlled->TractionModeSwitch(TMoverParameters::traction_mode::genset, range_t::consist); + if (Train->mvControlled->GensetSelected()) + { + Train->ggTractionModeSwitch.UpdateValue(1.0, Train->dsbSwitch); + } +} + +// the start request of the genset of a dual-mode vehicle, a two-state switch +void TTrain::OnCommand_gensettoggle(TTrain *Train, command_data const &Command) +{ + if (Command.action != GLFW_PRESS) + { + return; + } + if (false == Train->mvControlled->Genset.is_enabled) + { + OnCommand_gensetenable(Train, Command); + } + else + { + OnCommand_gensetdisable(Train, Command); + } +} + +void TTrain::OnCommand_gensetenable(TTrain *Train, command_data const &Command) +{ + if (Command.action != GLFW_PRESS) + { + return; + } + // ignored by a genset which starts on its own: then the switch doesn't move + Train->mvControlled->GensetSwitch(true, range_t::consist); + if (Train->mvControlled->Genset.is_enabled) + { + Train->ggGensetButton.UpdateValue(1.0, Train->dsbSwitch); + } +} + +void TTrain::OnCommand_gensetdisable(TTrain *Train, command_data const &Command) +{ + if (Command.action != GLFW_PRESS) + { + return; + } + Train->mvControlled->GensetSwitch(false, range_t::consist); + if (false == Train->mvControlled->Genset.is_enabled) + { + Train->ggGensetButton.UpdateValue(0.0, Train->dsbSwitch); + } +} + void TTrain::OnCommand_waterheaterbreakertoggle(TTrain *Train, command_data const &Command) { @@ -10087,6 +10182,8 @@ bool TTrain::Update(double const Deltatime) ggFuelPumpButton.Update(); ggOilPumpButton.Update(); ggOilFuelPumpButton.Update(); + ggTractionModeSwitch.Update(); + ggGensetButton.Update(); ggMotorBlowersFrontButton.Update(); ggMotorBlowersRearButton.Update(); ggMotorBlowersAllOffButton.Update(); @@ -11703,6 +11800,8 @@ void TTrain::clear_cab_controls() ggFuelPumpButton.Clear(); ggOilPumpButton.Clear(); ggOilFuelPumpButton.Clear(); + ggTractionModeSwitch.Clear(); + ggGensetButton.Clear(); ggMotorBlowersFrontButton.Clear(); ggMotorBlowersRearButton.Clear(); ggMotorBlowersAllOffButton.Clear(); @@ -12064,6 +12163,12 @@ void TTrain::set_cab_controls(int const Cab) { ggOilFuelPumpButton.PutValue(mvControlled->OilFuelPumpsEnabled() ? 1.f : 0.f); } + // traction selector and genset of a dual-mode vehicle + ggTractionModeSwitch.PutValue(mvControlled->GensetSelected() ? 1.f : 0.f); + if (ggGensetButton.type() != TGaugeType::push) + { + ggGensetButton.PutValue(mvControlled->Genset.is_enabled ? 1.f : 0.f); + } // traction motor fans if (ggMotorBlowersFrontButton.type() != TGaugeType::push) { @@ -12403,6 +12508,8 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con {"fuelpump_sw:", ggFuelPumpButton}, {"oilpump_sw:", ggOilPumpButton}, {"oilfuelpump_sw:", ggOilFuelPumpButton}, + {"tractionmode_sw:", ggTractionModeSwitch}, + {"genset_sw:", ggGensetButton}, {"oilpressb:", ggOilPressB}, {"motorblowersfront_sw:", ggMotorBlowersFrontButton}, {"motorblowersrear_sw:", ggMotorBlowersRearButton}, diff --git a/vehicle/Train.h b/vehicle/Train.h index d0c3aaa8b..932e9a78a 100644 --- a/vehicle/Train.h +++ b/vehicle/Train.h @@ -374,6 +374,12 @@ class TTrain { static void OnCommand_oilfuelpumptoggle( TTrain *Train, command_data const &Command ); static void OnCommand_oilpumpenable( TTrain *Train, command_data const &Command ); static void OnCommand_oilpumpdisable( TTrain *Train, command_data const &Command ); + static void OnCommand_tractionmodetoggle( TTrain *Train, command_data const &Command ); + static void OnCommand_tractionmodecatenary( TTrain *Train, command_data const &Command ); + static void OnCommand_tractionmodegenset( TTrain *Train, command_data const &Command ); + static void OnCommand_gensettoggle( TTrain *Train, command_data const &Command ); + static void OnCommand_gensetenable( TTrain *Train, command_data const &Command ); + static void OnCommand_gensetdisable( TTrain *Train, command_data const &Command ); static void OnCommand_waterheaterbreakertoggle( TTrain *Train, command_data const &Command ); static void OnCommand_waterheaterbreakerclose( TTrain *Train, command_data const &Command ); static void OnCommand_waterheaterbreakeropen( TTrain *Train, command_data const &Command ); @@ -745,6 +751,8 @@ public: // reszta może by?publiczna TGauge ggFuelPumpButton; // fuel pump switch TGauge ggOilPumpButton; // oil pump switch TGauge ggOilFuelPumpButton; // joint oil and fuel pump switch + TGauge ggTractionModeSwitch; // traction selector of a dual-mode vehicle (catenary/genset) + TGauge ggGensetButton; // genset start switch of a dual-mode vehicle TGauge ggMotorBlowersFrontButton; // front traction motor fan switch TGauge ggMotorBlowersRearButton; // rear traction motor fan switch TGauge ggMotorBlowersAllOffButton; // motor fans shutdown switch