Coasting distance formula?

I'm making a program in JavaScript to make a model train controllable in the same way that a real one is, so I need to have momentum in there.

Is there a way, if i just let the locomotive coast without any resistance (I know it won't be perfect because of the potential for wind, friction, etc, but work with me here i just need it to be reasonably realistic) that I can create a coasting distance formula?

Basically I'm looking for an equation that will take in speed, weight (as in how much the prototype locomotive weighs, not how much the model train weighs), and percentage of brakes applied, and calculate how far the locomotive will coast before coming to a stop. Is this even remotely possible?

Keep in mind I'm a sophomore in high school, so I haven't taken much math (Geometry 1 is the last math course i took), so pardon me if i asked a dumb question.

Simple equations in motion. This is going to look really long but that's only because I've spread everything out to be nice and clear.

We're going to forget about drag and all that crap and just concentrate on the friction between the train and the rails, and for the sake of ease, and because it's going to be on a railway line anyway, lets stick with one speed value and keep it as a measurement of speed in your train's forward direction. Like a speedometer in a car, except when you go backwards it dips into a negative value.

If you want to apply a braking force to it, you'd need to work out your momentum. In kg/m/s, kilograms per meter per second, by dividing the mass of your train by your speed value.

You're now going to need a braking force value, in newtons (which are equivalent to kg/m/s^2), which you'll subtract from the momentum value every second to get its new momentum value.

You can then take this momentum value, which is in kg/m/s, and multiply it by the mass of the train to get how fast the train is going (in m/s). You can keep doing this until the train reaches a speed of 0 (you don't want your brakes to be sending that train backwards do you?).

EDIT: Drawing this out would probably make a lot more sense and prevent me from making a stupid brainfart (again, haha).

Okay, I get confused when you start talking about measuring the momentum. I don't understand why momentum is measured in kilograms per meter per second...

(this sounds really stupid but work with me here) what does that actually measure? I'm confused by the units (not the kg and meters and seconds, i get that, i just dont get why its kilograms per meter per second and not some kind of measurement of force.

Thank you for your help btw, sorry for my probably stupid questions

What does this mean? Are you talking about a physical model or a computer model? The momentum of a real train can not be equated to a model train by linearly scaling down distances and masses. The momenta will be fundamentally different due to the differences in the internal mechanics.

If I were working on this project. I would do it empirically and get my hands on some data for a real train stopping, and then just add weight to the model train until it performs like the real train. AASHTO or ASCE may have some data on this.

Well, if I throw a 2kg ball at a 1kg ball at a speed of 1m/s is the 1kg ball going to go 1m/s assuming all the momentum is transferred to it? No! It's going to have the same amount of momentum though, 2kg/m/s, and it's 1kg, so 2kg/m/s / 1kg = 2m/s! It's going to go 2m/s!

I'm not physicist so don't quote me on this crap, I could have made mistakes. Easily. I've had a long day. Seems to all be right after consulting a textbook.

No, I mean use software to make a model train appear to behave like a real train. That's why I need an equation, I want to use it in the software.

Sorry for not clarifying this, let me know if you need additional info.

How is it looking so far? When I read what you wanted to do I thought it would be like this, to have the main game loop running, with say a variable called brake set to false. And if that is set to true, reduce the speed over x seconds until it is zero, else continue as normal (brake being false). Because I would do something like that without worrying too much about the physics to begin with, even though that in itself is interesting.

Momentum is the product of mass and velocity. Measuring a force requires an acceleration.

If the tracks+air have a set drag force in Newtons (kg*m/s^-2), you can calculate the stopping duration by dividing by the momentum (kg*ms^-1) by the drag force. Obviously, the drag force of the air changes with velocity, but this would require even more calculation.

Gravity's affect could be calculated using the slope angle of the track, in combination with the average acceleration due to gravity (9.81ms^-2). You could then add this value to the drag force to get the total deceleration/acceleration when the train isn't accelerating (gravity could potentially overpower the drag force at higher angles).

That's similar to what I did before realizing it wasn't right. In a locomotive the brake is variable, so a simple true/false wouldn't work. That's an interesting idea though, I could have it do something like

newSpeed = CurrentSpeed - (some number in percent * BrakePercentage)

Maybe that would be close enough? The trick is that the brake doesn't always do anything. For example if you're going downhill full throttle, putting the brake on 20% isn't going to do anything besides MAYBE decrease your acceleration a bit. Not even noticeably though.

I see what you mean, there's a lot that could be plugged in as a new condition and many variables I can think of. I did not know you were altering the behaviour of the brake that way, i think it would look/feel convincing when it's done.

I just thought of a staggering too, when the brake is applied, so it is not always the same, maybe for an older train, a different class speed obj for each train

So if something's momentum is 1kg/m/s, it's like an object was 1 kilogram moving at 1 meter per second? So then if I had a 10kg ball moving at 5m/s, it's like a 50kg ball moving at 1 m/s?

Sorry just trying to understand this.

I like the way you approach it, and I would love to be able to calculate all this with the track grade in the equation, but unfortunately I have no (no practical) way of measuring that. DCC, the electrical system that allows more than one model locomotive to run on a single electrical block of track, doesn't allow readback from locomotives. The only way I could get track grade would be to place a gyro sensor and a bluetooth something in a transmitter in one of the cars, and that just doesn't seem worth it. So I was just going to assume the track is always exactly flat (it is "just a toy" lol, doesn't have to be ABSOLUTELY perfect, as long as it gives the feeling of driving an actual locomotive)

How would I go about calculating track drag force and air drag force? I assume I could calculate track drag force using the weight of the locomotive and how many wheels it has, but I could be wrong, and I'm completely lost about calculating air drag force (would that even be worth fighting with here?)

I was actually going to allow users of the software to configure settings like this based on their prototype locomotive. For example I'm writing this with a model of an EMD FT-A as a test loco, but if Bob down the street wants to do it with a SD40-2, he'll be able to look up some information on the model (weight, horsepower, any other values i need that get added to this) and configure the program to work best with his engine.

The whole idea of this is that it's modular, one of the things I did to allow that is having all the decoder-specific (each train has a decoder thats basically a tiny computer interpreting commands from a DCC "command station", that's how the locomotives handle things light lights and sound and such) functions in their own file. That file can be switched out, and as long as you have functions that do the same things (or do nothing, if your decoder doesn't support all of it) then the program will still work.

I imagine there will be something about traction motor (the motors in the wheels) torque and probably brake cylinder pressure in the final thing...just dont know how to take all that info in and spit out the info I need lol

Yeah, exactly. Just like @SpaceCat said.

Didn't read your post properly and though you were making a simulator or something lol

You know the mass of the train. Let it go along on a bit of straight track at a constant velocity, preferably the fastest it'll go, or a set amount if you can control it accurately (you'd have to calculate the velocity by putting a couple of markers one metre apart and recording it on video. See how long it takes to go from one marker to the other).

Once you've got an idea of the velocity. Give the train as much track as possible to stop. Take it to that velocity and stop accelerating. Make note of the time it took to stop. You can calculate the deceleration by dividing the velocity by the time it took to stop.

If you want the drag force in Newtons, just multiply the deceleration by the mass of the train.

That's a fantastic idea, and is exactly what I would have done, if it wasn't for the fact that the locomotive trucks are connected to it's electric motor (these are your typical electric trains, they get power from the two nickel silver rails of the track, theyre not battery powered or anything) with worm gears. :P Sorry, another thing I forgot to mention lol

If the locomotive would coast on it's own I would probably just guesstimate, but I can't guesstimate when the ONLY kind of coasting I can do is simulated because of the way the drive works. It's nice because they never slide down hills or anything, but from a prototypical standpoint its horrible. :P

My current (I know this isn't right, I compared it to the way locomotives handle in RailWorks 2015) system is:

var newLocoSpeedNoBrakes = (((ARGnotch/prototypeMaxNotch) * locoMaxSpeed) / 100)
 var newLocoSpeed = newLocoSpeedNoBrakes - (newLocoSpeedNoBrakes * (ARGlocoBrake / 100))

the first line finds the speed in the hypothetical situation that there are no brakes applied, the second one figures out how that changes with the brakes. ARGnotch is the throttle's notch (1-8), and it's divided by prototypeMaxNotch, which is a user configurable variable because some other locomotives have 16 or 22 notches instead of the usual 8. locoMaxSpeed is a configurable setting i put in there so you can get the speed range of it more accurate, because my locomotive's "100% speed" is not really the correct scale speed, it's more on par with breaking the sound barrier lol.

ARGlocoBrake is expressed as a number 0-100, because i use it as a percent.

It SEEMS like it would work, but it's not even remotely close to how RailWorks behaves. If I put the throttle on notch 1 in RailWorks, it doesn't adjust how fast the train ends up going, it adjusts the rate of acceleration mostly. For example notch 1 starts off slow, but after a few minutes I end up going 50mph, and notch 8 starts off MUCH faster and after less time I end up going 50mph. So I assume for notching to be right I'm going to have to have some kind of continuous loop running to constantly recalculate all this, but since JS has no wait function, I don't know how I'm going to do that without crashing the browser with a "black hole" loop.

I'm going to take a guess and say that's happening because, at about 50mph, the drag force of the track is so much lower relative to the force of gravity compared to at, say, 20mph. So the wheels end up spinning on the rails instead of gripping.

Either that or your train's producing enough lift to take off slightly, lol. As I said, just a guess.

You'd have to do some pretty fine tuning to get the wheels to the rotational speed where it starts accelerating again.

...that's actually a really smart observation lol

Now that you mention that I remember reading that the reason trains are so efficient is because they have such small contact area with the track (compared to a rubber tire on a car, the steel wheels of a train have an insanely small contact area for how much mass is being moved)

Hm....I'm trying to think how I can make this all behave realistically...

I took a screen capture of me doing some tests in RailWorks so when that gets done uploading ill put it here for yall to see how the locomotives behave (I assume RailWorks is at least MOSTLY accurate, it better be for the cost lol)

It's hard to model physics on a smaller scale because some things, like air resistance, behave differently and have a lesser relative affect.

The scale in which if you observe you affect the measurement.

1 Like

Don't observe the train's electrons, then. It'll turn into a wave...

I understand that, that's why I want to do it with software so it behaves like a real locomotive would. This is 1:87 scale, but I want it to move like it's full scale (or close to it, again doesn't have to be scientifically perfect) so that it's similar to the way you'd use a real locomotive. I'm not trying to do any expirements or anything with this, for all intents and purposes I want to "upscale" this locomotive's physics (as far as the software is concerned) to full scale. Since the locomotive won't model realistic physics of a real one on it's own, and I want it to behave like I'm driving a real one instead of a 1:87 scale toy on a plywood table, I want to use software to give the illusion of full scale physics.

Basically I don't want to model it on a smaller scale, I want it to be as it is in 1:1 scale, proportionally shrunk down to make the 1:87 scale locomotive seem like it's full scale and us humans are just 87 times larger than life. (Like a reverse "Honey I shrunk the kids")