Elvas Tower: Trying to fix starting friction myself - Elvas Tower

Jump to content

  • 7 Pages +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

Trying to fix starting friction myself Any advice is appreciated here Rate Topic: -----

#21 User is online   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,000
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 18 January 2020 - 10:28 AM

Then I assume you have to modify the clause as I am suggesting.

#22 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 18 January 2020 - 10:33 AM

Quote

Then I assume you have to modify the clause as I am suggesting.


Yes, I just fixed this line. Another 'if' clause is maybe causing the code extention not to work.
if (IsDavisFriction == true) // test to see if OR thinks that Davis Values have been entered in WG file.
            {
                if (DavisAN == 0 || DavisBNSpM == 0 || DavisCNSSpMM == 0 && StandstillFrictionN >= 0 && MergeSpeedMpS >= 0) // If Davis parameters are not defined in WAG file, then set falg to use default friction values
                    IsDavisFriction = false; // set to false - indicating that Davis friction is not used
            }
            if (IsORTSFriction == true) // test to see if OR thinks that Davis Values have been entered in WAG file.
            {
                if (DavisAN > 0 || DavisBNSpM > 0 || DavisCNSSpMM > 0 && StandstillFrictionN > 0 && MergeSpeedMpS > 0) // If Davis parameters are not defined in WAG file, then set falg to use default friction values
                    IsORTSFriction = true;
                else IsORTSFriction = false; // set to false - indicating that Davis friction is not used


#23 User is online   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,000
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 18 January 2020 - 11:32 AM

This is different from your file above. The line
            if (IsORTSFriction == true) // test to see if OR thinks that Davis Values have been entered in WAG file.

is of no use.
Remember also that VS computes first the && and then the ||, so I don't know if your long if clauses do what you desire. I suggest you to use the debugger to check how your changes behave.

#24 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 19 January 2020 - 01:54 AM

I just deleted this particular line...
if (IsDavisFriction == true) // test to see if OR thinks that Davis Values have been entered in WG file.
            {
                if (DavisAN == 0 || DavisBNSpM == 0 || DavisCNSSpMM == 0 && StandstillFrictionN >= 0 && MergeSpeedMpS >= 0) // If Davis parameters are not defined in WAG file, then set falg to use default friction values
                    IsDavisFriction = false; // set to false - indicating that Davis friction is not used
            }
            if (IsORTSFriction == true) // test to see if OR thinks that Davis Values have been entered in WAG file.
            {
                if (DavisAN > 0 || DavisBNSpM > 0 || DavisCNSSpMM > 0 && StandstillFrictionN > 0 && MergeSpeedMpS > 0) // If Davis parameters are not defined in WAG file, then set falg to use default friction values
                    IsORTSFriction = true;
                else IsORTSFriction = false; // set to false - indicating that Davis friction is not used
                    // Davis formulas only apply above merge speed, so different treatment required for low speed
                    if (AbsSpeedMpS > MpS.FromMpH(MergeSpeedMpS))     // if speed above merge speed then turn off low speed calculations
                        IsBelowMergeSpeed = false;
                    if (AbsSpeedMpS == 0.0)
                        IsBelowMergeSpeed = true;

                    if (IsBelowMergeSpeed)
                    {

                        // Dtermine the starting friction factor based upon the type of bearing

                        float StartFrictionLowLoadN = StandstillFrictionN;  // Starting friction

                        // Determine the starting resistance due to wheel bearing temperature
                        // Note reference values in lbf and US tons - converted to metric values as appropriate
                        // At -10 DegC it will be equal to the snowing value, as the temperature increases to 25 DegC, it will move towards the summer value
                        // Assume a linear relationship between the two sets of points above and plot a straight line relationship.
                        const float LowGrad = -0.15f;
                        float LowIntersect = 7.15f * (StandstillFrictionN / DavisAN);
                        float HighIntersect = 18.5f * (StandstillFrictionN / DavisAN);

                        if (WheelBearingTemperatureDegC < -10)
                        {
                            // Set to snowing (frozen value)
                            StartFrictionLowLoadN = N.FromLbf(8f * (StandstillFrictionN / DavisAN));  // Starting friction for a car with standard roller bearings, snowing
                        }
                        else if (WheelBearingTemperatureDegC > 25)
                        {
                            // Set to normal temperature value
                            StartFrictionLowLoadN = N.FromLbf(2.5f * (StandstillFrictionN / DavisAN) * (StandstillFrictionN / DavisAN));  // Starting friction for a 10 ton(US) car with standard roller bearings, not snowing
                        }
                        else
                        {
                            // Set to variable value as bearing heats and cools
                            StartFrictionLowLoadN = N.FromLbf(LowGrad * WheelBearingTemperatureDegC + LowIntersect);
                        }

                        // Determine the running resistance due to wheel bearing temperature
                        float WheelBearingTemperatureResistanceFactor = 0;

                        // Assume the running resistance is impacted by wheel bearing temperature, ie gets higher as tmperature decreasses. This will only impact the A parameter as it is related to
                        // bearing. Assume that resisnce will increase by 30% as temperature drops below 0 DegC.
                        // At -10 DegC it will be equal to the snowing value, as the temperature increases to 25 DegC, it will move towards the summer value
                        // Assume a linear relationship between the two sets of points above and plot a straight line relationship.
                        const float RunGrad = -0.0085714285714286f;
                        const float RunIntersect = 1.2142857142857f;

                        if (WheelBearingTemperatureDegC < -10)
                        {
                            // Set to snowing (frozen value)
                            WheelBearingTemperatureResistanceFactor = 1.3f;
                        }
                        else if (WheelBearingTemperatureDegC > 25)
                        {
                            // Set to normal temperature value
                            WheelBearingTemperatureResistanceFactor = 1.0f;
                        }
                        else
                        {
                            // Set to variable value as bearing heats and cools
                            WheelBearingTemperatureResistanceFactor = RunGrad * WheelBearingTemperatureDegC + RunIntersect;
                        }
                        // If hot box has been initiated, then increase friction on the wagon significantly
                        if (HotBoxActivated && ActivityElapsedDurationS > HotBoxStartTimeS)
                        {
                            WheelBearingTemperatureResistanceFactor = 2.0f;
                            StaticFrictionFactorN *= 2.0f;
                        }
                        // Calculation of resistance @ low speeds
                        // Wind resistance is not included at low speeds, as it does not have a significant enough impact
                        MergeSpeedFrictionN = DavisAN * WheelBearingTemperatureResistanceFactor + MpS.FromMpH(MergeSpeedMpS) * (DavisBNSpM + MpS.FromMpH(MergeSpeedMpS) * DavisCNSSpMM); // Calculate friction @ merge speed
                        Friction0N = StandstillFrictionN * StaticFrictionFactorN; // Static friction is journal or roller bearing friction x weight factor based upon US tons as this matches reference value
                        FrictionLowSpeedN = ((1.0f - (AbsSpeedMpS / MpS.FromMpH(MergeSpeedMpS))) * (Friction0N - MergeSpeedFrictionN)) + MergeSpeedFrictionN; // Calculate friction below merge speed - decreases linearly with speed
                        FrictionForceN = FrictionLowSpeedN; // At low speed use this value
                    }
                    else
                    {
                        // Determine the running resistance due to wheel bearing temperature
                        float WheelBearingTemperatureResistanceFactor = 0;

                        // Assume the running resistance is impacted by wheel bearing temperature, ie gets higher as tmperature decreasses. This will only impact the A parameter as it is related to
                        // bearing. Assume that resisnce will increase by 30% as temperature drops below 0 DegC.
                        // At -10 DegC it will be equal to the snowing value, as the temperature increases to 25 DegC, it will move towards the summer value
                        // Assume a linear relationship between the two sets of points above and plot a straight line relationship.
                        const float RunGrad = -0.0085714285714286f;
                        const float RunIntersect = 1.2142857142857f;

                        if (WheelBearingTemperatureDegC < -10)
                        {
                            // Set to snowing (frozen value)
                            WheelBearingTemperatureResistanceFactor = 1.3f;
                        }
                        else if (WheelBearingTemperatureDegC > 25)
                        {
                            // Set to normal temperature value
                            WheelBearingTemperatureResistanceFactor = 1.0f;
                        }
                        else
                        {
                            // Set to variable value as bearing heats and cools
                            WheelBearingTemperatureResistanceFactor = RunGrad * WheelBearingTemperatureDegC + RunIntersect;

                        }

                        // If hot box has been initiated, then increase friction on the wagon significantly
                        if (HotBoxActivated && ActivityElapsedDurationS > HotBoxStartTimeS)
                        {
                            WheelBearingTemperatureResistanceFactor = 2.0f;
                        }

                        FrictionForceN = DavisAN * WheelBearingTemperatureResistanceFactor + AbsSpeedMpS * (DavisBNSpM + AbsSpeedMpS * DavisCNSSpMM); // for normal speed operation

                        // if this car is a locomotive, but not the lead one then recalculate the resistance with lower value as drag will not be as high on trailing locomotives
                        // Only the drag (C) factor changes if a trailing locomotive, so only running resistance, and not starting resistance needs to be corrected
                        if (WagonType == WagonTypes.Engine && Train.LeadLocomotive != this)
                        {
                            FrictionForceN = DavisAN * WheelBearingTemperatureResistanceFactor + AbsSpeedMpS * (DavisBNSpM + AbsSpeedMpS * (TrailLocoResistanceFactor * DavisCNSSpMM));
                        }

                        // Test to identify whether a tender is attached to the leading engine, if not then the resistance should also be derated as for the locomotive
                        bool IsLeadTender = false;
                        if (WagonType == WagonTypes.Tender)
                        {
                            bool PrevCarLead = false;
                            foreach (var car in Train.Cars)
                            {
                                // If this car is a tender and the previous car is the lead locomotive then set the flag so that resistance will be reduced
                                if (car == this && PrevCarLead)
                                {
                                    IsLeadTender = true;
                                    break;  // If the tender has been identified then break out of the loop, otherwise keep going until whole train is done.
                                }
                                // Identify whether car is a lead locomotive or not. This is kept for when the next iteration (next car) is checked.
                                if (Train.LeadLocomotive == car)
                                {
                                    PrevCarLead = true;
                                }
                                else
                                {
                                    PrevCarLead = false;
                                }

                            }

                            // If tender is coupled to a trailing locomotive then reduce resistance
                            if (!IsLeadTender)
                            {
                                FrictionForceN = DavisAN * WheelBearingTemperatureResistanceFactor + AbsSpeedMpS * (DavisBNSpM + AbsSpeedMpS * (TrailLocoResistanceFactor * DavisCNSSpMM));
                            }

                        }
                    }


The arrangement of || and && symbols seemingly have to be that way as otherwise the doings of the older friction calculation got messed up in some clumsy way (as told cars have no friction at all then).

The problem though is still that the code addition seemingly not getting used. From observing my rebuilt ES44 the standstill frction value is higher than of the units using ORTSBearingType, maybe because ORTS defaults to friction bearings if ORTSBearingType is not found in the wagon section. The code though does mean that if ORTSStandstillFriction and ORTSMergeSpeed both have a value higher than 0 (which basicly means these lines must be present in the wagon section) ORTS should use the added code section. Judging from the beginning of this code snippet I can´t really understnd why ORTS still takes the older calculation although the two new lines are present with the modified engine, which of course lacks ORTSBearingType and as a consequence should not use the older code.

#25 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 20 January 2020 - 09:00 AM

I changed the first few lines over and over again to see if anything could fix this...
if (IsDavisFriction == true) // test to see if OR thinks that Davis Values have been entered in WG file.
            {
                if (DavisAN == 0 || DavisBNSpM == 0 || DavisCNSSpMM == 0 && StandstillFrictionN >= 0 && MergeSpeedMpS >= 0) // If Davis parameters are not defined in WAG file, then set falg to use default friction values
                    IsDavisFriction = false; // set to false - indicating that Davis friction is not used
            }
            if (IsORTSFriction == true) // test to see if OR thinks that Davis Values have been entered in WG file.
            {
                if (DavisAN == 0 || DavisBNSpM == 0 || DavisCNSSpMM == 0 && StandstillFrictionN == 0 && MergeSpeedMpS == 0) // If Davis parameters are not defined in WAG file, then set falg to use default friction values
                    IsORTSFriction = false; // set to false - indicating that Davis friction is not used
            }
            if (IsORTSFriction) // test to see if OR thinks that Davis Values have been entered in WAG file.
            {
                    // Davis formulas only apply above merge speed, so different treatment required for low speed
                    if (AbsSpeedMpS > MpS.FromMpH(MergeSpeedMpS))     // if speed above merge speed then turn off low speed calculations
                        IsBelowMergeSpeed = false;
                    if (AbsSpeedMpS == 0.0)
                        IsBelowMergeSpeed = true;


Honestly I think there is still some influence from ORTSBearingType though this line is NOT used in this part of the code. I´m nearly throwing the towel as obviously nothing can change this for the better. It more and more looks like whether VS or ORTS has a bug regarding how to read the code; I don´t really think this is the case...

As the older parts work with AND without ORTSBearingType, where ORTS just defaults to friction bearings and exactly this is what I get with my modified ES44, not what the engine should have according to this code and the lines in the wagon section.
 ORTSDavis_A ( 2670.353756 )
 ORTSDavis_B ( 18.59957 )
 ORTSDavis_C ( 1.607582 )
 ORTSStandstillFriction ( 2803.871443 )
 ORTSMergeSpeed ( 1.674476 )


As you can read here the value of the third engine is basicly what ORTS calculates with the older code section, guessing it has friction bearings as ORTSBearingType is not present in the wagon section. This value should be below 1000lbf according to the ORTSStandstillFriction value.

#26 User is online   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,000
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 20 January 2020 - 09:12 AM

Use the debugger... select Runactivity in the largest box in the upper part of the VS window, select Properties under Runactivity in the Solution Explorer, select the Debug tab that appears in the vertical list of tabs at the left, and insert in the Command line arguments box, one after the other, the arguments that you find at the top of the OpenRailsLog.txt file, for explore mode e.g.
"-start" "-explorer" "D:\Programmi\Microsoft Games\Train Simulator\ROUTES\USA1\PATHS\aftstrmtrafficplayer.pat" "D:\Programmi\Microsoft Games\Train Simulator\TRAINS\CONSISTS\1 Dash.con" "12:00" "1" "0"

To simplify things use a consist where only the player locomotive is present (obviously in its .eng file you will have added your new wagon parameters), and start debugging, after having positioned breakpoints in the critical points. You can advance code line by code line with F11... but if you have never used a debugger, best you find somewhere an explanation of the basics of debugging with Visual Studio.
If you want to develop code, learning using the debugger is unavoidable IMHO.

#27 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 20 January 2020 - 10:28 AM

Quote

Use the debugger... select Runactivity in the largest box in the upper part of the VS window, select Properties under Runactivity in the Solution Explorer, select the Debug tab that appears in the vertical list of tabs at the left, and insert in the Command line arguments box, one after the other, the arguments that you find at the top of the OpenRailsLog.txt file, for explore mode e.g.

Sorry, but I can´t find OpenRailsLog.txt in any ORTS installment, also not when logging or activity debrief checked on before running the activity.

Inserting the code one by one just leads to strange behaviour as VS can´t find the rest of what is needed to actually run ORTS. Can you explain this to me in images?

#28 User is online   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 7,000
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 20 January 2020 - 11:24 AM

Openrailslog.txt is created on your desktop everytime you run OR. Sorry, but I don't have time to write an image-based guide.
This is how my VS page appears just before starting debug
Attached Image: debug.jpg

#29 User is offline   NickonWheels 

  • Conductor
  • Group: Status: Active Member
  • Posts: 327
  • Joined: 05-December 19
  • Gender:Male
  • Simulator:ORTS
  • Country:

Posted 20 January 2020 - 11:27 AM

Thanks, Carlo

I will try again...

#30 User is online   BillC 

  • Conductor
  • Group: Private - Open Rails Developer
  • Posts: 322
  • Joined: 31-May 11
  • Gender:Male
  • Country:

Posted 20 January 2020 - 12:09 PM

NickonWheels said:

Here is a tutorial[/url]435' post='255027']
Thanks, Carlo

I will try again...


You may find these links helpful
Go to OR Contribute > Developing Code
Select Running the RunActiviity.exe in Debug Mode
In the drop down you will see 6 steps to set up

Here is a tutorial from MS on debugging C# code

This along with Carlo's screen shot above should get you started.

Bill

  • 7 Pages +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users