Acceleration calculations...

Got a problem with OpenTTD? Find some help here.

Moderator: OpenTTD Developers

Post Reply
Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Acceleration calculations...

Post by Cadde »

I am having some problems figuring out the math for train acceleration.

I have a train that will weigh at most 1,457 tonnes. (loaded)

Using the calculations from the Wiki in regards to Tractive Effort (HERE) i can deduct that i need...

35 * 1,457 = 50,995 = 51 kN of TE to get it moving.

My train has 316 kN MAX. TE so it does move, kinda slowly.

The trains maximum speed is 201 km/h (56 m/s) so i can deduct that i need...

51 * 56 = 2,847 kW of power to get it to max speed.

My train has 10,119 hp (7,443 kW) of power. More than enough to reach the max speed, which it does... In 123 tiles after having passed one down slope and one up slope. (10% grade)
It has 21 wagons and one engine.

To re-iterate:

Consist weight: 1,457 tonnes
Power: 10,119 hp (7,443 kW)
Max TE: 316 kN
Max Speed: 201 km/h
Total parts (wagons and engine): 1+21 = 22 (Matters in air resistance calculations.)

I have first tried the math for acceleration from THIS wiki page. But i realized it is either very old or i just can't put it to good use since i fail at doing the math. (And i backtraced the source to a topic from 2008-ish.)
I then downloaded the source and went through the calculations in there. I kinda managed to get some reasonable numbers out of it in an excel sheet but the speed values increased way too fast so i still failed.

My question therefore is... Is there an upgraded formula or could someone be so kind as to come up with one that is easy to use? I doesn't have to be 100% accurate, the purpose for it is for me to determine what the gains will be if i add another locomotive to the train.

Oh, and before you go nuts about me running a heavy freight train at 201 km/h (124 mph, almost the same as an HST) which isn't "realistically" possible.... I am running a 2cc nightly and it doesn't have wagon speed limits for freight cars. Only passenger cars. Either way, i am happy i can go fast... I know it's not "cool".

Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 592
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: Acceleration calculations...

Post by Michi_cc »

Cadde wrote:I have first tried the math for acceleration from THIS wiki page. But i realized it is either very old or i just can't put it to good use since i fail at doing the math. (And i backtraced the source to a topic from 2008-ish.)
I then downloaded the source and went through the calculations in there. I kinda managed to get some reasonable numbers out of it in an excel sheet but the speed values increased way too fast so i still failed.
The wiki page looks outdated, so somebody™ would need to extract the new formulas from the source. One very important thing to note for trains is that the output of the acceleration calculation is applied twice per movement step, different from the other vehicle types.

-- Michael Lutz

Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: Acceleration calculations...

Post by Cadde »

Well, i wish i was that somebody™ that could understand™ how it worked so i could update the calculations. But i don't understand it...
My main concern is that i have somehow messed up a unit.

So to get started, a list of all the units would be great. Like...

Mass = consist weight in tonnes
Power = consist hp (imperial or metric?) converted to kW.
etc etc...

Right now i am getting a return value (acceleration) of 47.97 in my calculations.
But i am wondering, is that an internal measurement? Maybe the variable it acts on isn't the value displayed to the user?


EDIT:

Wait, i think i get it now. v->subspeed is a fractional (brain not working) which basically means 1/256th of a km right?
And when you assign a value to subspeed (that is a byte) and the value is > 256 it just assigns the rightmost 8 bits right?
So for instance, if subspeed was 250 and accel is 21 then subspeed will become 10?

Never mind, i think i got it. I just need to finish it off :D (And no wonder i thought dividing the acceleration by 100 felt more right...)

Yes, i am stupid.

Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: Acceleration calculations...

Post by Cadde »

Still can't get it to work.

I am working under the assumption that DoUpdateSpeed() is called every tick (And i even considered that it is indeed called twice) but that doesn't help me...
I measured the number of days it took for the above train to reach 201 km/h and it takes 11 days. To my knowledge a day is 74 ticks which means my calculations should leave me with 201 km/h at 814 ticks.
But my calculations fall short and reach 201 km/h at 319 ticks.

I might have missed some major magic number or constant somewhere but i have tried messing with most values and whenever i do the calculations say i can't reach 201 km/h which i clearly can.

Hoping someone could take a look and see what's wrong, attaching the .xls document here.
Attachments
Acceleration.xls
My wrong calculations...
(682.5 KiB) Downloaded 146 times

Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 592
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: Acceleration calculations...

Post by Michi_cc »

You didn't write which actual vehicles you used, so I made a guess from the stats, which came out as a DB 103 + 21 fully loaded 2nd gen flatbed wagons. If that is indeed matching, I don't know how you arrived at 11 days for full acceleration, because my test train took more like 22 days for that.

With one major change and some minor changes I was able to replicate my test with your spreadsheet.
  • Use INT() instead of ROUND() for the proper C++ rounding behaviour (HUGE difference).
  • Power is stored in imperial and not metric HP internally, so power should be 9980 HP. Internal speed is also not exactly km/h, but mph/1.6, so top speed is actually 200 km/h-ish.
  • The 2CC set defines the air drag property as 32 and not 0 for all vehicles (which is incidentally why some 2cc vehicles don't reach top speed any more after the not-so-recent acceleration changes).
  • Wagon count for air drag includes the engine, so 22 and not 21.
  • You can use MOD() for the subspeed, makes it more readable.
  • For acceleration purposes, a day has indeed 2*74 ticks for a train.
With those changes, the calculated speed reaches 200 shortly after 3100 steps, which is around 21 days and thus identical to my own observation.

-- Michael Lutz

Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: Acceleration calculations...

Post by Cadde »

Michi_cc wrote:You didn't write which actual vehicles you used, so I made a guess from the stats, which came out as a DB 103 + 21 fully loaded 2nd gen flatbed wagons. If that is indeed matching, I don't know how you arrived at 11 days for full acceleration, because my test train took more like 22 days for that.
Damn, sorry about that. I should have done that. I was so dug into the math part that i forgot to just mention how to replicate the result. I myself don't remember how reached that 11 minute result. I spent the whole night trying to get it right because i got that deeply involved with it. Indeed my train took more like 22-23 days to reach top speed. But in my fiddling with the code and calculations i got tired and eventually went to bed not having the energy to make a post about the progress.

EDIT: oh...

I used: DB 103 + 21 wagons of mixed cargo (was running a game at the time) 4 hauling petrol (empty), 3 hauling engineering supplies (empty) and 14 hauling oil (full). All wagons where third generation ones.
But it doesn't matter what engine or how many wagons one uses. What matters is getting the math right for whatever train is used. I later saved that game and made a test scenario testing various combinations of engines and wagons.
Still didn't get it right when i finally hit the sack at ~11am (sigh)
Michi_cc wrote:With one major change and some minor changes I was able to replicate my test with your spreadsheet.
  • Use INT() instead of ROUND() for the proper C++ rounding behaviour (HUGE difference).
  • Power is stored in imperial and not metric HP internally, so power should be 9980 HP. Internal speed is also not exactly km/h, but mph/1.6, so top speed is actually 200 km/h-ish.
  • The 2CC set defines the air drag property as 32 and not 0 for all vehicles (which is incidentally why some 2cc vehicles don't reach top speed any more after the not-so-recent acceleration changes).
  • Wagon count for air drag includes the engine, so 22 and not 21.
  • You can use MOD() for the subspeed, makes it more readable.
  • For acceleration purposes, a day has indeed 2*74 ticks for a train.
With those changes, the calculated speed reaches 200 shortly after 3100 steps, which is around 21 days and thus identical to my own observation.

-- Michael Lutz
  • Thank you for the heads up. I knew there was some kind of rounding error but i forgot there was an INT function in excel.
  • Already found this out after having dug deeper into code (where unit conversions are made, where you tell us what's the original values, but got additionally confused because there the imperical miles per hour is defined as a standard unit but km/h-ish is indeed used for trains.)
  • I looked at the nfo's for 2cc for this very reason because i was only ever able to get a matching result in my latest spreadsheet by altering air resistance... Albeit not to 32 for obvious reasons. But i found no mention in the nfo's for any action0trains property 0x20 used anywhere. No vehicles have it set either explicitly or via the previously used AIR_DRAG defined constant.
    Adding to that, i believe THIS post still holds true but obviously i am going to keep the number 32 in mind.
  • Already found this bug and fixed it in my own sheet.
  • "You can use MOD() for the subspeed, makes it more readable." - And more accurate, already done so after realizing we are working with INT and not FLOAT or DOUBLE.
  • "For acceleration purposes, a day has indeed 2*74 ticks for a train." - In my latest spreadsheet I'm NOT calculating it like that and i get close results after having made the major changes i mentioned above. Will try your changes and see what the result is but changing it to run twice per tick left me with wayy off values in the past. Yet, reading the source i too came to the conclusion that it is indeed run twice per tick.
Either way, i am forever grateful for the assist. Now to find a formula that can work out the speed at Tick/Day X without having to iterate through it like i do now.
As with everything, the time i spent reading through the code gave me a slightly better understanding of how things work. It also left me with a few ideas of patches i can make... Not about acceleration but other things. We'll see how it goes.

Thanks again, you have been really helpful.

Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: Acceleration calculations...

Post by Cadde »

I have updated my spreadsheet and it is (as far as i can tell) 100% accurate now.
I also took the liberty of making it "User friendly" so others can benefit from it.

My last question then is... Should i add it to the OpenTTD Wiki page?

Anyways, attached it here. (Had to .rar it because it is > 6 MB. Reason for that is the 7400 calculations it does. 2 for each tick giving you a graph over 50 days. Which makes the .xls file LARGE...)

Thanks all who helped! (even those who tried/wanted to)
Attachments
Acceleration.rar
(715.12 KiB) Downloaded 680 times

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9358
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Acceleration calculations...

Post by planetmaker »

Cadde wrote: My last question then is... Should i add it to the OpenTTD Wiki page?
As the file is already here, it might make (more) sense to just link the download here?

Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: Acceleration calculations...

Post by Cadde »

planetmaker wrote:
Cadde wrote: My last question then is... Should i add it to the OpenTTD Wiki page?
As the file is already here, it might make (more) sense to just link the download here?
Thought of that as well, will do that then. I take it everything seems to be in order in the spreadsheet?

Post Reply

Return to “OpenTTD Problems”

Who is online

Users browsing this forum: No registered users and 6 guests