vehicle controllers ai logic fixes

This commit is contained in:
tmj-fstate
2019-03-21 01:36:29 +01:00
parent fe6789778f
commit ab16fc17d9
6 changed files with 52 additions and 47 deletions

View File

@@ -2706,9 +2706,17 @@ bool TController::IncBrake()
}
}
}
standalone = standalone && ( mvControlling->EIMCtrlType == 0 );
if( true == standalone ) {
OK = mvOccupied->IncLocalBrakeLevel(
1 + static_cast<int>( std::floor( 0.5 + std::fabs( AccDesired ) ) ) ); // hamowanie lokalnym bo luzem jedzie
if( mvControlling->EIMCtrlType > 0 ) {
OK = IncBrakeEIM();
}
else {
OK = mvOccupied->IncLocalBrakeLevel(
1 + static_cast<int>( std::floor( 0.5 + std::fabs( AccDesired ) ) ) ); // hamowanie lokalnym bo luzem jedzie
}
}
else {
if( mvOccupied->BrakeCtrlPos + 1 == mvOccupied->BrakeCtrlPosNo ) {
@@ -2846,8 +2854,10 @@ bool TController::DecBrake()
mvOccupied->BrakeLevelSet(0.0);
}
}
if (!OK)
OK = mvOccupied->DecLocalBrakeLevel(2);
if( !OK ) {
OK = DecBrakeEIM();
// OK = mvOccupied->DecLocalBrakeLevel(2);
}
if (mvOccupied->PipePress < 3.0)
Need_BrakeRelease = true;
break;
@@ -2936,7 +2946,7 @@ bool TController::IncSpeed()
return false; // to nici z ruszania
}
if (!mvControlling->FuseFlag) //&&mvControlling->StLinFlag) //yBARC
if ((mvControlling->IsMainCtrlZero()) ||
if ((mvControlling->IsMainCtrlNoPowerPos()) ||
(mvControlling->StLinFlag)) // youBy polecił dodać 2012-09-08 v367
// na pozycji 0 przejdzie, a na pozostałych będzie czekać, aż się załączą liniowe (zgaśnie DelayCtrlFlag)
if (Ready || (iDrivigFlags & movePress)) {
@@ -3093,17 +3103,6 @@ void TController::ZeroSpeed( bool const Enforce ) {
}
}
void TController::ZeroMasterController( bool const Enforce ) {
// combined controller may be set to braking, i.e. position lower than neutral
auto const neutralposition { mvControlling->MainCtrlZeroPos() };
while( ( mvControlling->MainCtrlPos < neutralposition )
&& ( DecBrake() ) ) {
;
}
ZeroSpeed( Enforce );
}
bool TController::DecSpeed(bool force)
{ // zmniejszenie prędkości (ale nie hamowanie)
bool OK = false; // domyślnie false, aby wyszło z pętli while

View File

@@ -212,7 +212,6 @@ private:
bool IncSpeed();
bool DecSpeed(bool force = false);
void ZeroSpeed( bool const Enforce = false );
void ZeroMasterController( bool const Enforce = false );
bool IncBrakeEIM();
bool DecBrakeEIM();
bool IncSpeedEIM();

View File

@@ -1592,7 +1592,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
return 0.0; // zerowa długość to brak pojazdu
}
// controller position
MoverParameters->MainCtrlPos = MoverParameters->MainCtrlZeroPos();
MoverParameters->MainCtrlPos = MoverParameters->MainCtrlNoPowerPos();
// ustawienie pozycji hamulca
MoverParameters->LocalBrakePosA = 0.0;
if (driveractive)

View File

@@ -1208,6 +1208,7 @@ public:
int LightsPos = 0;
int ActiveDir = 0; //czy lok. jest wlaczona i w ktorym kierunku:
//względem wybranej kabiny: -1 - do tylu, +1 - do przodu, 0 - wylaczona
int MaxMainCtrlPosNoDirChange { 0 }; // can't change reverser state with master controller set above this position
int CabNo = 0; //numer kabiny, z której jest sterowanie: 1 lub -1; w przeciwnym razie brak sterowania - rozrzad
int DirAbsolute = 0; //zadany kierunek jazdy względem sprzęgów (1=w strone 0,-1=w stronę 1)
int ActiveCab = 0; //numer kabiny, w ktorej jest obsada (zwykle jedna na skład)
@@ -1356,6 +1357,7 @@ public:
int DettachStatus(int ConnectNo);
bool Dettach(int ConnectNo);
bool DirectionForward();
bool DirectionBackward( void );/*! kierunek ruchu*/
void BrakeLevelSet(double b);
bool BrakeLevelAdd(double b);
bool IncBrakeLevel(); // wersja na użytek AI
@@ -1392,9 +1394,9 @@ public:
/*! glowny nastawnik:*/
bool IncMainCtrl(int CtrlSpeed);
bool DecMainCtrl(int CtrlSpeed);
bool IsMainCtrlZero() const;
int MainCtrlZeroPos() const;
int MainCtrlPowerPos() const;
bool IsMainCtrlNoPowerPos() const; // whether the master controller is set to position which won't generate any extra power
int MainCtrlNoPowerPos() const; // highest setting of master controller which won't cause engine to generate extra power
int MainCtrlPowerPos() const; // current setting of master controller, relative to the highest setting not generating extra power
/*! pomocniczy nastawnik:*/
bool IncScndCtrl(int CtrlSpeed);
bool DecScndCtrl(int CtrlSpeed);
@@ -1458,7 +1460,6 @@ public:
double ComputeRotatingWheel(double WForce, double dt, double n) const;
/*--funkcje dla lokomotyw*/
bool DirectionBackward(void);/*! kierunek ruchu*/
bool WaterPumpBreakerSwitch( bool State, range_t const Notify = range_t::consist ); // water pump breaker state toggle
bool WaterPumpSwitch( bool State, range_t const Notify = range_t::consist ); // water pump state toggle
bool WaterPumpSwitchOff( bool State, range_t const Notify = range_t::consist ); // water pump state toggle
@@ -1582,6 +1583,7 @@ private:
bool readLightsList( std::string const &Input );
void BrakeValveDecode( std::string const &s ); //Q 20160719
void BrakeSubsystemDecode(); //Q 20160719
bool EIMDirectionChangeAllow( void );
};
//double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);

View File

@@ -502,7 +502,7 @@ bool TMoverParameters::Dettach(int ConnectNo)
bool TMoverParameters::DirectionForward()
{
if ((MainCtrlPosNo > 0) && (ActiveDir < 1) && (IsMainCtrlZero()))
if ((MainCtrlPosNo > 0) && (ActiveDir < 1) && (MainCtrlPos <= MaxMainCtrlPosNoDirChange) && (EIMDirectionChangeAllow()))
{
++ActiveDir;
DirAbsolute = ActiveDir * CabNo;
@@ -512,7 +512,7 @@ bool TMoverParameters::DirectionForward()
SendCtrlToNext("Direction", ActiveDir, CabNo);
return true;
}
else if ((ActiveDir == 1) && (IsMainCtrlZero()) && (TrainType == dt_EZT) && (EngineType != TEngineType::ElectricInductionMotor))
else if ((ActiveDir == 1) && (IsMainCtrlNoPowerPos()) && (TrainType == dt_EZT) && (EngineType != TEngineType::ElectricInductionMotor))
return MinCurrentSwitch(true); //"wysoki rozruch" EN57
return false;
};
@@ -641,7 +641,7 @@ TMoverParameters::CurrentSwitch(bool const State) {
// for SM42/SP42
if( ( EngineType == TEngineType::DieselElectric )
&& ( true == ShuntModeAllow )
&& ( IsMainCtrlZero() ) ) {
&& ( IsMainCtrlNoPowerPos() ) ) {
ShuntMode = State;
return true;
}
@@ -1904,23 +1904,23 @@ bool TMoverParameters::DecMainCtrl(int CtrlSpeed)
return OK;
}
bool TMoverParameters::IsMainCtrlZero() const {
bool TMoverParameters::IsMainCtrlNoPowerPos() const {
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
return MainCtrlPos == MainCtrlZeroPos();
return MainCtrlPos <= MainCtrlNoPowerPos();
}
int TMoverParameters::MainCtrlZeroPos() const {
int TMoverParameters::MainCtrlNoPowerPos() const {
switch( EIMCtrlType ) {
case 1: { return 4; }
case 2: { return 2; }
case 1: { return 3; }
case 2: { return 3; }
default: { return 0; }
}
}
int TMoverParameters::MainCtrlPowerPos() const {
return MainCtrlPos - MainCtrlZeroPos();
return MainCtrlPos - MainCtrlNoPowerPos();
}
// *************************************************************************************************
@@ -1931,7 +1931,7 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
{
bool OK = false;
if ((IsMainCtrlZero()) && (CabNo != 0) && (TrainType == dt_ET42) && (ScndCtrlPos == 0) && (DynamicBrakeFlag))
if ((IsMainCtrlNoPowerPos()) && (CabNo != 0) && (TrainType == dt_ET42) && (ScndCtrlPos == 0) && (DynamicBrakeFlag))
{
OK = DynamicBrakeSwitch(false);
}
@@ -1992,7 +1992,7 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
{
bool OK = false;
if ((IsMainCtrlZero()) && (CabNo != 0) && (TrainType == dt_ET42) && (ScndCtrlPos == 0) &&
if ((IsMainCtrlNoPowerPos()) && (CabNo != 0) && (TrainType == dt_ET42) && (ScndCtrlPos == 0) &&
!(DynamicBrakeFlag) && (CtrlSpeed == 1))
{
// Ra: AI wywołuje z CtrlSpeed=2 albo gdy ScndCtrlPos>0
@@ -2339,16 +2339,13 @@ bool TMoverParameters::EpFuseSwitch(bool State)
bool TMoverParameters::DirectionBackward(void)
{
bool DB = false;
if ( ( TrainType == dt_EZT )
&& ( EngineType != TEngineType::ElectricInductionMotor )
&& ( ActiveDir == 1 )
&& (IsMainCtrlZero() ) )
if ((ActiveDir == 1) && (MainCtrlPos == 0) && (TrainType == dt_EZT) && (EngineType != TEngineType::ElectricInductionMotor))
if (MinCurrentSwitch(false))
{
DB = true; //
return DB; // exit; TODO: czy dobrze przetlumaczone?
}
if ((MainCtrlPosNo > 0) && (ActiveDir > -1) && (IsMainCtrlZero()))
if ((MainCtrlPosNo > 0) && (ActiveDir > -1) && (MainCtrlPos <= MaxMainCtrlPosNoDirChange) && (EIMDirectionChangeAllow()))
{
if (EngineType == TEngineType::WheelsDriven)
CabNo--;
@@ -2366,6 +2363,13 @@ bool TMoverParameters::DirectionBackward(void)
return DB;
}
bool TMoverParameters::EIMDirectionChangeAllow(void)
{
bool OK = false;
OK = (EngineType != TEngineType::ElectricInductionMotor || ((eimic <= 0) && (eimic_real <= 0) && (Vel < 0.1)));
return OK;
}
// *************************************************************************************************
// Q: 20160710
// załączenie przycisku przeciwpoślizgowego
@@ -2968,7 +2972,7 @@ bool TMoverParameters::DynamicBrakeSwitch(bool Switch)
{
bool DBS;
if ((DynamicBrakeType == dbrake_switch) && (IsMainCtrlZero()))
if ((DynamicBrakeType == dbrake_switch) && (IsMainCtrlNoPowerPos()))
{
DynamicBrakeFlag = Switch;
DBS = true;
@@ -4841,7 +4845,7 @@ double TMoverParameters::TractionForce( double dt ) {
Voltage = 0;
// przekazniki bocznikowania, kazdy inny dla kazdej pozycji
if ((IsMainCtrlZero()) || (ShuntMode) || (false==Mains))
if ((IsMainCtrlNoPowerPos()) || (ShuntMode) || (false==Mains))
ScndCtrlPos = 0;
else {
@@ -5324,7 +5328,7 @@ bool TMoverParameters::FuseFlagCheck(void) const
bool TMoverParameters::FuseOn(void)
{
bool FO = false;
if ((IsMainCtrlZero()) && (ScndCtrlPos == 0) && (TrainType != dt_ET40) &&
if ((IsMainCtrlNoPowerPos()) && (ScndCtrlPos == 0) && (TrainType != dt_ET40) &&
((Mains) || (TrainType != dt_EZT)) && (!TestFlag(EngDmgFlag, 1)))
{ // w ET40 jest blokada nastawnika, ale czy działa dobrze?
SendCtrlToNext("FuseSwitch", 1, CabNo);
@@ -5812,7 +5816,7 @@ bool TMoverParameters::MotorConnectorsCheck() {
( false == Mains )
|| ( true == FuseFlag )
|| ( true == StLinSwitchOff )
|| ( IsMainCtrlZero() )
|| ( IsMainCtrlNoPowerPos() )
|| ( ActiveDir == 0 ) };
if( connectorsoff ) { return false; }
@@ -6070,7 +6074,7 @@ bool TMoverParameters::dizel_AutoGearCheck(void)
{
if (dizel_engagestate > 0)
dizel_EngageSwitch(0);
if ((IsMainCtrlZero()) && (ScndCtrlActualPos > 0))
if ((IsMainCtrlNoPowerPos()) && (ScndCtrlActualPos > 0))
dizel_automaticgearstatus = -1;
}
else
@@ -6357,7 +6361,7 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt)
if ((MainCtrlPowerPos() > 0) && (Mains) && (enrot>dizel_nmin*0.9))
hydro_TC_Fill += hydro_TC_FillRateInc * dt;
//oproznianie przetwornika
if (((IsMainCtrlZero()) && (Vel<3))
if (((IsMainCtrlNoPowerPos()) && (Vel<3))
|| (!Mains)
|| (enrot<dizel_nmin*0.8))
hydro_TC_Fill -= hydro_TC_FillRateDec * dt;
@@ -8523,6 +8527,7 @@ void TMoverParameters::LoadFIZ_Cntrl( std::string const &line ) {
extract_value( MainCtrlPosNo, "MCPN", line, "" );
extract_value( ScndCtrlPosNo, "SCPN", line, "" );
extract_value( ScndInMain, "SCIM", line, "" );
extract_value( MaxMainCtrlPosNoDirChange, "DirChangeMaxPos", line, "" );
std::string autorelay;
extract_value( autorelay, "AutoRelay", line, "" );

View File

@@ -783,7 +783,7 @@ void TTrain::OnCommand_jointcontrollerset( TTrain *Train, command_data const &Co
1.0 - ( Command.param1 * 2 ),
0.0, 1.0 ) );
if( Train->mvControlled->MainCtrlPowerPos() > 0 ) {
Train->set_master_controller( Train->mvControlled->MainCtrlZeroPos() );
Train->set_master_controller( Train->mvControlled->MainCtrlNoPowerPos() );
}
}
}
@@ -839,7 +839,7 @@ void TTrain::OnCommand_mastercontrollerdecrease( TTrain *Train, command_data con
if( Command.action != GLFW_RELEASE ) {
// on press or hold
if( ( Train->ggJointCtrl.SubModel != nullptr )
&& ( Train->mvControlled->IsMainCtrlZero() ) ) {
&& ( Train->mvControlled->IsMainCtrlNoPowerPos() ) ) {
OnCommand_independentbrakeincrease( Train, Command );
}
else {
@@ -859,7 +859,7 @@ void TTrain::OnCommand_mastercontrollerdecreasefast( TTrain *Train, command_data
if( Command.action != GLFW_RELEASE ) {
// on press or hold
if( ( Train->ggJointCtrl.SubModel != nullptr )
&& ( Train->mvControlled->IsMainCtrlZero() ) ) {
&& ( Train->mvControlled->IsMainCtrlNoPowerPos() ) ) {
OnCommand_independentbrakeincreasefast( Train, Command );
}
else {