mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 05:02:45 +01:00
d0b8d689af
The blending of the electrodynamic and the electropneumatic brakes over a consist driven by induction motors (the MED of the .fiz) moves out of TDynamicObject into physics::ConsistBrakeBlending (physics/consistbraking.*). It works on the physics of the vehicles alone, given in the order of the consist; TDynamicObject::distributeInductionBraking() only lists them from the occupied cab, as its loops walked them, and hands the result (the most deceleration of the service braking) to the driver. The state of the blending (the ED demand of the step before, the log of MEDLOGS/, the figures of the debug screen) goes with it. The code moves as it was: its arithmetic, its float and double conversions and the order of its steps are kept. Nothing in the unit tests reached it before, as they don't run TDynamicObject; now that it stands on its own, tests of it are added (test_consist_braking.cpp): the full braking demand over the mass of an Elf, the electropneumatic brake of every car standing, no demand at neutral. The figures of the debug screen start at zero rather than uninitialised for a vehicle that never led a consist.
418 lines
17 KiB
C++
418 lines
17 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "physics/consistbraking.h"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <string>
|
|
|
|
#include "physics/vehicle.h"
|
|
#include "physics/brakes.h"
|
|
#include "utilities/utilities.h"
|
|
|
|
// the state shared by the steps of the blending
|
|
struct physics::ConsistBrakeBlending::Step {
|
|
int np { 0 };
|
|
double masa { 0.0 };
|
|
double FrED { 0.0 };
|
|
double masamax { 0.0 };
|
|
double FmaxPN { 0.0 };
|
|
double FfulED { 0.0 };
|
|
double FmaxED { 0.0 };
|
|
int osie { 0 };
|
|
double eimic { 0.0 };
|
|
double LBR { 0.0 };
|
|
double eim_lb { 0.0 };
|
|
double amax { 0.0 };
|
|
bool doorisopen { false };
|
|
double Fzad { 0.0 };
|
|
double FzadED { 0.0 };
|
|
double FzadPN { 0.0 };
|
|
float nPrzekrF { 0.f };
|
|
};
|
|
|
|
// the consist with induction motors driven and braked as a whole, its braking split between the ED and the EP brakes
|
|
double physics::ConsistBrakeBlending::Update(Vehicle &Lead, std::vector<Vehicle *> const &Consist, Inputs const &Given, double const dt1)
|
|
{
|
|
Step state;
|
|
SetControl( state, Lead, Given, dt1 );
|
|
SumForces( state, Consist );
|
|
ComputeDeceleration( state, Lead );
|
|
UpdateShuntMode( state, Lead );
|
|
ComputeDemand( state, Lead, dt1 );
|
|
OpenLog( state, Lead );
|
|
ComputeElectrodynamicDemand( state, Lead, dt1 );
|
|
DistributeForces( state, Lead, Consist, dt1 );
|
|
Record( state, Lead, Consist, dt1 );
|
|
|
|
lastEdDemand = state.FzadED;
|
|
return state.amax;
|
|
}
|
|
|
|
// step 0a of the blending: the demand of the integrated controller read and passed down the consist
|
|
void physics::ConsistBrakeBlending::SetControl(Step &state, Vehicle &Lead, Inputs const &Given, double const dt1)
|
|
{
|
|
// 0a. ustal aktualna nastawe zadania sily napedowej i hamowania
|
|
if( Lead.Power < 1
|
|
&& Given.owner != nullptr ) {
|
|
Lead.MainCtrlPos = Given.owner->MainCtrlPos*Lead.MainCtrlPosNo / std::max(1, Given.owner->MainCtrlPosNo);
|
|
Lead.SpeedCtrlValue = Given.owner->SpeedCtrlValue;
|
|
Lead.SpeedCtrlUnit.IsActive = Given.owner->SpeedCtrlUnit.IsActive;
|
|
}
|
|
Lead.CheckEIMIC(dt1);
|
|
Lead.CheckSpeedCtrl(dt1);
|
|
|
|
state.eimic = std::min(Lead.eimic, Lead.eimicSpeedCtrl);
|
|
Lead.eimic_real = state.eimic;
|
|
// Elf: full braking at once in the lowest position, and in the emergency brake position below it
|
|
if (Lead.EIMCtrlType == 2 && Lead.MainCtrlPos <= Lead.EIMCtrlEmergencyPositions())
|
|
state.eimic = -1.0;
|
|
Lead.SendCtrlToNext(VehicleCommand::integratedController, std::max(0., state.eimic), Lead.CabActive);
|
|
state.LBR = std::max(-state.eimic, 0.);
|
|
state.eim_lb = Given.aiDriving || !Lead.brakes.independentTraxx ? 0 : Lead.eim_localbrake;
|
|
}
|
|
|
|
// steps 1-2 of the blending: the masses and the most braking forces, pneumatic and ED, summed over the consist
|
|
void physics::ConsistBrakeBlending::SumForces(Step &state, std::vector<Vehicle *> const &Consist)
|
|
{
|
|
auto FED { 0.0 };
|
|
auto Frj { 0.0 };
|
|
|
|
// 1. ustal wymagana sile hamowania calego pociagu
|
|
// - opoznienie moze byc ustalane na podstawie charakterystyki
|
|
// - opoznienie moze byc ustalane na podstawie mas i cisnien granicznych
|
|
//
|
|
|
|
// 2. ustal mozliwa do realizacji sile hamowania ED
|
|
// - w szczegolnosci powinien brac pod uwage rozne sily hamowania
|
|
for (auto *vehicle : Consist)
|
|
{
|
|
++state.np;
|
|
state.masamax +=
|
|
vehicle->brakes.maxPressureMass
|
|
+ ( vehicle->brakes.maxPressureMass > 1.0 ?
|
|
0.0 :
|
|
vehicle->Mass )
|
|
+ vehicle->Mred;
|
|
auto const Nmax = ((vehicle->brakes.pressureToForce * vehicle->brakes.maxCylinderPressure[0] -
|
|
vehicle->brakes.cylinders.springForce) *
|
|
vehicle->brakes.cylinders.leverRatio[0] -
|
|
vehicle->brakes.cylinders.slackAdjusterForce) *
|
|
vehicle->brakes.cylinders.count * vehicle->brakes.cylinders.riggingEfficiency;
|
|
state.FmaxPN += Nmax * vehicle->brakes.distributor->GetFC(
|
|
Nmax / (vehicle->NAxles * vehicle->brakes.blocksPerAxle),
|
|
vehicle->brakes.blending.referenceSpeed) *
|
|
1000; // sila hamowania pn
|
|
state.FmaxED += vehicle->lineBreaker.IsClosed() && vehicle->DirActive != 0 && vehicle->inductionMotor.inverterRatio == 1.0 &&
|
|
vehicle->inductionMotor.braking.maxForce * vehicle->NPoweredAxles > 0 ?
|
|
vehicle->inductionMotor.braking.maxForce * 1000 :
|
|
0; // chwilowy max ED -> do rozdzialu sil
|
|
FED -= std::min(vehicle->inductionMotor.state.maxForce, 0.0) *
|
|
1000; // chwilowy max ED -> do rozdzialu sil
|
|
state.FfulED = std::min(vehicle->inductionMotor.state.fullForce, 0.0) *
|
|
1000; // chwilowy max ED -> do rozdzialu sil
|
|
state.FrED -= std::min(vehicle->inductionMotor.state.maxForce, 0.0) *
|
|
1000; // chwilowo realizowane ED -> do pneumatyki
|
|
Frj += std::max(vehicle->inductionMotor.state.maxForce, 0.0) *
|
|
1000;// chwilowo realizowany napęd -> do utrzymującego
|
|
state.masa += vehicle->TotalMass;
|
|
state.osie += vehicle->NAxles;
|
|
}
|
|
}
|
|
|
|
// the most deceleration of the service braking of the consist, given to the driver too
|
|
void physics::ConsistBrakeBlending::ComputeDeceleration(Step &state, Vehicle const &Lead)
|
|
{
|
|
double RapidMult = 1.0;
|
|
if ((Lead.brakes.availableDelays & bdelay_P + bdelay_R) == bdelay_P + bdelay_R
|
|
&& Lead.brakes.delaySetting & bdelay_P)
|
|
RapidMult = Lead.brakes.rapidRatio;
|
|
|
|
state.amax = RapidMult * std::min(state.FmaxPN / state.masamax, Lead.brakes.blending.maxDeceleration);
|
|
|
|
}
|
|
|
|
// the doors open or closed, and from them, the demand and the speed the shunting mode (the holding brake) of the consist
|
|
void physics::ConsistBrakeBlending::UpdateShuntMode(Step &state, Vehicle &Lead)
|
|
{
|
|
state.doorisopen =
|
|
false == Lead.Doors.instances[VehicleSide::left].is_closed
|
|
|| false == Lead.Doors.instances[VehicleSide::right].is_closed
|
|
|| ( Lead.Doors.permit_needed
|
|
&& ( Lead.Doors.instances[ VehicleSide::left ].open_permit
|
|
|| Lead.Doors.instances[ VehicleSide::right ].open_permit ) );
|
|
state.doorisopen &= !(Lead.brakes.spring.releasesParkingWithDoorOpen && Lead.brakes.spring.isActive);
|
|
|
|
if (Lead.Vel < 0.5 && (state.eimic < 0 || state.doorisopen || Lead.brakes.distributor->GetEDBCP()))
|
|
{
|
|
Lead.ShuntMode = true;
|
|
}
|
|
if (Lead.ShuntMode)
|
|
{
|
|
Lead.ShuntModeAllow = false == state.doorisopen &&
|
|
state.LBR < 0.01;
|
|
}
|
|
if( Lead.Vel > 1 && false == state.doorisopen )
|
|
{
|
|
Lead.ShuntMode = false;
|
|
Lead.ShuntModeAllow = Lead.brakes.cylinderPressure > 0.2 &&
|
|
state.LBR < 0.01;
|
|
}
|
|
}
|
|
// the braking force demanded of the whole consist
|
|
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)
|
|
&& 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
|
|
if (Lead.ScndS &&
|
|
Lead.Vel > Lead.inductionMotor.braking.fullSpeed && state.FmaxED > 0)
|
|
{
|
|
state.Fzad = std::min(state.LBR * state.FmaxED, state.FfulED);
|
|
}
|
|
// the holding brake lets go once power has been demanded for its delay (SBDReleaseDelay, none by default)
|
|
auto const holdingbrakereleased { Lead.UpdateStopBrakeRelease( state.eimic, dt1 ) };
|
|
if (Lead.ShuntMode && false == holdingbrakereleased || state.doorisopen /*||
|
|
(Lead.V * Lead.DirAbsolute < -0.2)*/)
|
|
{
|
|
auto const sbd { ( Lead.brakes.spring.isActive && Lead.brakes.spring.releasesParking ? 0.0 : Lead.brakes.holding.deceleration ) };
|
|
state.Fzad = std::max( state.Fzad, sbd * state.masa );
|
|
}
|
|
}
|
|
|
|
// the log of the braking of the consist opened, once it brakes while moving
|
|
void physics::ConsistBrakeBlending::OpenLog(Step const &state, Vehicle const &Lead)
|
|
{
|
|
if (state.Fzad > 1 && !log.is_open() && Lead.Vel > 1)
|
|
{
|
|
log.open(
|
|
"MEDLOGS/" + Lead.Name + "_" + std::to_string( ++logCount ) + ".csv",
|
|
std::ios::in | std::ios::out | std::ios::trunc );
|
|
log << "t\tVel\tMasa\tOsie\tFmaxPN\tFmaxED\tFfulED\tFrED\tFzad\tFzadED\tFzadPN";
|
|
for(int k=1;k<=state.np;k++)
|
|
{
|
|
log << "\tBP" << k;
|
|
}
|
|
log << "\n";
|
|
log.flush();
|
|
logInactiveTime = 0;
|
|
logTime = 0;
|
|
}
|
|
}
|
|
|
|
// the part of the demand the ED brake takes, brought in with a delay, and the rest left to the pneumatic brake
|
|
void physics::ConsistBrakeBlending::ComputeElectrodynamicDemand(Step &state, Vehicle &Lead, double const dt1) const
|
|
{
|
|
state.FzadED = 0.0;
|
|
if( state.LBR > Lead.brakes.blending.minEdDemand
|
|
&& ( Lead.brakes.driverValveType == TBrakeHandle::MHZ_EN57 ?
|
|
(Lead.brakes.operatingMode & bom_MED) != 0 :
|
|
Lead.EpFuse ) ) {
|
|
state.FzadED = std::min( state.Fzad, state.FmaxED );
|
|
}
|
|
/*/ELF - wdrazanie ED po powrocie na utrzymanie hamowania - do usuniecia
|
|
if (Lead.EIMCtrlType == 2 && Lead.MainCtrlPos < 2 && Lead.eimic > -0.999)
|
|
{
|
|
FzadED = std::min(FzadED, lastEdDemand);
|
|
} //*/
|
|
//opoznienie wdrazania ED
|
|
if (state.FzadED > lastEdDemand)
|
|
{
|
|
if (Lead.brakes.blending.edDelayTimer <= 0) {
|
|
Lead.brakes.blending.edDelayTimer += dt1;
|
|
if (Lead.brakes.blending.edDelayTimer > 0) {
|
|
|
|
}
|
|
else {
|
|
state.FzadED = std::min(state.FzadED, lastEdDemand);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
state.FzadED = std::min(state.FzadED, lastEdDemand);
|
|
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)
|
|
&& 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;
|
|
}
|
|
// steps 3-6 of the blending: the ED and the pneumatic braking forces set to the vehicles of the consist
|
|
void physics::ConsistBrakeBlending::DistributeForces(Step &state, Vehicle const &Lead, std::vector<Vehicle *> const &Consist, double const dt1)
|
|
{
|
|
std::vector<bool> PrzekrF( state.np );
|
|
state.nPrzekrF = 0;
|
|
bool test = true;
|
|
std::vector<float> FzED( state.np );
|
|
std::vector<float> FzEP( state.np );
|
|
std::vector<float> FmaxEP( state.np );
|
|
// 3. ustaw pojazdom sile hamowania ED
|
|
// - proporcjonalnie do mozliwosci
|
|
|
|
// 4. ustal potrzebne dohamowanie pneumatyczne
|
|
// - od sily zadanej trzeba odjac realizowana przez ED
|
|
// 5. w razie potrzeby wlacz hamulec utrzymujacy
|
|
// - gdy zahamowany ma ponizej 2 km/h
|
|
// 6. ustaw pojazdom sile hamowania ep
|
|
// - proporcjonalnie do masy, do liczby osi, rowne cisnienia - jak
|
|
// bedzie, tak bedzie dobrze
|
|
float Fpoj = 0; // Lead.CabOccupied < 0
|
|
////ALGORYTM 2 - KAZDEMU PO ROWNO, ale nie wiecej niz eped * masa
|
|
// 1. najpierw daj kazdemu tyle samo
|
|
int i = 0;
|
|
for (auto *vehicle : Consist)
|
|
{
|
|
auto const Nmax = ((vehicle->brakes.pressureToForce * vehicle->brakes.maxCylinderPressure[0] -
|
|
vehicle->brakes.cylinders.springForce) *
|
|
vehicle->brakes.cylinders.leverRatio[0] -
|
|
vehicle->brakes.cylinders.slackAdjusterForce) *
|
|
vehicle->brakes.cylinders.count * vehicle->brakes.cylinders.riggingEfficiency;
|
|
FmaxEP[i] = Nmax *
|
|
vehicle->brakes.distributor->GetFC(
|
|
Nmax / (vehicle->NAxles * vehicle->brakes.blocksPerAxle),
|
|
vehicle->brakes.blending.referenceSpeed) *
|
|
1000; // sila hamowania pn
|
|
|
|
PrzekrF[i] = false;
|
|
FzED[i] = state.FmaxED > 0 ? state.FzadED / state.FmaxED : 0;
|
|
vehicle->AnPos =
|
|
Lead.ScndS ? state.LBR : FzED[i];
|
|
FzEP[ i ] = static_cast<float>( state.FzadPN * vehicle->NAxles ) / static_cast<float>( state.osie );
|
|
++i;
|
|
vehicle->ShuntMode = Lead.ShuntMode;
|
|
vehicle->ShuntModeAllow = Lead.ShuntModeAllow;
|
|
}
|
|
while (test)
|
|
{
|
|
test = false;
|
|
i = 0;
|
|
float przek = 0;
|
|
for (auto *vehicle : Consist)
|
|
{
|
|
if (FzEP[i] > 0.01 &&
|
|
FzEP[i] > vehicle->TotalMass * vehicle->inductionMotor.braking.maxEpDeceleration + std::min(vehicle->inductionMotor.state.maxForce, 0.) * 1000 &&
|
|
!PrzekrF[i])
|
|
{
|
|
float przek1 = -std::min(vehicle->inductionMotor.state.maxForce, 0.) * 1000 +
|
|
FzEP[i] -
|
|
vehicle->TotalMass *
|
|
vehicle->inductionMotor.braking.maxEpDeceleration * 0.999;
|
|
PrzekrF[i] = true;
|
|
test = true;
|
|
state.nPrzekrF++;
|
|
przek1 = std::min(przek1, FzEP[i]);
|
|
FzEP[i] -= przek1;
|
|
if (FzEP[i] < 0)
|
|
FzEP[i] = 0;
|
|
przek += przek1;
|
|
}
|
|
++i;
|
|
}
|
|
i = 0;
|
|
przek = przek / (state.np - state.nPrzekrF);
|
|
for (auto *vehicle : Consist)
|
|
{
|
|
if (!PrzekrF[i])
|
|
{
|
|
FzEP[i] += przek;
|
|
}
|
|
++i;
|
|
}
|
|
}
|
|
i = 0;
|
|
for (auto *vehicle : Consist)
|
|
{
|
|
float Nmax = ((vehicle->brakes.pressureToForce * vehicle->brakes.maxCylinderPressure[0] -
|
|
vehicle->brakes.cylinders.springForce) *
|
|
vehicle->brakes.cylinders.leverRatio[0] -
|
|
vehicle->brakes.cylinders.slackAdjusterForce) *
|
|
vehicle->brakes.cylinders.count * vehicle->brakes.cylinders.riggingEfficiency;
|
|
if (state.FrED > 0.1)
|
|
vehicle->brakes.blending.epCorrectionTimer = 0;
|
|
else
|
|
vehicle->brakes.blending.epCorrectionTimer += dt1;
|
|
bool EPVC = vehicle->brakes.blending.epCorrection && (vehicle->brakes.blending.epCorrectionTime < 0 || vehicle->brakes.blending.epCorrectionTimer < vehicle->brakes.blending.epCorrectionTime);
|
|
float VelC = EPVC ? safe_clamp(vehicle->Vel, vehicle->brakes.blending.minSpeed, vehicle->brakes.blending.maxSpeed) : vehicle->brakes.blending.referenceSpeed;//korekcja EP po prędkości
|
|
float FmaxPoj = Nmax *
|
|
vehicle->brakes.distributor->GetFC(
|
|
Nmax / (vehicle->NAxles * vehicle->brakes.blocksPerAxle), VelC) *
|
|
1000; // sila hamowania pn
|
|
vehicle->brakes.independentPositionEim = FzEP[i] / FmaxPoj;
|
|
if (vehicle->brakes.independentPositionEim>0.009)
|
|
if (vehicle->brakes.pressureToForce * vehicle->brakes.cylinders.leverRatio[0] *
|
|
vehicle->brakes.maxCylinderPressure[0] != 0)
|
|
{
|
|
float x = (vehicle->brakes.cylinders.slackAdjusterForce / vehicle->brakes.cylinders.leverRatio[0] +
|
|
vehicle->brakes.cylinders.springForce) / (vehicle->brakes.pressureToForce *
|
|
vehicle->brakes.maxCylinderPressure[0]);
|
|
vehicle->brakes.independentPositionEim = x + (1 - x) * vehicle->brakes.independentPositionEim;
|
|
}
|
|
else
|
|
vehicle->brakes.independentPositionEim = vehicle->brakes.independentPositionEim;
|
|
else
|
|
vehicle->brakes.independentPositionEim = 0;
|
|
if (vehicle->brakes.independentTraxx)
|
|
{
|
|
vehicle->eim_localbrake = state.eim_lb;
|
|
vehicle->brakes.independentPositionEim = std::max(vehicle->brakes.independentPositionEim, state.eim_lb);
|
|
}
|
|
++i;
|
|
}
|
|
}
|
|
|
|
// the state of the blending kept for the debug screen, and written to the log of the braking while it is open
|
|
void physics::ConsistBrakeBlending::Record(Step const &state, Vehicle const &Lead, std::vector<Vehicle *> const &Consist, double const dt1)
|
|
{
|
|
figures[0] = state.masa*0.001;
|
|
figures[1] = state.amax;
|
|
figures[2] = state.Fzad*0.001;
|
|
figures[3] = state.FmaxPN*0.001;
|
|
figures[4] = state.FmaxED*0.001;
|
|
figures[5] = state.FrED*0.001;
|
|
figures[6] = state.FzadPN*0.001;
|
|
figures[7] = state.nPrzekrF;
|
|
|
|
if (log.is_open())
|
|
{
|
|
log << logTime << "\t" << Lead.Vel << "\t" << state.masa*0.001 << "\t" << state.osie << "\t" << state.FmaxPN*0.001 << "\t" << state.FmaxED*0.001 << "\t"
|
|
<< state.FfulED*0.001 << "\t" << state.FrED*0.001 << "\t" << state.Fzad*0.001 << "\t" << state.FzadED*0.001 << "\t" << state.FzadPN*0.001;
|
|
for (auto *vehicle : Consist)
|
|
{
|
|
log << "\t" << vehicle->brakes.cylinderPressure;
|
|
}
|
|
log << "\n";
|
|
if (floor(logTime + dt1) > floor(logTime))
|
|
{
|
|
log.flush();
|
|
}
|
|
logTime += dt1;
|
|
|
|
if (Lead.Vel < 0.1 || Lead.MainCtrlPowerPos() > 0)
|
|
{
|
|
logInactiveTime += dt1;
|
|
}
|
|
else
|
|
{
|
|
logInactiveTime = 0;
|
|
}
|
|
if (logInactiveTime > 5)
|
|
{
|
|
log.flush();
|
|
log.close();
|
|
}
|
|
|
|
}
|
|
}
|
|
|