From 0b5459ef7bd385b94e6cf606cec406426e30e59c Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Sun, 29 Nov 2026 12:38:26 +0100 Subject: [PATCH] refactor(physics): the positions of the brake handles are private to the brakes The positions of the driver's brake valve (stepped, continuous, and of the FV4a with its cap), of the independent brake and of its EP counterpart in units with induction motors, and of the hand brake are private to physics::Braking: read through HandlePosition(), IndependentPosition(), ... and moved through SetHandlePosition(), SetIndependentPosition(), ..., by the vehicle's own stepping as by the cab, the AI and the consist braking. The gauges of the cab bind to them read-only. No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit. --- application/driverhints.cpp | 16 +++--- application/driveruipanels.cpp | 10 ++-- input/drivermouseinput.cpp | 6 +- physics/components/body.cpp | 4 +- physics/components/braking.h | 31 ++++++++--- physics/components/commands.cpp | 2 +- physics/components/controllers.cpp | 10 ++-- physics/components/pneumatics.cpp | 86 ++++++++++++++--------------- physics/components/setup.cpp | 14 ++--- physics/components/traction.cpp | 2 +- physics/consistbraking.cpp | 16 +++--- simulation/blackboxrecorder.cpp | 6 +- tests/unit/golden.cpp | 6 +- tests/unit/invariants.cpp | 4 +- tests/unit/test_brake_handles.cpp | 2 +- tests/unit/test_brakes.cpp | 2 +- tests/unit/test_cab.cpp | 2 +- tests/unit/test_consist_braking.cpp | 6 +- tests/unit/test_crew.cpp | 8 +-- tests/unit/test_drivingaid.cpp | 12 ++-- tests/unit/test_elf_controller.cpp | 2 +- tests/unit/test_pullee.cpp | 8 +-- tests/unit/vehicle.cpp | 8 +-- vehicle/ai/consist.cpp | 12 ++-- vehicle/ai/controls.cpp | 26 ++++----- vehicle/ai/engine.cpp | 4 +- vehicle/ai/force.cpp | 12 ++-- vehicle/ai/physicslog.cpp | 4 +- vehicle/ai/situation.cpp | 2 +- vehicle/ai/speed.cpp | 2 +- vehicle/cab/brakecommands.cpp | 20 +++---- vehicle/cab/controllercommands.cpp | 8 +-- vehicle/cab/setup.cpp | 4 +- vehicle/cab/train.cpp | 14 ++--- vehicle/cab/update.cpp | 10 ++-- vehicle/drivingaid.cpp | 4 +- vehicle/dynamic/lifecycle.cpp | 12 ++-- vehicle/dynamic/sounds.cpp | 4 +- widgets/vehicleparams.cpp | 4 +- 39 files changed, 210 insertions(+), 195 deletions(-) diff --git a/application/driverhints.cpp b/application/driverhints.cpp index fcc9b48dc..7750339f3 100644 --- a/application/driverhints.cpp +++ b/application/driverhints.cpp @@ -490,7 +490,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this]( float const /*Parameter*/ ) { - return occupied->brakes.config.localKind != TLocalBrake::ManualBrake || occupied->brakes.config.hasHandBrake == false || occupied->brakes.handBrakePosition == ManualBrakePosNo; } ); + return occupied->brakes.config.localKind != TLocalBrake::ManualBrake || occupied->brakes.config.hasHandBrake == false || occupied->brakes.HandBrakePosition() == ManualBrakePosNo; } ); break; } case driver_hint::manualbrakoff: { @@ -501,7 +501,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this]( float const /*Parameter*/ ) { - return occupied->brakes.config.localKind != TLocalBrake::ManualBrake || occupied->brakes.config.hasHandBrake == false || occupied->brakes.handBrakePosition == 0; } ); + return occupied->brakes.config.localKind != TLocalBrake::ManualBrake || occupied->brakes.config.hasHandBrake == false || occupied->brakes.HandBrakePosition() == 0; } ); break; } // master controller @@ -818,7 +818,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - return is_equal(occupied->brakes.handlePositionSmooth, occupied->brakes.driverValve->GetPos(bh_RP), 0.2) || (occupied->brakes.driverValve->Time && occupied->brakes.driverValve->GetCP() > occupied->brakes.config.pipeHighPressure - 0.05); } ); + return is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_RP), 0.2) || (occupied->brakes.driverValve->Time && occupied->brakes.driverValve->GetCP() > occupied->brakes.config.pipeHighPressure - 0.05); } ); // return ( BrakeCtrlPosition == gbh_RP ); } ); break; } @@ -867,7 +867,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const Parameter) { - return std::abs(mvControlling->Fb) > Parameter || is_equal(occupied->brakes.handlePositionSmooth, occupied->brakes.driverValve->GetPos(bh_EB), 0.2); }, + return std::abs(mvControlling->Fb) > Parameter || is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_EB), 0.2); }, static_cast(std::max( 0.0, std::max( @@ -885,7 +885,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - return Ready && fReady < 0.4 && is_equal(occupied->brakes.handlePositionSmooth, occupied->brakes.driverValve->GetPos(bh_RP), 0.2); } ); + return Ready && fReady < 0.4 && is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_RP), 0.2); } ); break; } case driver_hint::brakingforcelap: { @@ -899,7 +899,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) } // independent brake case driver_hint::independentbrakeapply: { - if (AIControllFlag && occupied->brakes.independentPosition < 1.0) { + if (AIControllFlag && occupied->brakes.IndependentPosition() < 1.0) { occupied->IncLocalBrakeLevel( LocalBrakePosNo ); if (occupied->EIMCtrlEmergency) { occupied->DecLocalBrakeLevel(1); @@ -909,7 +909,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const Parameter) { - return occupied->brakes.independentPosition >= Parameter; }, + return occupied->brakes.IndependentPosition() >= Parameter; }, ( LocalBrakePosNo - ( occupied->EIMCtrlEmergency ? 1 : 0 ) ) / LocalBrakePosNo ); break; } @@ -921,7 +921,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - return occupied->brakes.independentPosition < 0.05; } ); + return occupied->brakes.IndependentPosition() < 0.05; } ); break; } // reverser diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index ae9eebe15..e474514f4 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -923,13 +923,13 @@ debug_panel::update_section_vehicle( std::vector &Output ) { m_buffer.data(), m_buffer.size(), STR_C("Brakes:\n train: %.2f (mode: %d, delay: %s, load flag: %d)\n independent: %.2f (%.2f), manual: %.2f, spring: %.2f\nBrake cylinder pressures:\n train: %.2f, independent: %.2f, status: 0x%.2x\nPipe pressures:\n brake: %.2f (hat: %.2f), main: %.2f, control: %.2f\nTank pressures:\n auxiliary: %.2f, main: %.2f, control: %.2f"), // brakes - physics.brakes.handlePositionSmooth, + physics.brakes.HandlePositionSmooth(), physics.brakes.operatingMode, update_vehicle_brake().c_str(), physics.brakes.loadSetting, - physics.brakes.independentPosition, - physics.brakes.independentPositionEim, - static_cast(physics.brakes.handBrakePosition) / static_cast(ManualBrakePosNo), + physics.brakes.IndependentPosition(), + physics.brakes.IndependentPositionEim(), + static_cast(physics.brakes.HandBrakePosition()) / static_cast(ManualBrakePosNo), physics.brakes.spring.activate ? 1.f : 0.f, // cylinders physics.brakes.cylinderPressure, @@ -937,7 +937,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { physics.brakes.distributor->GetBrakeStatus(), // pipes physics.brakePipe.Pressure(), - physics.brakes.handleCapPosition, + physics.brakes.HandleCapPosition(), physics.mainPipe.Pressure(), physics.brakes.controlReservoirPressure, // tanks diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 299dac67b..37bc1992c 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -73,7 +73,7 @@ mouse_slider::bind( user_command const &Command ) { + 0.5 * ( vehicle->CoupledCtrl ? vehicle->MainCtrlPos() + vehicle->ScndCtrlPos() : vehicle->MainCtrlPos() ) / powerrange - - 0.5 * occupied->brakes.independentPosition; + - 0.5 * occupied->brakes.IndependentPosition(); m_analogue = true; m_invertrange = false; break; @@ -94,14 +94,14 @@ mouse_slider::bind( user_command const &Command ) { } case user_command::trainbrakeset: { m_valuerange = 1.0; - m_value = ( vehicle->brakes.handlePositionSmooth - vehicle->brakes.driverValve->GetPos( bh_MIN ) ) / ( vehicle->brakes.driverValve->GetPos( bh_MAX ) - vehicle->brakes.driverValve->GetPos( bh_MIN ) ); + m_value = ( vehicle->brakes.HandlePositionSmooth() - vehicle->brakes.driverValve->GetPos( bh_MIN ) ) / ( vehicle->brakes.driverValve->GetPos( bh_MAX ) - vehicle->brakes.driverValve->GetPos( bh_MIN ) ); m_analogue = true; m_invertrange = true; break; } case user_command::independentbrakeset: { m_valuerange = 1.0; - m_value = vehicle->brakes.independentPosition; + m_value = vehicle->brakes.IndependentPosition(); m_analogue = true; m_invertrange = true; break; diff --git a/physics/components/body.cpp b/physics/components/body.cpp index 145f7e141..6264ff513 100644 --- a/physics/components/body.cpp +++ b/physics/components/body.cpp @@ -1266,7 +1266,7 @@ bool physics::Vehicle::brakes_changed_asleep() const return false; constexpr double pressure_change{0.05}; // [bar] return std::abs(brakes.cylinderPressure - sleep_brakes.cylinder) > pressure_change || std::abs(brakes.spring.pressure - sleep_brakes.spring) > pressure_change || - brakes.handBrakePosition != sleep_brakes.manual || std::abs(brakes.independentPosition - sleep_brakes.local) > 0.01; + brakes.HandBrakePosition() != sleep_brakes.manual || std::abs(brakes.IndependentPosition() - sleep_brakes.local) > 0.01; } // ************************************************************************************************* @@ -1288,7 +1288,7 @@ bool physics::Vehicle::switch_physics(bool const State, wake_cause const Cause) else { // what the brake force of the last step came from, which it keeps while asleep (brakes_changed_asleep()) - sleep_brakes = {brakes.cylinderPressure, brakes.spring.pressure, brakes.handBrakePosition, brakes.independentPosition}; + sleep_brakes = {brakes.cylinderPressure, brakes.spring.pressure, brakes.HandBrakePosition(), brakes.IndependentPosition()}; } return true; diff --git a/physics/components/braking.h b/physics/components/braking.h index 9aeb5f5ab..a767be94f 100644 --- a/physics/components/braking.h +++ b/physics/components/braking.h @@ -223,13 +223,20 @@ struct Braking double pipeFlow = 0.0; // of the brake pipe, double driverValveFlow = 0.0; // through the driver's valve, double independentValveFlow = 0.0; // through the valve of the independent brake - int handlePosition = -2; // the position of the driver's valve - double handlePositionReal = 0.0; // the same, continuous, of the FV4a - double handleCapPosition = 0.0; // the cap of the FV4a - double handlePositionSmooth = -2.0; // the continuous position of the driver's valve - double independentPosition = 0.0; // the position of the independent brake - double independentPositionEim = 0.0; // the position of the EP independent brake of the asynchronous EMUs - int handBrakePosition = 0; + int const &HandlePosition() const { return handlePosition; } // the position of the driver's valve + void SetHandlePosition(int const Value) { handlePosition = Value; } + double const &HandlePositionReal() const { return handlePositionReal; } // the same, continuous, of the FV4a + void SetHandlePositionReal(double const Value) { handlePositionReal = Value; } + double const &HandleCapPosition() const { return handleCapPosition; } // the cap of the FV4a + void SetHandleCapPosition(double const Value) { handleCapPosition = Value; } + double const &HandlePositionSmooth() const { return handlePositionSmooth; } // the continuous position of the driver's valve + void SetHandlePositionSmooth(double const Value) { handlePositionSmooth = Value; } + double const &IndependentPosition() const { return independentPosition; } // the position of the independent brake + void SetIndependentPosition(double const Value) { independentPosition = Value; } + double const &IndependentPositionEim() const { return independentPositionEim; } // the position of the EP independent brake of the asynchronous EMUs + void SetIndependentPositionEim(double const Value) { independentPositionEim = Value; } + int const &HandBrakePosition() const { return handBrakePosition; } + void SetHandBrakePosition(int const Value) { handBrakePosition = Value; } int status = 0; // the bits b_* (b_off 0, b_on, b_dmg, b_rls, b_asb, b_ep ...) bool alarmChain = false; // the manual emergency brake int delaySetting = 0; // the delay set (bdelay_*) @@ -245,6 +252,16 @@ struct Braking EmuDynamicBrake emuDynamic; HoldingBrake holding; SpringBrake spring; + + private: + // the positions of the handles: the driver, the cab and the AI move them through the operations above + int handlePosition = -2; + double handlePositionReal = 0.0; + double handleCapPosition = 0.0; + double handlePositionSmooth = -2.0; + double independentPosition = 0.0; + double independentPositionEim = 0.0; + int handBrakePosition = 0; }; } // namespace physics diff --git a/physics/components/commands.cpp b/physics/components/commands.cpp index 65d16f643..f8e9130a3 100644 --- a/physics/components/commands.cpp +++ b/physics/components/commands.cpp @@ -285,7 +285,7 @@ bool physics::Vehicle::RunBrakeCommand(VehicleCommand const Command, double CVal if (CValue1 < 0.001) brakes.electrodynamic.emuWorking = true; // fBrakeCtrlPos:=BrakeCtrlPos; //to powinnno być w jednym miejscu, aktualnie w C++!!! - brakes.actualPressure = brakes.config.pressureTable[brakes.handlePosition]; + brakes.actualPressure = brakes.config.pressureTable[brakes.HandlePosition()]; OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } // youby - odluzniacz hamulcow, przyda sie else if (Command == VehicleCommand::brakeReleaser) diff --git a/physics/components/controllers.cpp b/physics/components/controllers.cpp index f16a99577..17e34428e 100644 --- a/physics/components/controllers.cpp +++ b/physics/components/controllers.cpp @@ -1168,17 +1168,17 @@ void physics::Vehicle::EIMICFromUniversalController(double dt, double const brak // 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 (UniCtrlList[mainCtrlPos].mode != brakes.HandlePosition() && MainCtrlActualPos == mainCtrlPos) // there was no move of controller, but brake only { - if (brakes.handlePosition < UniCtrlList[MainCtrlPosNo].mode) + if (brakes.HandlePosition() < UniCtrlList[MainCtrlPosNo].mode) BrakeLevelSet(UniCtrlList[MainCtrlPosNo].mode); // bottom clamping - if (brakes.handlePosition > UniCtrlList[0].mode) + if (brakes.HandlePosition() > UniCtrlList[0].mode) BrakeLevelSet(UniCtrlList[0].mode); // top clamping if (IsCabMaster()) { - while (brakes.handlePosition > UniCtrlList[mainCtrlPos].mode) + while (brakes.HandlePosition() > UniCtrlList[mainCtrlPos].mode) DecMainCtrl(1); // find nearest position - while (brakes.handlePosition < UniCtrlList[mainCtrlPos].mode) + while (brakes.HandlePosition() < UniCtrlList[mainCtrlPos].mode) IncMainCtrl(1); // find nearest position } } diff --git a/physics/components/pneumatics.cpp b/physics/components/pneumatics.cpp index 5ac5ccf5d..f057e4cce 100644 --- a/physics/components/pneumatics.cpp +++ b/physics/components/pneumatics.cpp @@ -35,24 +35,24 @@ http://mozilla.org/MPL/2.0/. void physics::Vehicle::BrakeLevelSet(double b) { // ustawienie pozycji hamulca na wartość (b) w zakresie od -2 do BrakeCtrlPosNo // jedyny dopuszczalny sposób przestawienia hamulca zasadniczego - if (brakes.handlePositionSmooth == b) + if (brakes.HandlePositionSmooth() == b) return; // nie przeliczać, jak nie ma zmiany - brakes.handlePositionSmooth = b; - if (brakes.handlePositionSmooth < brakes.driverValve->GetPos(bh_MIN)) - brakes.handlePositionSmooth = brakes.driverValve->GetPos(bh_MIN); // odcięcie - else if (brakes.handlePositionSmooth > brakes.driverValve->GetPos(bh_MAX)) - brakes.handlePositionSmooth = brakes.driverValve->GetPos(bh_MAX); + brakes.SetHandlePositionSmooth(b); + if (brakes.HandlePositionSmooth() < brakes.driverValve->GetPos(bh_MIN)) + brakes.SetHandlePositionSmooth(brakes.driverValve->GetPos(bh_MIN)); // odcięcie + else if (brakes.HandlePositionSmooth() > brakes.driverValve->GetPos(bh_MAX)) + brakes.SetHandlePositionSmooth(brakes.driverValve->GetPos(bh_MAX)); // TODO: verify whether BrakeCtrlPosR and fBrakeCtrlPos can be rolled into single variable - brakes.handlePositionReal = brakes.handlePositionSmooth; - auto x = static_cast(std::floor(brakes.handlePositionSmooth)); // jeśli odwołujemy się do BrakeCtrlPos w pośrednich, to musi być + brakes.SetHandlePositionReal(brakes.HandlePositionSmooth()); + auto x = static_cast(std::floor(brakes.HandlePositionSmooth())); // jeśli odwołujemy się do BrakeCtrlPos w pośrednich, to musi być // obcięte a nie zaokrągone - while (x > brakes.handlePosition && brakes.handlePosition < brakes.config.handlePositions) // jeśli zwiększyło się o 1 + while (x > brakes.HandlePosition() && brakes.HandlePosition() < brakes.config.handlePositions) // jeśli zwiększyło się o 1 if (!IncBrakeLevelOld()) // physics::Vehicle:: break; // wyjście awaryjne - while (x < brakes.handlePosition && brakes.handlePosition >= -1) // jeśli zmniejszyło się o 1 + while (x < brakes.HandlePosition() && brakes.HandlePosition() >= -1) // jeśli zmniejszyło się o 1 if (!DecBrakeLevelOld()) // physics::Vehicle:: break; - brakes.actualPressure = brakes.config.pressureTable[brakes.handlePosition]; // skopiowanie pozycji + brakes.actualPressure = brakes.config.pressureTable[brakes.HandlePosition()]; // skopiowanie pozycji /* //youBy: obawiam sie, ze tutaj to nie dziala :P //Ra 2014-03: było tak zrobione, że działało - po każdej zmianie pozycji była wywoływana ta @@ -76,8 +76,8 @@ void physics::Vehicle::BrakeLevelSet(double b) bool physics::Vehicle::BrakeLevelAdd(double b) { // dodanie wartości (b) do pozycji hamulca (w tym ujemnej) // zwraca false, gdy po dodaniu było by poza zakresem - BrakeLevelSet(brakes.handlePositionSmooth + b); - return b > 0.0 ? brakes.handlePositionSmooth < brakes.config.handlePositions : brakes.handlePosition > -1.0; // true, jeśli można kontynuować + BrakeLevelSet(brakes.HandlePositionSmooth() + b); + return b > 0.0 ? brakes.HandlePositionSmooth() < brakes.config.handlePositions : brakes.HandlePosition() > -1.0; // true, jeśli można kontynuować }; bool physics::Vehicle::IncBrakeLevel() @@ -138,13 +138,13 @@ double physics::Vehicle::LocalBrakeRatio(void) const double LBR; if (brakes.config.driverValveType == TBrakeHandle::MHZ_EN57) if (brakes.operatingMode >= bom_EP) - LBR = brakes.driverValve->GetEP(brakes.handlePositionReal); + LBR = brakes.driverValve->GetEP(brakes.HandlePositionReal()); else LBR = 0; else { if (LocalBrakePosNo > 0) - LBR = brakes.independentPosition; + LBR = brakes.IndependentPosition(); else LBR = 0; } @@ -162,7 +162,7 @@ double physics::Vehicle::ManualBrakeRatio(void) const double MBR; if (ManualBrakePosNo > 0) - MBR = (double)brakes.handBrakePosition / ManualBrakePosNo; + MBR = (double)brakes.HandBrakePosition() / ManualBrakePosNo; else MBR = 0; return MBR; @@ -354,12 +354,12 @@ bool physics::Vehicle::IncBrakeLevelOld(void) if (brakes.config.handlePositions > 0) { - if (brakes.handlePosition < brakes.config.handlePositions) + if (brakes.HandlePosition() < brakes.config.handlePositions) { - ++brakes.handlePosition; + brakes.SetHandlePosition(brakes.HandlePosition() + 1); // youBy: EP po nowemu IBLO = true; - if (brakes.actualPressure.PipePressureVal < 0 && brakes.config.pressureTable[brakes.handlePosition - 1].PipePressureVal > 0) + if (brakes.actualPressure.PipePressureVal < 0 && brakes.config.pressureTable[brakes.HandlePosition() - 1].PipePressureVal > 0) brakes.pipeLimiterPressure = brakePipe.Pressure(); } else @@ -381,9 +381,9 @@ bool physics::Vehicle::DecBrakeLevelOld(void) if (brakes.config.handlePositions > 0) { - if (brakes.handlePosition > (brakes.config.driverValveType == TBrakeHandle::FV4a ? -2 : -1)) + if (brakes.HandlePosition() > (brakes.config.driverValveType == TBrakeHandle::FV4a ? -2 : -1)) { - --brakes.handlePosition; + brakes.SetHandlePosition(brakes.HandlePosition() - 1); // youBy: EP po nowemu DBLO = true; // if ((BrakePressureTable[BrakeCtrlPos].PipePressureVal<0.0) && @@ -404,9 +404,9 @@ bool physics::Vehicle::DecBrakeLevelOld(void) bool physics::Vehicle::IncLocalBrakeLevel(float const CtrlSpeed) { bool IBL; - if (brakes.independentPosition < 1.0 /*and (BrakeCtrlPos<1)*/) + if (brakes.IndependentPosition() < 1.0 /*and (BrakeCtrlPos<1)*/) { - brakes.independentPosition = std::min(1.0, brakes.independentPosition + CtrlSpeed / LocalBrakePosNo); + brakes.SetIndependentPosition(std::min(1.0, brakes.IndependentPosition() + CtrlSpeed / LocalBrakePosNo)); wake_for_brake(); IBL = true; } @@ -423,9 +423,9 @@ bool physics::Vehicle::IncLocalBrakeLevel(float const CtrlSpeed) bool physics::Vehicle::DecLocalBrakeLevel(float const CtrlSpeed) { bool DBL; - if (brakes.independentPosition > 0) + if (brakes.IndependentPosition() > 0) { - brakes.independentPosition = std::max(0.0, brakes.independentPosition - CtrlSpeed / LocalBrakePosNo); + brakes.SetIndependentPosition(std::max(0.0, brakes.IndependentPosition() - CtrlSpeed / LocalBrakePosNo)); wake_for_brake(); DBL = true; } @@ -442,11 +442,11 @@ bool physics::Vehicle::DecLocalBrakeLevel(float const CtrlSpeed) bool physics::Vehicle::IncManualBrakeLevel(int CtrlSpeed) { bool IMBL; - if (brakes.handBrakePosition < ManualBrakePosNo) /*and (BrakeCtrlPos<1)*/ + if (brakes.HandBrakePosition() < ManualBrakePosNo) /*and (BrakeCtrlPos<1)*/ { - while (brakes.handBrakePosition < ManualBrakePosNo && CtrlSpeed > 0) + while (brakes.HandBrakePosition() < ManualBrakePosNo && CtrlSpeed > 0) { - brakes.handBrakePosition++; + brakes.SetHandBrakePosition(brakes.HandBrakePosition() + 1); CtrlSpeed--; } wake_for_brake(); @@ -465,11 +465,11 @@ bool physics::Vehicle::IncManualBrakeLevel(int CtrlSpeed) bool physics::Vehicle::DecManualBrakeLevel(int CtrlSpeed) { bool DMBL; - if (brakes.handBrakePosition > 0) + if (brakes.HandBrakePosition() > 0) { - while (CtrlSpeed > 0 && brakes.handBrakePosition > 0) + while (CtrlSpeed > 0 && brakes.HandBrakePosition() > 0) { - brakes.handBrakePosition--; + brakes.SetHandBrakePosition(brakes.HandBrakePosition() - 1); CtrlSpeed--; } wake_for_brake(); @@ -887,7 +887,7 @@ void physics::Vehicle::UpdateLocalBrakeValve(double dt) // the local brake of a vehicle prepared for hauling (PulleeMode) is held released, whatever asks for it if (EngineType != TEngineType::ElectricInductionMotor) { - double lbpa = brakes.config.independentTraxx ? eim_localbrake : brakes.independentPosition; + double lbpa = brakes.config.independentTraxx ? eim_localbrake : brakes.IndependentPosition(); if (EIMCtrlType > 0 && UniCtrlIntegratedLocalBrakeCtrl) { lbpa = std::max(0.0, -eimic_real); @@ -896,7 +896,7 @@ void physics::Vehicle::UpdateLocalBrakeValve(double dt) { lbpa = std::max(lbpa, brakes.holding.deceleration); } - brakes.independentValveFlow = brakes.independentValve->GetPF(PulleeMode ? 0.0 : std::max(lbpa, brakes.independentPositionEim), brakes.distributor->GetBCP(), mainPipe.Pressure(), dt, 0); + brakes.independentValveFlow = brakes.independentValve->GetPF(PulleeMode ? 0.0 : std::max(lbpa, brakes.IndependentPositionEim()), brakes.distributor->GetBCP(), mainPipe.Pressure(), dt, 0); } else { @@ -911,13 +911,13 @@ void physics::Vehicle::UpdateLocalBrakeValve(double dt) } else if (brakes.electrodynamic.splitFromPneumatic) // When LocHandleTimeTraxx and SplitEDPneumaticBrake are both active, lbpa is taken from LocHandleTimeTraxx, which is the desired behavior. { - lbpa = brakes.independentPosition; + lbpa = brakes.IndependentPosition(); } else { lbpa = 0.0; } - brakes.independentValveFlow = brakes.independentValve->GetPF(PulleeMode ? 0.0 : std::max(lbpa, brakes.independentPositionEim), brakes.distributor->GetBCP(), mainPipe.Pressure(), dt, 0); + brakes.independentValveFlow = brakes.independentValve->GetPF(PulleeMode ? 0.0 : std::max(lbpa, brakes.IndependentPositionEim()), brakes.distributor->GetBCP(), mainPipe.Pressure(), dt, 0); } } @@ -925,7 +925,7 @@ void physics::Vehicle::UpdateLocalBrakeValve(double dt) void physics::Vehicle::UpdateMainValve(double dt) { auto const temp{MainValveSupply()}; - brakes.driverValve->SetReductor(brakes.handleCapPosition); + brakes.driverValve->SetReductor(brakes.HandleCapPosition()); if (PulleeMode) { @@ -935,7 +935,7 @@ void physics::Vehicle::UpdateMainValve(double dt) else if ((brakes.config.availableOperatingModes & bom_PS) == 0 || (cabOccupied != 0 && brakes.operatingMode != bom_PS)) { - if (brakes.operatingMode < bom_EP || brakes.driverValve->GetPos(bh_EB) - 0.5 < brakes.handlePositionReal || (brakes.config.driverValveType != TBrakeHandle::MHZ_EN57 && brakes.config.driverValveType != TBrakeHandle::MHZ_K8P)) + if (brakes.operatingMode < bom_EP || brakes.driverValve->GetPos(bh_EB) - 0.5 < brakes.HandlePositionReal() || (brakes.config.driverValveType != TBrakeHandle::MHZ_EN57 && brakes.config.driverValveType != TBrakeHandle::MHZ_K8P)) { brakes.driverValveFlow = brakes.driverValve->GetPF(MainValveHandlePosition(), brakePipe.Pressure(), temp, dt, brakes.equivalentPipePressure); } @@ -944,9 +944,9 @@ void physics::Vehicle::UpdateMainValve(double dt) brakes.driverValveFlow = brakes.driverValve->GetPF(0, brakePipe.Pressure(), temp, dt, brakes.equivalentPipePressure); } } - else if (brakes.handlePosition == brakes.driverValve->GetPos(bh_EB)) + else if (brakes.HandlePosition() == brakes.driverValve->GetPos(bh_EB)) { - brakes.driverValveFlow = brakes.driverValve->GetPF(brakes.handlePositionReal, brakePipe.Pressure(), temp, dt, brakes.equivalentPipePressure); + brakes.driverValveFlow = brakes.driverValve->GetPF(brakes.HandlePositionReal(), brakePipe.Pressure(), temp, dt, brakes.equivalentPipePressure); } if (brakes.driverValveFlow < 0) // && (PipePressureVal > 0.01) //50 @@ -965,7 +965,7 @@ void physics::Vehicle::UpdateMainValve(double dt) double physics::Vehicle::MainValveSupply() { brakes.pipeLock.locked = brakePipe.Pressure() < (brakes.pipeLock.locked ? brakes.pipeLock.offPressure : brakes.pipeLock.onPressure); - bool lock_new = (brakes.pipeLock.locked && !brakes.pipeLock.unlockPressed && brakes.handlePositionReal > brakes.pipeLock.unlockHandlePosition) || (brakes.config.emergencyCutsOffDriverValve && brakes.emergencyValve.flow > 0); // new simple codition based on .fiz + bool lock_new = (brakes.pipeLock.locked && !brakes.pipeLock.unlockPressed && brakes.HandlePositionReal() > brakes.pipeLock.unlockHandlePosition) || (brakes.config.emergencyCutsOffDriverValve && brakes.emergencyValve.flow > 0); // new simple codition based on .fiz bool lock_old = brakes.config.driverValveType == TBrakeHandle::FV4a // old complex condition based on assumptions && brakePipe.Pressure() < 2.75 && (brakes.distributor->GetStatus() & b_rls) == 0 && brakes.config.subsystem == TBrakeSubSystem::ss_LSt && TrainType != train_type::emu && !brakes.pipeLock.unlockPressed; @@ -979,8 +979,8 @@ double physics::Vehicle::MainValveSupply() // the position the driver's handle works at: its own, or the one the speed control's brake intervention sets double physics::Vehicle::MainValveHandlePosition() const { - double pos = brakes.handlePositionReal; - if (SpeedCtrlUnit.IsActive && SpeedCtrlUnit.BrakeIntervention && !SpeedCtrlUnit.Standby && brakes.handlePosition != brakes.driverValve->GetPos(bh_EB)) + double pos = brakes.HandlePositionReal(); + if (SpeedCtrlUnit.IsActive && SpeedCtrlUnit.BrakeIntervention && !SpeedCtrlUnit.Standby && brakes.HandlePosition() != brakes.driverValve->GetPos(bh_EB)) { pos = brakes.driverValve->GetPos(bh_NP); if (SpeedCtrlUnit.BrakeInterventionBraking) @@ -1002,7 +1002,7 @@ void physics::Vehicle::UpdateEmergencyValve(double dt) // vents the pipe only from the vehicle driven from, whatever the controllers of the others show. // a vehicle prepared for hauling (PulleeMode) vents it for nothing of its own, only for the alarm chain, // which a train parting sets too - auto const ownemergency{radioStopFlag || (EIMCtrlEmergency && brakes.independentPosition >= 1.0) || (IsMainCtrlEmergencyPos() && IsCabMaster()) || SecuritySystem.is_braking() || + auto const ownemergency{radioStopFlag || (EIMCtrlEmergency && brakes.IndependentPosition() >= 1.0) || (IsMainCtrlEmergencyPos() && IsCabMaster()) || SecuritySystem.is_braking() || (brakes.spring.driveEmergencySpeed >= 0 && Vel > brakes.spring.driveEmergencySpeed && brakes.spring.isActive) || (0 == CabActive && (InactiveCabFlag & activation::emergencybrake) != 0)}; if (brakes.alarmChain || (ownemergency && false == PulleeMode)) diff --git a/physics/components/setup.cpp b/physics/components/setup.cpp index 7e7ca796d..36b415f3c 100644 --- a/physics/components/setup.cpp +++ b/physics/components/setup.cpp @@ -128,10 +128,10 @@ bool physics::Vehicle::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/) } ActFlowSpeed = 0.0; - brakes.handlePositionReal = brakes.handlePosition; + brakes.SetHandlePositionReal(brakes.HandlePosition()); if (brakes.config.independentValveType == TBrakeHandle::Knorr) - brakes.independentPosition = 0.5; + brakes.SetIndependentPosition(0.5); brakePipe.reservoir->CreatePress(brakePipe.Pressure()); mainPipe.reservoir->CreatePress(mainPipe.Pressure()); @@ -424,11 +424,11 @@ void physics::Vehicle::SetReadyToDepart() mainPipe.SetPressure(InitialScndPipePress(5.0)); brakePipe.SetPressure(brakes.controlReservoirPressure); brakes.cylinderPressure = 0.0; - brakes.independentPosition = 0.0; + brakes.SetIndependentPosition(0.0); if (CabActive == 0) - brakes.handlePosition = static_cast(brakes.driverValve->GetPos(bh_NP)); + brakes.SetHandlePosition(static_cast(brakes.driverValve->GetPos(bh_NP))); else - brakes.handlePosition = static_cast(brakes.driverValve->GetPos(bh_RP)); + brakes.SetHandlePosition(static_cast(brakes.driverValve->GetPos(bh_RP))); /* // NOTE: disabled and left up to the driver, if there's any MainSwitch( false ); @@ -456,8 +456,8 @@ void physics::Vehicle::SetBraked() brakePipe.SetPressure(brakes.config.pipeLowPressure); brakes.pipeCylinderPressure = brakes.config.maxCylinderPressure[3] * 0.5; brakes.cylinderPressure = brakes.config.maxCylinderPressure[3] * 0.5; - brakes.independentPosition = 0.0; - brakes.handlePosition = static_cast(brakes.driverValve->GetPos(bh_NP)); + brakes.SetIndependentPosition(0.0); + brakes.SetHandlePosition(static_cast(brakes.driverValve->GetPos(bh_NP))); brakes.pipeLimiterPressure = brakes.config.pipeLowPressure; if (brakes.config.localKind == TLocalBrake::ManualBrake || brakes.config.hasHandBrake == true) { diff --git a/physics/components/traction.cpp b/physics/components/traction.cpp index b3b6e349a..aedc46797 100644 --- a/physics/components/traction.cpp +++ b/physics/components/traction.cpp @@ -1185,7 +1185,7 @@ void physics::Vehicle::InductionMotorDynamicBrakeFlag() brakes.electrodynamic.on = true; } else if ((edBCP < 0.25 && false == localbrakeforED && false == dynbrakectrlactive && anPos < 0.01) || - (edBCP < 0.25 && ShuntModeAllow && false == dynbrakectrlactive && brakes.independentPosition < 0.01)) + (edBCP < 0.25 && ShuntModeAllow && false == dynbrakectrlactive && brakes.IndependentPosition() < 0.01)) brakes.electrodynamic.on = false; else if (brakes.cylinderPressure > 0.25 && edBCP > 0.25 || localbrakeforED || anPos > 0.02 || dynbrakectrlactive) brakes.electrodynamic.on = true; diff --git a/physics/consistbraking.cpp b/physics/consistbraking.cpp index a718a6624..235e9ac0c 100644 --- a/physics/consistbraking.cpp +++ b/physics/consistbraking.cpp @@ -171,7 +171,7 @@ void physics::ConsistBrakeBlending::UpdateShuntMode(Step &state, Vehicle &Lead) void physics::ConsistBrakeBlending::ComputeDemand(Step &state, Vehicle &Lead, double const dt1) { state.Fzad = state.amax * state.LBR * state.masa; - if ((Lead.brakes.handlePosition == Lead.brakes.driverValve->GetPos(bh_EB) + if ((Lead.brakes.HandlePosition() == Lead.brakes.driverValve->GetPos(bh_EB) && Lead.inductionMotor.braking.cylinderPressureGain < 0.001) || Lead.brakes.emergencyValve.flow > 0) state.Fzad = state.amax * state.masa; //pętla bezpieczeństwa - pełne służbowe @@ -243,7 +243,7 @@ void physics::ConsistBrakeBlending::ComputeElectrodynamicDemand(Step &state, Veh Lead.brakes.blending.edDelayTimer = state.FrED > 0 ? -Lead.brakes.blending.edNextDelay : -Lead.brakes.blending.edFirstDelay; } } - if (Lead.brakes.handlePosition == Lead.brakes.driverValve->GetPos(bh_EB) + if (Lead.brakes.HandlePosition() == Lead.brakes.driverValve->GetPos(bh_EB) && Lead.inductionMotor.braking.cylinderPressureGain < 0.001) state.FzadED = 0; //pętla bezpieczeństwa - bez ED state.FzadPN = state.Fzad - state.FrED * Lead.brakes.blending.edForceFactor; @@ -347,24 +347,24 @@ void physics::ConsistBrakeBlending::DistributeForces(Step &state, Vehicle const vehicle->brakes.distributor->GetFC( Nmax / (vehicle->NAxles * vehicle->brakes.config.blocksPerAxle), VelC) * 1000; // sila hamowania pn - vehicle->brakes.independentPositionEim = FzEP[i] / FmaxPoj; - if (vehicle->brakes.independentPositionEim>0.009) + vehicle->brakes.SetIndependentPositionEim(FzEP[i] / FmaxPoj); + if (vehicle->brakes.IndependentPositionEim()>0.009) if (vehicle->brakes.config.pressureToForce * vehicle->brakes.config.cylinders.leverRatio[0] * vehicle->brakes.config.maxCylinderPressure[0] != 0) { float x = (vehicle->brakes.config.cylinders.slackAdjusterForce / vehicle->brakes.config.cylinders.leverRatio[0] + vehicle->brakes.config.cylinders.springForce) / (vehicle->brakes.config.pressureToForce * vehicle->brakes.config.maxCylinderPressure[0]); - vehicle->brakes.independentPositionEim = x + (1 - x) * vehicle->brakes.independentPositionEim; + vehicle->brakes.SetIndependentPositionEim(x + (1 - x) * vehicle->brakes.IndependentPositionEim()); } else - vehicle->brakes.independentPositionEim = vehicle->brakes.independentPositionEim; + vehicle->brakes.SetIndependentPositionEim(vehicle->brakes.IndependentPositionEim()); else - vehicle->brakes.independentPositionEim = 0; + vehicle->brakes.SetIndependentPositionEim(0); if (vehicle->brakes.config.independentTraxx) { vehicle->eim_localbrake = state.eim_lb; - vehicle->brakes.independentPositionEim = std::max(vehicle->brakes.independentPositionEim, state.eim_lb); + vehicle->brakes.SetIndependentPositionEim(std::max(vehicle->brakes.IndependentPositionEim(), state.eim_lb)); } ++i; } diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 320c444f1..d5ab1df1a 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -450,8 +450,8 @@ void blackbox_recorder::write_cab() { sample.main_controller = static_cast(controlling->MainCtrlPos()); sample.scnd_controller = static_cast(controlling->ScndCtrlPos()); sample.reverser = static_cast(controlling->DirActive); - sample.train_brake = static_cast(occupied->brakes.handlePositionSmooth); - sample.local_brake = static_cast(occupied->brakes.independentPosition); + sample.train_brake = static_cast(occupied->brakes.HandlePositionSmooth()); + sample.local_brake = static_cast(occupied->brakes.IndependentPosition()); sample.brake_cylinder = static_cast(occupied->brakes.cylinderPressure); sample.brake_pipe = static_cast(occupied->brakePipe.Pressure()); sample.motor_current = static_cast(controlling->Im); @@ -485,7 +485,7 @@ void blackbox_recorder::write_cab() { sample.engine_temperature = controlling->diesel.heat.Ts; sample.speed_control_kmh = controlling->SpeedCtrl ? static_cast(controlling->SpeedCtrlUnit.DesiredVelocity) : 0.0f; sample.engine_power = static_cast(controlling->EnginePower); - sample.hand_brake = static_cast(std::clamp(occupied->brakes.handBrakePosition, -128, 127)); + sample.hand_brake = static_cast(std::clamp(occupied->brakes.HandBrakePosition(), -128, 127)); sample.brake_mode = static_cast(occupied->brakes.operatingMode); sample.horn = static_cast(occupied->WarningSignal()); sample.integrated_controller = static_cast(controlling->eimic); diff --git a/tests/unit/golden.cpp b/tests/unit/golden.cpp index 4c5ced5ec..da5f146c4 100644 --- a/tests/unit/golden.cpp +++ b/tests/unit/golden.cpp @@ -74,7 +74,7 @@ std::vector traction() { std::vector brakes() { return { - {"BrakeCtrlPos", [](auto const &M) { return M.brakes.handlePosition; }}, + {"BrakeCtrlPos", [](auto const &M) { return M.brakes.HandlePosition(); }}, {"PipePress", [](auto const &M) { return M.brakePipe.Pressure(); }}, {"BrakePress", [](auto const &M) { return M.brakes.cylinderPressure; }}, {"LocBrakePress", [](auto const &M) { return M.brakes.independentCylinderPressure; }}, @@ -94,12 +94,12 @@ std::vector air() { std::vector handles() { std::vector result{ - {"BrakeCtrlPosR", [](auto const &M) { return M.brakes.handlePositionReal; }}, + {"BrakeCtrlPosR", [](auto const &M) { return M.brakes.HandlePositionReal(); }}, {"dpMainValve", [](auto const &M) { return M.brakes.driverValveFlow; }}, {"HandleCP", [](auto const &M) { return M.brakes.driverValve->GetCP(); }}, {"HandleRP", [](auto const &M) { return M.brakes.driverValve->GetRP(); }}, {"HandleEP", [](auto const &M) { return M.brakes.driverValve->GetEP(); }}, - {"LocalBrakePosA", [](auto const &M) { return M.brakes.independentPosition; }}, + {"LocalBrakePosA", [](auto const &M) { return M.brakes.IndependentPosition(); }}, {"dpLocalValve", [](auto const &M) { return M.brakes.independentValveFlow; }}, }; for (int i = 0; i < 5; ++i) { diff --git a/tests/unit/invariants.cpp b/tests/unit/invariants.cpp index b3bf168c2..454978056 100644 --- a/tests/unit/invariants.cpp +++ b/tests/unit/invariants.cpp @@ -115,8 +115,8 @@ std::vector const &invariants() { }, [](auto const &M) { return values({{"V", M.V}, {"AccS", M.AccS}}); }}, {"hand brake applied, the wheels braked on the move", - [](auto const &M, double, auto const *) { return false == M.brakes.config.hasHandBrake || M.brakes.handBrakePosition == 0 || std::abs(M.V) < 0.5 || std::abs(M.Fb) > 0.0; }, - [](auto const &M) { return values({{"ManualBrakePos", M.brakes.handBrakePosition}, {"V", M.V}, {"Fb", M.Fb}}); }}, + [](auto const &M, double, auto const *) { return false == M.brakes.config.hasHandBrake || M.brakes.HandBrakePosition() == 0 || std::abs(M.V) < 0.5 || std::abs(M.Fb) > 0.0; }, + [](auto const &M) { return values({{"ManualBrakePos", M.brakes.HandBrakePosition()}, {"V", M.V}, {"Fb", M.Fb}}); }}, }; return rules; } diff --git a/tests/unit/test_brake_handles.cpp b/tests/unit/test_brake_handles.cpp index d37ef677b..98ca34336 100644 --- a/tests/unit/test_brake_handles.cpp +++ b/tests/unit/test_brake_handles.cpp @@ -111,7 +111,7 @@ TEST_CASE("brake handles: the local brake handle of every real vehicle") { real.run(60.0); for (auto const position : {0.25, 0.5, 1.0, 0.5, 0.0}) { trace.mark(std::format("local {:f}", position)); - real->brakes.independentPosition = position; + real->brakes.SetIndependentPosition(position); real.run(15.0); } trace.check(); diff --git a/tests/unit/test_brakes.cpp b/tests/unit/test_brakes.cpp index ed69a9a42..e83c25334 100644 --- a/tests/unit/test_brakes.cpp +++ b/tests/unit/test_brakes.cpp @@ -197,7 +197,7 @@ TEST_CASE("brakes: a wagon held by its hand brake on a gradient wakes and rolls slope.gradient = 0.01; vehicle wagon{definition::load("wagon")}; // made standing, it has the hand brake on (SetBraked()) - REQUIRE(wagon->brakes.handBrakePosition == ManualBrakePosNo); + REQUIRE(wagon->brakes.HandBrakePosition() == ManualBrakePosNo); wagon.hold_brake_pipe(5.0); wagon.run(90.0, slope); REQUIRE(wagon->brakes.cylinderPressure < 0.1); diff --git a/tests/unit/test_cab.cpp b/tests/unit/test_cab.cpp index e83dcc234..7de3a2bfc 100644 --- a/tests/unit/test_cab.cpp +++ b/tests/unit/test_cab.cpp @@ -150,7 +150,7 @@ TEST_CASE("cab: the spring brake shut off and released by hand, the ep brake's f scenario.act("handle stepped"); railbus.BrakeLevelSet(railbus.brakes.driverValve->GetPos(bh_RP)); CHECK(railbus.BrakeLevelAdd(1.0)); - CHECK(railbus.brakes.handlePosition == static_cast(railbus.brakes.driverValve->GetPos(bh_RP)) + 1); + CHECK(railbus.brakes.HandlePosition() == static_cast(railbus.brakes.driverValve->GetPos(bh_RP)) + 1); CHECK(railbus.BrakeLevelAdd(-1.0)); CHECK_FALSE(railbus.BrakeLevelAdd(-10.0)); CHECK_FALSE(railbus.BrakeLevelAdd(100.0)); diff --git a/tests/unit/test_consist_braking.cpp b/tests/unit/test_consist_braking.cpp index 921a636d9..85276f00f 100644 --- a/tests/unit/test_consist_braking.cpp +++ b/tests/unit/test_consist_braking.cpp @@ -79,8 +79,8 @@ TEST_CASE("consist braking: standing at full braking, every car brakes with its unit.step(2.0); for (auto const *car : unit.cars) { CAPTURE(car->Name); - CHECK(car->brakes.independentPositionEim > 0.0); - CHECK(car->brakes.independentPositionEim <= 1.0); + CHECK(car->brakes.IndependentPositionEim() > 0.0); + CHECK(car->brakes.IndependentPositionEim() <= 1.0); // the shunting mode (the holding brake) of the head car goes to all of them CHECK(car->ShuntMode == unit.cab().ShuntMode); } @@ -103,6 +103,6 @@ TEST_CASE("consist braking: with the controller at neutral and the train release CHECK(unit.blending.Figures()[demand] == doctest::Approx(0.0)); for (auto const *car : unit.cars) { CAPTURE(car->Name); - CHECK(car->brakes.independentPositionEim == doctest::Approx(0.0)); + CHECK(car->brakes.IndependentPositionEim() == doctest::Approx(0.0)); } } diff --git a/tests/unit/test_crew.cpp b/tests/unit/test_crew.cpp index 93b0306b6..4c97ee31e 100644 --- a/tests/unit/test_crew.cpp +++ b/tests/unit/test_crew.cpp @@ -200,7 +200,7 @@ TEST_CASE("crew: a locomotive under power left by its driver stops and stays bra CHECK(eu07.MainCtrlPos() == eu07.MainCtrlNoPowerPos()); CHECK(eu07.ScndCtrlPos() == 0); - CHECK(eu07.brakes.handlePosition == static_cast(eu07.brakes.driverValve->GetPos(bh_EB))); + CHECK(eu07.brakes.HandlePosition() == static_cast(eu07.brakes.driverValve->GetPos(bh_EB))); CHECK(eu07.CabActive == 0); CHECK(eu07.CabOccupied() == 0); CHECK_FALSE(eu07.CabMaster); @@ -293,7 +293,7 @@ TEST_CASE("crew: the power an integrated handle asked for goes when the driver l CHECK(impuls->MainCtrlPos() == impuls->MainCtrlNoPowerPos()); CHECK(impuls->eimic == 0.0); CHECK(impuls->eimic_real == 0.0); - CHECK(impuls->brakes.handlePosition == static_cast(impuls->brakes.driverValve->GetPos(bh_EB))); + CHECK(impuls->brakes.HandlePosition() == static_cast(impuls->brakes.driverValve->GetPos(bh_EB))); CHECK(impuls->CabOccupied() == 0); } @@ -301,12 +301,12 @@ TEST_CASE("crew: a road vehicle left by its driver gets the brake the driver sto test::reseed_random(); vehicle bus{definition::fiz("road/man/nl293"), 40.0, "bus", 1}; REQUIRE(bus->brakes.config.kind == TBrakeSystem::Individual); - REQUIRE(bus->brakes.independentPosition == 0.0); + REQUIRE(bus->brakes.IndependentPosition() == 0.0); bus->CabActivisation(); crew::secure(bus.physics(), bus.physics()); - CHECK(bus->brakes.independentPosition == 1.0); + CHECK(bus->brakes.IndependentPosition() == 1.0); CHECK(bus->MainCtrlPos() == bus->MainCtrlNoPowerPos()); bus.run(60.0, track{0.6, 0.0, 0.0, 2}); CHECK(std::abs(bus.speed()) <= 0.01); diff --git a/tests/unit/test_drivingaid.cpp b/tests/unit/test_drivingaid.cpp index 6b609b8ad..62c2d2be7 100644 --- a/tests/unit/test_drivingaid.cpp +++ b/tests/unit/test_drivingaid.cpp @@ -35,8 +35,8 @@ drivingaid::readout before(physics::Vehicle const &Physics) { drivingaid::readout result; result.throttle_first = Physics.EIMCtrlType > 0 ? std::max(0, static_cast(100.4 * Physics.eimic_real)) : Physics.MainCtrlPos(); result.throttle_second = Physics.EIMCtrlType > 0 ? Physics.MainCtrlPos() : Physics.ScndCtrlPos(); - result.brake_first = Physics.UniCtrlIntegratedBrakeCtrl ? std::max(0.0, -100.0 * Physics.eimic_real) : Physics.brakes.handlePositionSmooth; - result.local_brake = Physics.brakes.independentPosition * LocalBrakePosNo; + result.brake_first = Physics.UniCtrlIntegratedBrakeCtrl ? std::max(0.0, -100.0 * Physics.eimic_real) : Physics.brakes.HandlePositionSmooth(); + result.local_brake = Physics.brakes.IndependentPosition() * LocalBrakePosNo; return result; } @@ -68,7 +68,7 @@ TEST_CASE("driving aid: the Vectron's ED lever shows as a negative throttle step REQUIRE(braking.ed_percent.has_value()); CHECK(*braking.ed_percent == 40); // the train brake handle and the local brake, as before - CHECK(braking.brake_first == doctest::Approx(vectron->brakes.handlePositionSmooth)); + CHECK(braking.brake_first == doctest::Approx(vectron->brakes.HandlePositionSmooth())); CHECK(braking.show_local_brake); CHECK(braking.local_brake == doctest::Approx(0.0)); @@ -117,7 +117,7 @@ TEST_CASE("driving aid: the Elf leaves out the local brake it has no control of, CHECK_FALSE(braking.show_local_brake); // applied after all (the AI, or the keys), it shows - elf->brakes.independentPosition = 0.3; + elf->brakes.SetIndependentPosition(0.3); auto const applied{read(elf, elf_cab)}; CHECK(applied.show_local_brake); CHECK(applied.local_brake == doctest::Approx(3.0)); @@ -126,7 +126,7 @@ TEST_CASE("driving aid: the Elf leaves out the local brake it has no control of, TEST_CASE("driving aid: a vehicle without an EIM controller shows what it did") { vehicle eu07{definition::fiz("4e_v1/4e"), 60.0 /* km/h */, "eu07", 1}; eu07->SetMainCtrlPos(5); - eu07->brakes.independentPosition = 0.2; + eu07->brakes.SetIndependentPosition(0.2); auto const readout{read(eu07, lever_cab)}; CHECK(readout.throttle_first == 5); CHECK(readout.throttle_second == eu07->ScndCtrlPos()); @@ -162,7 +162,7 @@ TEST_CASE("driving aid: every real vehicle with a local brake control shows the vehicle real{definition::fiz(path), 40.0 /* km/h */, "real", 1}; for (auto const &[mainctrl, localbrake, eimic] : {std::tuple{0, 0.0, 0.0}, std::tuple{1, 0.4, -0.25}, std::tuple{1, 0.0, 0.6}}) { real->SetMainCtrlPos(std::min(mainctrl, real->MainCtrlPosNo)); - real->brakes.independentPosition = localbrake; + real->brakes.SetIndependentPosition(localbrake); real->eimic_real = eimic; auto const now{read(real, lever_cab)}; auto const was{before(real.physics())}; diff --git a/tests/unit/test_elf_controller.cpp b/tests/unit/test_elf_controller.cpp index e1fa8df1e..e754f3d1b 100644 --- a/tests/unit/test_elf_controller.cpp +++ b/tests/unit/test_elf_controller.cpp @@ -311,7 +311,7 @@ void hold(elf &Unit, bool Hold) { else { position = 0.0; } - car.brakes.independentPositionEim = position; + car.brakes.SetIndependentPositionEim(position); } } diff --git a/tests/unit/test_pullee.cpp b/tests/unit/test_pullee.cpp index 33f8bbfb5..f4aacbfc2 100644 --- a/tests/unit/test_pullee.cpp +++ b/tests/unit/test_pullee.cpp @@ -304,7 +304,7 @@ TEST_CASE("pullee: the local brake of a vehicle prepared for hauling stays relea // applied with the lever, as on a vehicle left on standby, and asked for by the brake computer of a unit // (what the MED of TDynamicObject writes; the lever of a Vectron does nothing without it) driven->IncLocalBrakeLevel(LocalBrakePosNo); - driven->brakes.independentPositionEim = 1.0; + driven->brakes.SetIndependentPositionEim(1.0); driven.run(20.0); if (pullee) { CHECK(driven->brakes.cylinderPressure < 0.1); @@ -329,9 +329,9 @@ TEST_CASE("pullee: entering the mode lets go of the hand brake and the spring br } SUBCASE("a unit standing with its hand brake on") { vehicle en57{definition::fiz("en57_v1/5bgb")}; - REQUIRE(en57->brakes.handBrakePosition > 0); + REQUIRE(en57->brakes.HandBrakePosition() > 0); CHECK(en57->PulleeModeSwitch(true)); - CHECK(en57->brakes.handBrakePosition == 0); + CHECK(en57->brakes.HandBrakePosition() == 0); } SUBCASE("a locomotive ready to depart, its battery on") { vehicle vectron{definition::fiz("vectron_v1/wariant_7w"), 0.1}; @@ -437,7 +437,7 @@ TEST_CASE("pullee: every real vehicle standing braked releases once prepared for // hand brakes on, spring brakes switched on, cylinders half full, the pipe at 3.5 hauled_train train{definition::fiz(path), 0.0, true}; auto const &hauled{train.hauled.physics()}; - CHECK(hauled.brakes.handBrakePosition == 0); + CHECK(hauled.brakes.HandBrakePosition() == 0); CHECK_FALSE(hauled.brakes.spring.activate); CHECK_FALSE(hauled.lowVoltage.IsBatteryOn()); train.run(180.0); diff --git a/tests/unit/vehicle.cpp b/tests/unit/vehicle.cpp index 1ef9a3256..a2a228a8a 100644 --- a/tests/unit/vehicle.cpp +++ b/tests/unit/vehicle.cpp @@ -136,9 +136,9 @@ vehicle::vehicle(definition const &Definition, double Velocity, std::string cons throw definition_error("parameters mismatch in the test vehicle definition"); } m_physics->SetMainCtrlPos(m_physics->MainCtrlNoPowerPos()); - m_physics->brakes.independentPosition = 0.0; + m_physics->brakes.SetIndependentPosition(0.0); if (driveractive) { - m_physics->brakes.handlePosition = static_cast(std::floor(m_physics->brakes.driverValve->GetPos(Cab == 0 ? bh_NP : bh_RP))); + m_physics->brakes.SetHandlePosition(static_cast(std::floor(m_physics->brakes.driverValve->GetPos(Cab == 0 ? bh_NP : bh_RP)))); // a driver keeps a vehicle on standby on its independent brake if (Cab != 0 && m_physics->brakes.config.localKind != TLocalBrake::ManualBrake && Velocity < 1.0) { m_physics->IncLocalBrakeLevel(LocalBrakePosNo); @@ -148,9 +148,9 @@ vehicle::vehicle(definition const &Definition, double Velocity, std::string cons } } else { - m_physics->brakes.handlePosition = static_cast(std::floor(m_physics->brakes.driverValve->GetPos(bh_NP))); + m_physics->brakes.SetHandlePosition(static_cast(std::floor(m_physics->brakes.driverValve->GetPos(bh_NP)))); } - m_physics->BrakeLevelSet(m_physics->brakes.handlePosition); + m_physics->BrakeLevelSet(m_physics->brakes.HandlePosition()); } void vehicle::step(track const &Track, double Dt) { diff --git a/vehicle/ai/consist.cpp b/vehicle/ai/consist.cpp index 6f87b81d3..15dc15dd2 100644 --- a/vehicle/ai/consist.cpp +++ b/vehicle/ai/consist.cpp @@ -73,7 +73,7 @@ void TController::Activation() } // odcięcie na zaworze maszynisty, FVel6 po drugiej stronie nie luzuje occupied->BrakeLevelSet( occupied->brakes.driverValve->GetPos(bh_NP) ); // odcięcie na zaworze maszynisty - BrakeLevelSet( occupied->brakes.handlePosition ); //ustawienie zmiennej GBH + BrakeLevelSet( occupied->brakes.HandlePosition() ); //ustawienie zmiennej GBH } // przejście AI na drugą stronę EN57, ET41 itp. // TODO: clean this up, there's lot of redundancy with physics::Vehicle::ChangeCab() and TTrain::MoveToVehicle() @@ -95,7 +95,7 @@ void TController::Activation() // TODO: investigate and resolve if necessary pVehicle->physics->SetCabOccupied(targetvehicle->physics->CabOccupied()); if( pVehicle->Mechanik ) { // not guaranteed, as target vehicle can be empty - pVehicle->Mechanik->BrakeLevelSet( pVehicle->physics->brakes.handlePosition ); + pVehicle->Mechanik->BrakeLevelSet( pVehicle->physics->brakes.HandlePosition() ); } // finish driver swap pVehicle = targetvehicle; @@ -110,7 +110,7 @@ void TController::Activation() occupied->brakes.pipeLimiterPressure = occupied->brakePipe.Pressure(); occupied->ActFlowSpeed = 0; } - BrakeLevelSet( occupied->brakes.handlePosition ); + BrakeLevelSet( occupied->brakes.HandlePosition() ); } if( mvControlling->EngineType == TEngineType::DieselEngine && mvControlling->ShuntModeAllow ) { // dla 2Ls150 - przed ustawieniem kierunku - można zmienić tryb pracy @@ -319,13 +319,13 @@ bool TController::CheckVehicles(DriverOrders user) && p->Mechanik != this && p->Mechanik->drivingFlags.primary ) { // ale chodzi o inny pojazd, niż aktualnie sprawdzający // a tamten ma priorytet // TODO: take into account drivers' operating modes, one or more of them might be on banking duty - if (drivingFlags.primary && occupied->DirAbsolute && occupied->brakes.handlePosition >= -1) + if (drivingFlags.primary && occupied->DirAbsolute && occupied->brakes.HandlePosition() >= -1) { // jeśli rządzi i ma kierunek p->Mechanik->primary(false); // dezaktywuje tamtego p->Mechanik->ZeroLocalBrake(); p->physics->BrakeLevelSet(p->physics->brakes.driverValve->GetPos(bh_NP)); // odcięcie na zaworze maszynisty - p->Mechanik->BrakeLevelSet(p->physics->brakes.handlePosition); // ustawienie zmiennej GBH + p->Mechanik->BrakeLevelSet(p->physics->brakes.HandlePosition()); // ustawienie zmiennej GBH } else { @@ -889,7 +889,7 @@ TController::determine_consist_state() { AIControllFlag ? BrakeCtrlPosition > 0.0 : // a human driver's handle, which BrakeCtrlPosition doesn't follow - occupied->brakes.handlePositionSmooth > occupied->brakes.driverValve->GetPos( bh_RP ) + 0.2 }; + occupied->brakes.HandlePositionSmooth() > occupied->brakes.driverValve->GetPos( bh_RP ) + 0.2 }; auto const reference { brake_charge::reference( occupied->brakePipe.Pressure(), std::min( occupied->brakes.driverValve->GetRP(), 5.0 ), trainbrakeapplied ) }; // air to charge with: the engine prepared, the main reservoir above what the pipe charges to, and the driver's diff --git a/vehicle/ai/controls.cpp b/vehicle/ai/controls.cpp index 30f6a7e29..919d77743 100644 --- a/vehicle/ai/controls.cpp +++ b/vehicle/ai/controls.cpp @@ -222,7 +222,7 @@ bool TController::IncBrake() } if( occupied->EngineType == TEngineType::ElectricInductionMotor ) { if (occupied->brakes.config.driverValveType == TBrakeHandle::MHZ_EN57) { - if (occupied->brakes.handlePosition < occupied->brakes.driverValve->GetPos(bh_FB)) + if (occupied->brakes.HandlePosition() < occupied->brakes.driverValve->GetPos(bh_FB)) OK = occupied->BrakeLevelAdd(1.0); } else { @@ -230,16 +230,16 @@ bool TController::IncBrake() } } else if( occupied->brakes.driverValve->TimeEP == false ) { - auto const initialbrakeposition { occupied->brakes.handlePositionSmooth }; + auto const initialbrakeposition { occupied->brakes.HandlePositionSmooth() }; auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], occupied->brakes.blending.maxDeceleration ) }; occupied->BrakeLevelSet( std::lerp( occupied->brakes.driverValve->GetPos( bh_EPR ), occupied->brakes.driverValve->GetPos( bh_EPB ), std::clamp( -AccDesired / AccMax * occupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); - OK = occupied->brakes.handlePositionSmooth != initialbrakeposition; + OK = occupied->brakes.HandlePositionSmooth() != initialbrakeposition; } - else if( occupied->brakes.handlePositionSmooth != occupied->brakes.driverValve->GetPos( bh_EPB ) ) { + else if( occupied->brakes.HandlePositionSmooth() != occupied->brakes.driverValve->GetPos( bh_EPB ) ) { occupied->BrakeLevelSet( occupied->brakes.driverValve->GetPos( bh_EPB ) ); if( occupied->brakes.driverValve->GetPos( bh_EPR ) - occupied->brakes.driverValve->GetPos( bh_EPN ) < 0.1 ) occupied->SwitchEPBrake( 1 ); // to nie chce działać @@ -273,8 +273,8 @@ bool TController::IncBrakeEIM() auto const brakelimit{ -2.2 * AccDesired / fMedAmax - 1.0}; //additional limit when hinted is too low auto const brakehinted{ -1.0 * occupied->AIHintLocalBrakeAccFactor * AccDesired / fMedAmax }; //preffered by AI auto const brakeposition{ maxpos * std::clamp(std::max(brakelimit, brakehinted), 0.0, 1.0)}; - OK = brakeposition != occupied->brakes.independentPosition; - occupied->brakes.independentPosition = brakeposition; + OK = brakeposition != occupied->brakes.IndependentPosition(); + occupied->brakes.SetIndependentPosition(brakeposition); } else { OK = occupied->IncLocalBrakeLevel( 1 ); @@ -383,7 +383,7 @@ bool TController::DecBrake() { case TBrakeSystem::ElectroPneumatic: { if( occupied->EngineType == TEngineType::ElectricInductionMotor ) { if( occupied->brakes.config.driverValveType == TBrakeHandle::MHZ_EN57 ) { - if( occupied->brakes.handlePosition > occupied->brakes.driverValve->GetPos( bh_RP ) ) { + if( occupied->brakes.HandlePosition() > occupied->brakes.driverValve->GetPos( bh_RP ) ) { OK = occupied->BrakeLevelAdd( -1.0 ); } } @@ -392,18 +392,18 @@ bool TController::DecBrake() { } } else if( occupied->brakes.driverValve->TimeEP == false ) { - auto const initialbrakeposition { occupied->brakes.handlePositionSmooth }; + auto const initialbrakeposition { occupied->brakes.HandlePositionSmooth() }; auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], occupied->brakes.blending.maxDeceleration ) }; occupied->BrakeLevelSet( std::lerp( occupied->brakes.driverValve->GetPos( bh_EPR ), occupied->brakes.driverValve->GetPos( bh_EPB ), std::clamp( -AccDesired / AccMax * occupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); - OK = occupied->brakes.handlePositionSmooth != initialbrakeposition; + OK = occupied->brakes.HandlePositionSmooth() != initialbrakeposition; } else { OK = false; - if (occupied->brakes.handlePositionSmooth != occupied->brakes.driverValve->GetPos(bh_EPR)) { + if (occupied->brakes.HandlePositionSmooth() != occupied->brakes.driverValve->GetPos(bh_EPR)) { occupied->BrakeLevelSet(occupied->brakes.driverValve->GetPos(bh_EPR)); OK = true; } @@ -456,8 +456,8 @@ bool TController::DecBrakeEIM() if( occupied->brakes.blending.maxDeceleration != 9.81 ) { auto const desiredacceleration { ( occupied->Vel > EU07_AI_NOMOVEMENT ? AccDesired : std::max( 0.0, AccDesired ) ) }; auto const brakeposition { std::clamp( -1.0 * occupied->AIHintLocalBrakeAccFactor * desiredacceleration / occupied->brakes.blending.maxDeceleration, 0.0, 1.0 ) }; - OK = brakeposition != occupied->brakes.independentPosition; - occupied->brakes.independentPosition = brakeposition; + OK = brakeposition != occupied->brakes.IndependentPosition(); + occupied->brakes.SetIndependentPosition(brakeposition); } else { OK = occupied->DecLocalBrakeLevel( 1 ); @@ -1176,7 +1176,7 @@ void TController::SetTimeControllers() } */ if( occupied->UniCtrlIntegratedLocalBrakeCtrl - && occupied->brakes.independentPosition > 0.95 ) { + && occupied->brakes.IndependentPosition() > 0.95 ) { while( IncBrakeEIM() ) { ; } } diff --git a/vehicle/ai/engine.cpp b/vehicle/ai/engine.cpp index 10c24d013..3bb5d68f9 100644 --- a/vehicle/ai/engine.cpp +++ b/vehicle/ai/engine.cpp @@ -181,7 +181,7 @@ bool TController::PrepareEngine() { static_cast( occupied->brakes.driverValve->GetPos( bh_RP ) ), gbh_RP }, { static_cast( occupied->brakes.driverValve->GetPos( bh_NP ) ), gbh_NP }, { static_cast( occupied->brakes.driverValve->GetPos( bh_FS ) ), gbh_FS } }; - auto const lookup{ brakepositions.find( static_cast( occupied->brakes.handlePositionSmooth ) ) }; + auto const lookup{ brakepositions.find( static_cast( occupied->brakes.HandlePositionSmooth() ) ) }; if( lookup != brakepositions.end() ) { BrakeLevelSet( lookup->second ); // GBH } @@ -191,7 +191,7 @@ bool TController::PrepareEngine() // standing: the locomotive brake first, then the pipe is filled secure_standing_train(); } - else if( ( occupied->brakes.handlePositionSmooth != occupied->brakes.driverValve->GetPos( bh_RP ) ) + else if( ( occupied->brakes.HandlePositionSmooth() != occupied->brakes.driverValve->GetPos( bh_RP ) ) && ( ( false == occupied->brakes.driverValve->Time ) || ( occupied->brakes.driverValve->GetCP() < occupied->brakes.config.pipeHighPressure - 0.05 ) ) ) { cue_action( driver_hint::trainbrakerelease ); diff --git a/vehicle/ai/force.cpp b/vehicle/ai/force.cpp index 242a98a80..70fdb5a36 100644 --- a/vehicle/ai/force.cpp +++ b/vehicle/ai/force.cpp @@ -95,7 +95,7 @@ TController::control_tractive_and_braking_force() { control_braking_force(); #if LOGVELOCITY - WriteLog("BrakePos=" + AnsiString(occupied->brakes.handlePosition) + ", MainCtrl=" + + WriteLog("BrakePos=" + AnsiString(occupied->brakes.HandlePosition()) + ", MainCtrl=" + AnsiString(mvControlling->MainCtrlPos())); #endif } @@ -253,7 +253,7 @@ void TController::control_uphill_start() { return; } if( ( occupied->brakes.config.localKind != TLocalBrake::ManualBrake ) - && ( occupied->brakes.independentPosition > 0.0 ) ) { + && ( occupied->brakes.IndependentPosition() > 0.0 ) ) { cue_action( driver_hint::independentbrakerelease ); } if( uphill_start::power_holds( now, ElapsedTime - uphillStart.startTime ) ) { @@ -522,7 +522,7 @@ void TController::control_braking_force() { || ( false == brake_charge::release_waits( IsConsistCharged, occupied->Vel < EU07_AI_NOMOVEMENT, - occupied->brakes.handlePositionSmooth > occupied->brakes.driverValve->GetPos( bh_RP ) + 0.2 ) ) ) ) { // the human driver's handle + occupied->brakes.HandlePositionSmooth() > occupied->brakes.driverValve->GetPos( bh_RP ) + 0.2 ) ) ) ) { // the human driver's handle // jak hamuje, to nie tykaj kranu za często // yB: luzuje hamulec dopiero przy różnicy opóźnień rzędu 0.2 // przy odłączaniu nie zwalniamy tu hamulca @@ -534,7 +534,7 @@ void TController::control_braking_force() { // uphill, the locomotive brake acts at once while the train brake of a long train takes many seconds to apply: // put it on as the train comes to a stand, and at once if the train has started to roll back if( ( occupied->brakes.config.localKind != TLocalBrake::ManualBrake ) - && ( occupied->brakes.independentPosition < 1.0 ) + && ( occupied->brakes.IndependentPosition() < 1.0 ) && ( ( uphill_stop_hold() && ( std::abs( velocity ) < 3.0 ) // a train that has slowed down short of where it is to stop and is to pull up further does not get it && ( VelDesired <= std::abs( velocity ) + 0.5 ) @@ -544,7 +544,7 @@ void TController::control_braking_force() { } // stop-gap measure to ensure cars actually brake to stop even when above calculactions go awry // instead of releasing the brakes and creeping into obstacle at 1-2 km/h - if( is_car() && VelDesired == 0.0 && velocity > VelDesired && ActualProximityDist <= fMinProximityDist && occupied->brakes.independentPosition < 0.01 ) { + if( is_car() && VelDesired == 0.0 && velocity > VelDesired && ActualProximityDist <= fMinProximityDist && occupied->brakes.IndependentPosition() < 0.01 ) { cue_action(driver_hint::brakingforceincrease); } } @@ -569,7 +569,7 @@ void TController::apply_independent_brake_only() { if( occupied->brakes.config.localKind != TLocalBrake::ManualBrake ) { if( false == occupied->ShuntMode // no need for independent brake if autobrake is active - && is_equal(occupied->brakes.handlePositionSmooth, occupied->brakes.driverValve->GetPos(bh_RP), 0.2) ) { + && is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_RP), 0.2) ) { cue_action( driver_hint::independentbrakeapply ); } else { diff --git a/vehicle/ai/physicslog.cpp b/vehicle/ai/physicslog.cpp index 08a40f14a..83ad149e4 100644 --- a/vehicle/ai/physicslog.cpp +++ b/vehicle/ai/physicslog.cpp @@ -77,8 +77,8 @@ std::string TController::physicslog_line() const { << mvControlling->Im << " " << int(mvControlling->MainCtrlPos()) << " " << int(mvControlling->ScndCtrlPos()) << " " - << occupied->brakes.handlePositionSmooth << " " - << occupied->brakes.independentPosition << " " + << occupied->brakes.HandlePositionSmooth() << " " + << occupied->brakes.IndependentPosition() << " " << int(mvControlling->DirActive) << " " << ( occupied->CommandIn.Text.empty() ? "none" : occupied->CommandIn.Text.c_str() ) << " " << occupied->CommandIn.Value1 << " " diff --git a/vehicle/ai/situation.cpp b/vehicle/ai/situation.cpp index ed4938226..01e98e40b 100644 --- a/vehicle/ai/situation.cpp +++ b/vehicle/ai/situation.cpp @@ -56,7 +56,7 @@ TController::update_timers( double dt ) { WaitingTime += dt; fBrakeTime -= dt; // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę hamulca fBrakeHeldTime += dt; - if( occupied->brakes.handlePositionSmooth != occupied->brakes.driverValve->GetPos( bh_FS ) ) { + if( occupied->brakes.HandlePositionSmooth() != occupied->brakes.driverValve->GetPos( bh_FS ) ) { // brake charging timeout starts after charging ends BrakeChargingCooldown += dt; } diff --git a/vehicle/ai/speed.cpp b/vehicle/ai/speed.cpp index 550b8819e..1f1a1d343 100644 --- a/vehicle/ai/speed.cpp +++ b/vehicle/ai/speed.cpp @@ -507,7 +507,7 @@ TController::adjust_desired_speed_for_braking_curve( double const Vel ) { BrakeCtrlPosition, // IncLocalBrakeLevel() moves the independent brake handle on a vehicle without one too ( occupied->brakes.config.localKind == TLocalBrake::PneumaticBrake || occupied->brakes.config.localKind == TLocalBrake::HydraulicBrake ) ? - occupied->brakes.independentPosition : + occupied->brakes.IndependentPosition() : 0.0 ), vehicle_ai::brake_response_horizon( occupied, BrakeSystem, AbsAccS, fBrake_a0[ 0 ] ), vehicle_ai::brake_response_horizon( occupied, BrakeSystem, 1.0, fillbrakea0 ) }; diff --git a/vehicle/cab/brakecommands.cpp b/vehicle/cab/brakecommands.cpp index 1528887c9..3d5cb341c 100644 --- a/vehicle/cab/brakecommands.cpp +++ b/vehicle/cab/brakecommands.cpp @@ -112,9 +112,9 @@ void TTrain::OnCommand_independentbrakedecrease(TTrain *Train, command_data cons if (Train->occupied->brakes.config.localKind != TLocalBrake::ManualBrake // Ra 1014-06: AI potrafi zahamować pomocniczym mimo jego braku - odhamować jakoś trzeba // TODO: sort AI out so it doesn't do things it doesn't have equipment for - || Train->occupied->brakes.independentPosition > 0) + || Train->occupied->brakes.IndependentPosition() > 0) { - if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->brakes.independentPosition == 0.0) + if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->brakes.IndependentPosition() == 0.0) { OnCommand_mastercontrollerincrease(Train, Command); } @@ -141,9 +141,9 @@ void TTrain::OnCommand_independentbrakedecreasefast(TTrain *Train, command_data if (Train->occupied->brakes.config.localKind != TLocalBrake::ManualBrake // Ra 1014-06: AI potrafi zahamować pomocniczym mimo jego braku - odhamować jakoś trzeba // TODO: sort AI out so it doesn't do things it doesn't have equipment for - || Train->occupied->brakes.independentPosition > 0) + || Train->occupied->brakes.IndependentPosition() > 0) { - if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->brakes.independentPosition == 0.0) + if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->brakes.IndependentPosition() == 0.0) { OnCommand_mastercontrollerincreasefast(Train, Command); } @@ -165,7 +165,7 @@ void TTrain::OnCommand_independentbrakeset(TTrain *Train, command_data const &Co if (Command.action != GLFW_RELEASE) { - Train->occupied->brakes.independentPosition = std::clamp(Command.param1, 0.0, 1.0); + Train->occupied->brakes.SetIndependentPosition(std::clamp(Command.param1, 0.0, 1.0)); } /* Train->controlled->LocalBrakePos = ( @@ -298,7 +298,7 @@ void TTrain::OnCommand_trainbrakeincrease(TTrain *Train, command_data const &Com if (Command.action == GLFW_REPEAT && Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a) Train->occupied->BrakeLevelAdd(Global.brake_speed * Command.time_delta * Train->occupied->brakes.config.handlePositions); else if (Command.action == GLFW_PRESS && Train->occupied->brakes.config.driverValveType != TBrakeHandle::FV4a) - Train->set_train_brake(Train->occupied->brakes.handlePositionSmooth + Global.fBrakeStep); + Train->set_train_brake(Train->occupied->brakes.HandlePositionSmooth() + Global.fBrakeStep); } void TTrain::OnCommand_trainbrakedecrease(TTrain *Train, command_data const &Command) @@ -306,7 +306,7 @@ void TTrain::OnCommand_trainbrakedecrease(TTrain *Train, command_data const &Com if (Command.action == GLFW_REPEAT && Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a) Train->occupied->BrakeLevelAdd(-Global.brake_speed * Command.time_delta * Train->occupied->brakes.config.handlePositions); else if (Command.action == GLFW_PRESS && Train->occupied->brakes.config.driverValveType != TBrakeHandle::FV4a) - Train->set_train_brake(Train->occupied->brakes.handlePositionSmooth - Global.fBrakeStep); + Train->set_train_brake(Train->occupied->brakes.HandlePositionSmooth() - Global.fBrakeStep); else if (Command.action == GLFW_RELEASE) { // release @@ -418,7 +418,7 @@ void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_dat if (Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a) { - Train->occupied->brakes.handleCapPosition = std::clamp(Train->occupied->brakes.handleCapPosition - 0.01, -1.5, 2.0); + Train->occupied->brakes.SetHandleCapPosition(std::clamp(Train->occupied->brakes.HandleCapPosition() - 0.01, -1.5, 2.0)); } else { @@ -435,7 +435,7 @@ void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_dat if (Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a) { - Train->occupied->brakes.handleCapPosition = std::clamp(Train->occupied->brakes.handleCapPosition + 0.01, -1.5, 2.0); + Train->occupied->brakes.SetHandleCapPosition(std::clamp(Train->occupied->brakes.HandleCapPosition() + 0.01, -1.5, 2.0)); } else { @@ -450,7 +450,7 @@ void TTrain::OnCommand_trainbrakebasepressurereset(TTrain *Train, command_data c if (Command.action == GLFW_PRESS) { - Train->occupied->brakes.handleCapPosition = 0; + Train->occupied->brakes.SetHandleCapPosition(0); } } diff --git a/vehicle/cab/controllercommands.cpp b/vehicle/cab/controllercommands.cpp index a25bc797e..b02129e65 100644 --- a/vehicle/cab/controllercommands.cpp +++ b/vehicle/cab/controllercommands.cpp @@ -97,7 +97,7 @@ void TTrain::OnCommand_jointcontrollerset(TTrain *Train, command_data const &Com } else { - Train->occupied->brakes.independentPosition = 0; + Train->occupied->brakes.SetIndependentPosition(0); } } else @@ -113,7 +113,7 @@ void TTrain::OnCommand_jointcontrollerset(TTrain *Train, command_data const &Com } else { - Train->occupied->brakes.independentPosition = negativeRange; + Train->occupied->brakes.SetIndependentPosition(negativeRange); } if (Train->controlled->MainCtrlPowerPos() > 0) { @@ -138,7 +138,7 @@ void TTrain::OnCommand_mastercontrollerincrease(TTrain *Train, command_data cons auto const splitMode{Train->controlled->brakes.electrodynamic.splitFromPneumatic}; // when SplitEDPneumaticBrake is true the joint controller's negative range maps // to the dedicated dynamic-brake lever (DynamicBrakeCtrl) rather than to LocalBrake - auto const negativeRangeActive{splitMode ? Train->controlled->brakes.electrodynamic.controllerPosition > 0.0 : Train->occupied->brakes.independentPosition > 0.0}; + auto const negativeRangeActive{splitMode ? Train->controlled->brakes.electrodynamic.controllerPosition > 0.0 : Train->occupied->brakes.IndependentPosition() > 0.0}; if (Train->ggJointCtrl.SubModel != nullptr && negativeRangeActive) { if (splitMode) @@ -172,7 +172,7 @@ void TTrain::OnCommand_mastercontrollerincreasefast(TTrain *Train, command_data { // on press or hold auto const splitMode{Train->controlled->brakes.electrodynamic.splitFromPneumatic}; - auto const negativeRangeActive{splitMode ? Train->controlled->brakes.electrodynamic.controllerPosition > 0.0 : Train->occupied->brakes.independentPosition > 0.0}; + auto const negativeRangeActive{splitMode ? Train->controlled->brakes.electrodynamic.controllerPosition > 0.0 : Train->occupied->brakes.IndependentPosition() > 0.0}; if (Train->ggJointCtrl.SubModel != nullptr && negativeRangeActive) { if (splitMode) diff --git a/vehicle/cab/setup.cpp b/vehicle/cab/setup.cpp index 65a9be482..ae1add60b 100644 --- a/vehicle/cab/setup.cpp +++ b/vehicle/cab/setup.cpp @@ -1676,8 +1676,8 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con } } // TODO: move viable dedicated gauges to the automatic array - std::unordered_map const autointgauges = { - {"manualbrake:", &occupied->brakes.handBrakePosition}, + std::unordered_map const autointgauges = { + {"manualbrake:", &occupied->brakes.HandBrakePosition()}, {"pantselect_sw:", &occupied->pantographCircuit.presets.second[cab_to_end()]}, }; { diff --git a/vehicle/cab/train.cpp b/vehicle/cab/train.cpp index 909d44531..9d9df0c45 100644 --- a/vehicle/cab/train.cpp +++ b/vehicle/cab/train.cpp @@ -214,15 +214,15 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const dict->insert("scndctrl_pos", controlled->ScndCtrlPos()); dict->insert("dynamicbrake_pos", controlled->brakes.electrodynamic.controllerPosition); dict->insert("scnd_ctrl_actual_pos", controlled->ScndCtrlActualPos); - dict->insert("brakectrl_pos", controlled->brakes.handlePositionSmooth); - dict->insert("localbrake_pos", controlled->brakes.independentPosition); + dict->insert("brakectrl_pos", controlled->brakes.HandlePositionSmooth()); + dict->insert("localbrake_pos", controlled->brakes.IndependentPosition()); dict->insert("new_speed", occupied->NewSpeed); dict->insert("speedctrl", occupied->SpeedCtrlValue); dict->insert("speedctrlpower", occupied->SpeedCtrlUnit.DesiredPower); dict->insert("speedctrlactive", occupied->SpeedCtrlUnit.IsActive); dict->insert("speedctrlstandby", occupied->SpeedCtrlUnit.Standby); // brakes - dict->insert("manual_brake", occupied->brakes.handBrakePosition > 0); + dict->insert("manual_brake", occupied->brakes.HandBrakePosition() > 0); bool const bEP = controlled->brakes.independentValve->GetCP() > 0.2 || fEIMParams[0][5] > 0.01; dict->insert("dir_brake", bEP); bool bPN{false}; @@ -463,16 +463,16 @@ void TTrain::set_master_controller(double const Position) void TTrain::set_train_brake(double const Position) { - auto const originalbrakeposition{static_cast(100.0 * occupied->brakes.handlePositionSmooth)}; + auto const originalbrakeposition{static_cast(100.0 * occupied->brakes.HandlePositionSmooth())}; occupied->BrakeLevelSet(Position); - if (static_cast(100.0 * occupied->brakes.handlePositionSmooth) == originalbrakeposition) + if (static_cast(100.0 * occupied->brakes.HandlePositionSmooth()) == originalbrakeposition) { return; } // sound feedback if the lever movement activates one of the switches - if (true == is_eztoer() && false == ((originalbrakeposition / 100 == 0 || originalbrakeposition / 100 >= 5) && (occupied->brakes.handlePosition == 0 || occupied->brakes.handlePosition >= 5)) && dsbPneumaticSwitch) + if (true == is_eztoer() && false == ((originalbrakeposition / 100 == 0 || originalbrakeposition / 100 >= 5) && (occupied->brakes.HandlePosition() == 0 || occupied->brakes.HandlePosition() >= 5)) && dsbPneumaticSwitch) { dsbPneumaticSwitch->play(); } @@ -482,7 +482,7 @@ void TTrain::zero_charging_train_brake() { using enum TBrakeHandle; - if (occupied->brakes.handlePosition == -1 && DynamicObject->Controller != AIdriver && Global.iFeedbackMode < 3 && + if (occupied->brakes.HandlePosition() == -1 && DynamicObject->Controller != AIdriver && Global.iFeedbackMode < 3 && (occupied->brakes.config.driverValveType == FVel6 || occupied->brakes.config.driverValveType == MHZ_EN57 || occupied->brakes.config.driverValveType == MHZ_K8P)) { // Odskakiwanie hamulce EP diff --git a/vehicle/cab/update.cpp b/vehicle/cab/update.cpp index 257b0efcc..61d9dd681 100644 --- a/vehicle/cab/update.cpp +++ b/vehicle/cab/update.cpp @@ -920,7 +920,7 @@ void TTrain::updateTrainLamps() btLampkaRadio.Turn(occupied->Radio() && occupied->RadioFuse()); btLampkaRadioMessage.Turn(radio_message_played); btLampkaRadioStop.Turn(occupied->Radio() && occupied->RadioFuse() && occupied->RadioStopFlag()); - btLampkaHamulecReczny.Turn(occupied->brakes.handBrakePosition > 0); + btLampkaHamulecReczny.Turn(occupied->brakes.HandBrakePosition() > 0); // NBMX wrzesien 2003 - drzwi oraz sygnał odjazdu if (DynamicObject->Mechanik != nullptr) { @@ -1191,7 +1191,7 @@ void TTrain::updateMasterControllers(bool const lowvoltagepower) // represents the dedicated dynamic-brake lever (DBPN steps), not the pneumatic local brake auto const negativePart{controlled->brakes.electrodynamic.splitFromPneumatic ? (controlled->brakes.electrodynamic.controllerPosition > 0.0 ? controlled->brakes.electrodynamic.controllerPosition * controlled->brakes.electrodynamic.controllerPositions * -1 * brakerangemultiplier : 0.0) : - occupied->brakes.independentPosition > 0.0 ? occupied->brakes.independentPosition * LocalBrakePosNo * -1 * brakerangemultiplier : + occupied->brakes.IndependentPosition() > 0.0 ? occupied->brakes.IndependentPosition() * LocalBrakePosNo * -1 * brakerangemultiplier : 0.0}; ggJointCtrl.UpdateValue(negativePart < 0.0 ? static_cast(negativePart) : controlled->CoupledCtrl ? static_cast(double(controlled->MainCtrlPos() + controlled->ScndCtrlPos())) : @@ -1306,7 +1306,7 @@ void TTrain::updateBrakeControllers() { // else //standardowa prodedura z kranem powiązanym z klawiaturą // ggBrakeCtrl.UpdateValue(double(occupied->BrakeCtrlPos)); - ggBrakeCtrl.UpdateValue(static_cast(occupied->brakes.handlePositionSmooth)); + ggBrakeCtrl.UpdateValue(static_cast(occupied->brakes.HandlePositionSmooth())); ggBrakeCtrl.Update(); } } @@ -1320,14 +1320,14 @@ void TTrain::updateBrakeControllers() // Ra: nie najlepsze miejsce, ale na początek gdzieś to dać trzeba // Firleju: dlatego kasujemy i zastepujemy funkcją w Console auto const b = std::clamp(Console::AnalogCalibrateGet(1), 0.f, 1.f); - occupied->brakes.independentPosition = b; + occupied->brakes.SetIndependentPosition(b); ggLocalBrake.UpdateValue(b * LocalBrakePosNo); } else #endif { // standardowa prodedura z kranem powiązanym z klawiaturą - ggLocalBrake.UpdateValue(static_cast(occupied->brakes.independentPosition * LocalBrakePosNo)); + ggLocalBrake.UpdateValue(static_cast(occupied->brakes.IndependentPosition() * LocalBrakePosNo)); } ggLocalBrake.Update(); } diff --git a/vehicle/drivingaid.cpp b/vehicle/drivingaid.cpp index d0ecb2c15..15c68faa0 100644 --- a/vehicle/drivingaid.cpp +++ b/vehicle/drivingaid.cpp @@ -70,8 +70,8 @@ input from_vehicles(physics::Vehicle const &Vehicle, physics::Vehicle const &Con result.dynamicbrakeposno = Controlling.brakes.electrodynamic.controllerPositions; result.mainctrlpos = Controlling.MainCtrlPos(); result.scndctrlpos = Controlling.ScndCtrlPos(); - result.brakectrlpos = Vehicle.brakes.handlePositionSmooth; - result.localbrakepos = Vehicle.brakes.independentPosition; + result.brakectrlpos = Vehicle.brakes.HandlePositionSmooth(); + result.localbrakepos = Vehicle.brakes.IndependentPosition(); result.cab = Cab; return result; } diff --git a/vehicle/dynamic/lifecycle.cpp b/vehicle/dynamic/lifecycle.cpp index 3af162884..64416967f 100644 --- a/vehicle/dynamic/lifecycle.cpp +++ b/vehicle/dynamic/lifecycle.cpp @@ -264,14 +264,13 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" // controller position physics->SetMainCtrlPos(physics->MainCtrlNoPowerPos()); // ustawienie pozycji hamulca - physics->brakes.independentPosition = 0.0; + physics->brakes.SetIndependentPosition(0.0); if (driveractive) { if (Cab == 0) - physics->brakes.handlePosition = - static_cast( std::floor(physics->brakes.driverValve->GetPos(bh_NP)) ); + physics->brakes.SetHandlePosition(static_cast( std::floor(physics->brakes.driverValve->GetPos(bh_NP)) )); else - physics->brakes.handlePosition = static_cast( std::floor(physics->brakes.driverValve->GetPos(bh_RP)) ); + physics->brakes.SetHandlePosition(static_cast( std::floor(physics->brakes.driverValve->GetPos(bh_RP)) )); // engage independent brake if applicable, if the vehicle is to be on standby // NOTE: with more than one driver in the consist this is likely to go awery, since all but one will be sent to sleep @@ -288,12 +287,11 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" } } else - physics->brakes.handlePosition = - static_cast( std::floor(physics->brakes.driverValve->GetPos(bh_NP)) ); + physics->brakes.SetHandlePosition(static_cast( std::floor(physics->brakes.driverValve->GetPos(bh_NP)) )); // poprawienie hamulca po ewentualnym przestawieniu przez Pascal // TODO: check if needed, we're not in Pascal anymore, Toto - physics->BrakeLevelSet(physics->brakes.handlePosition); + physics->BrakeLevelSet(physics->brakes.HandlePosition()); // dodatkowe parametry yB MoreParams += "."; // wykonuje o jedną iterację za mało, więc trzeba mu dodać diff --git a/vehicle/dynamic/sounds.cpp b/vehicle/dynamic/sounds.cpp index 778b2163b..e5bccba88 100644 --- a/vehicle/dynamic/sounds.cpp +++ b/vehicle/dynamic/sounds.cpp @@ -260,7 +260,7 @@ void TDynamicObject::renderEpBrakeSounds( double const dt ) { if (physics->brakes.config.kind == TBrakeSystem::ElectroPneumatic && physics->brakes.independentValve) { auto const epbrakepressureratio{ std::min( std::max( 0.0, physics->brakes.independentValve->GetCP() ) / std::max( 1.0, physics->brakes.config.maxCylinderPressure[0] ), m_epbrakepressurechangedectimer > -1.0f ? - std::max( physics->brakes.independentPositionEim, physics->brakes.distributor->GetEDBCP() / physics->brakes.config.maxCylinderPressure[3]) : + std::max( physics->brakes.IndependentPositionEim(), physics->brakes.distributor->GetEDBCP() / physics->brakes.config.maxCylinderPressure[3]) : 1.0 ) }; if ( m_lastepbrakepressure != -1.f ) { // HACK: potentially reset playback of opening bookend sounds @@ -296,7 +296,7 @@ void TDynamicObject::renderEpBrakeSounds( double const dt ) { } if ( m_epbrakepressurechangeinctimer == 0 || m_epbrakepressurechangedectimer == 0 ) m_lastepbrakepressure = std::min( physics->brakes.independentValve->GetCP(), - physics->brakes.independentPositionEim * std::max( 1.0, physics->brakes.config.maxCylinderPressure[0] ) ); + physics->brakes.IndependentPositionEim() * std::max( 1.0, physics->brakes.config.maxCylinderPressure[0] ) ); } } diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp index b80cb28a7..8d786f02b 100644 --- a/widgets/vehicleparams.cpp +++ b/widgets/vehicleparams.cpp @@ -201,11 +201,11 @@ void ui::vehicleparams_panel::render_contents() STR_C("Brakes:\n train: %.2f, independent: %.2f, mode: %d, delay: %s, load flag: %d\nBrake cylinder pressures:\n train: %.2f, independent: %.2f, status: 0x%.2x\nPipe pressures:\n " "brake: %.2f (hat: %.2f), main: %.2f, control: %.2f\nTank pressures:\n auxiliary: %.2f, main: %.2f, control: %.2f"), // brakes - physics.brakes.handlePositionSmooth, physics.brakes.independentPosition, physics.brakes.operatingMode, brakedelay.c_str(), physics.brakes.loadSetting, + physics.brakes.HandlePositionSmooth(), physics.brakes.IndependentPosition(), physics.brakes.operatingMode, brakedelay.c_str(), physics.brakes.loadSetting, // cylinders physics.brakes.cylinderPressure, physics.brakes.independentCylinderPressure, physics.brakes.distributor->GetBrakeStatus(), // pipes - physics.brakePipe.Pressure(), physics.brakes.handleCapPosition, physics.mainPipe.Pressure(), physics.brakes.controlReservoirPressure, + physics.brakePipe.Pressure(), physics.brakes.HandleCapPosition(), physics.mainPipe.Pressure(), physics.brakes.controlReservoirPressure, // tanks physics.brakes.distributor->GetBRP(), physics.air.MainReservoirPressure(), physics.brakes.distributor->GetCRP());