The online racing simulator
Train simulator
(18 posts, started )
Train simulator
I have begun to make my own train simulator. Actually, I've just been doing a bit of research. I started out writing it in C, but I think I am going to scrap that and program it in Java or C++. I need object oriented programming for this. Because, I realized that locomotives have multiple driven axles. So, it is easier to use object oriented programming. I will have an axle object. Each axle will have it's polar moment of inertia, and coefficent of rolling resistance, and how much weight is on it. Resistive force would be calculated. Then, there would be a locomotive object.
The locomotive object would have axles defined, a motor, the locomotive's mass, and aerodynamic properties. The motor object would have a maximum amount of torque, which would be the output at 0 rad/s, and maximum rad/s, at which the torque would be zero. This torque would be changed by the throttle which I think is a linear relationship, but that calculation could be mucked around with. So, at 50% throttle the torque output would be half of what it would be at full throttle at that given RPM.
All of this would be used to calculate the total pulling force that the locomotive can produce, with all of the aerodynamics and resistance calculated.
The top-level object would basically be a train object. The train object would define the whole train. It would sum all the cars net forces together. Regular train cars might actually use the same object as the locomotive. Only difference would be no motor driving it. Infact, there might be a general train car object, which is a parent of the locomotive object. Each "tick" of the clock would call a tick method, which would notify the train that there was a timestep. So then, the physics for that tick would be calculated.
This post is pretty random, I just needed somewhere to write down my ideas and have people critique them. If there's anything that I left out that is easy to implement, I'm willing to accept suggestions. The sim will have no graphics to start with, and will have no turns either. It will be a little more difficult to calculate the angle of each car, and the fact that there is less forward pulling force.
Quote from wheel4hummer :Each axle will have it's polar moment of inertia

Polar? Are you planning on bending it? I'd have thought it's regular moment of inertia you would wanted.

Anyway, check your PMs, I have something that might give you a big headstart.
Quote from Bob Smith :Polar? Are you planning on bending it? I'd have thought it's regular moment of inertia you would wanted.

I think you may be right. I haven't taken any physics classes, so I just started searching around on google. I used this website: http://www.engineeringtoolbox. ... -power-torque-d_1397.html, which calls it polar moment of inertia, but it seems that the formula is either identical or simmilar enough to the formula for regular moment of inertia that it doesn't seem to make a difference.

So I think that screwed me up. I'm working out some bugs in the code that I made today. I have axles, a train car, and a motor. The train car has axles and a motor. The rolling resistance of the axles is calculated and summed, as is the inertias. Then the torque is calculated using a simple linear formula so that max torque is at zero RPM, and zero torque at the max RPM. The problem I am having right now is that the train will only go 0.7m/s. Either the wheel radius is too big or I messed up the speed calculation.
Realy looking forward for your work !

Look´s promising
Good Luck man and i can't wait to see some pics ingame. Are you going to be making it 3d like Trainz or Rail simulator? If you do make it 3d like those games Good luck and if i knew how to code i would love to help but i no absolutly zilch in coding.
Quote from swisscosmo :Good Luck man and i can't wait to see some pics ingame.

It has no graphics yet. It just does the calculations and spits out the results in the console. Once I do add graphics, they will be really primitive. Most likely a top-down view to start with. If I do manage to make it 3d, It will probably end up being eerily simmilar to BVE, except in Java haha.
I hope it all goes well - Personally, I hate maths... but gotta do it all the time with work. haha! never great!
Quote from wheel4hummer :IThe rolling resistance of the axles is calculated and summed, as is the inertias.

So you're not rotating the wheels individually?

Quote from wheel4hummer :The problem I am having right now is that the train will only go 0.7m/s. Either the wheel radius is too big or I messed up the speed calculation.

There must be a very basic issue here, as your engine torque should give rise to a forward force, and accelerate the train (at least at low speeds) at a constant rate. It shouldn't take many frames (depending on what timestep you are using) to exceed a couple of mph. I find it useful to work it out in Excel and get that right first, before writing the code, and then making sure the figures match.
Quote from Bob Smith :So you're not rotating the wheels individually?

Well, I figured that since I'm not simulating slippage, there was no reason to.


Quote from Bob Smith :There must be a very basic issue here, as your engine torque should give rise to a forward force, and accelerate the train (at least at low speeds) at a constant rate. It shouldn't take many frames (depending on what timestep you are using) to exceed a couple of mph. I find it useful to work it out in Excel and get that right first, before writing the code, and then making sure the figures match.

I took a look at the code i wrote a little while ago, and I am a little confused by my own code. I think I will try using Excel, like you are suggesting. And I may try learning C++ instead of using Java, because there are many different graphics engines that can be used with C++, like ogre.

EDIT: The problem is that I am having difficulty calculating the forward force that propels the train. I'm confused on how to calculate output torque from the angular torque and the inertia. The way my code worked is that the acceleration was calculated by subtracting the resistive torque from the rolling resistance from the torque of the motor. And then to find angular acceleration I divided the torque by the moment of inertia. Then I converted from angular acceleration to regular acceleration. It's really hard to explain, and I think it's wrong.
Quote from wheel4hummer :Well, I figured that since I'm not simulating slippage, there was no reason to.

I suspect the slip ratio for a metal wheel is very small compared a rubber tyres, so that can likely be ignored. Since they can be considered to not deform, there is not that issue either. What about taking bends though? The outer wheel must take a longer path, and I'm not familiar enough about trains to know whether they have a differential or force the wheels to slip.

Quote from wheel4hummer :EDIT: The problem is that I am having difficulty calculating the forward force that propels the train. I'm confused on how to calculate output torque from the angular torque and the inertia. The way my code worked is that the acceleration was calculated by subtracting the resistive torque from the rolling resistance from the torque of the motor. And then to find angular acceleration I divided the torque by the moment of inertia. Then I converted from angular acceleration to regular acceleration. It's really hard to explain, and I think it's wrong.

Yeah, that doesn't sound right.

If you were to model wheel slip, you would apply the wheel's share of the engine torque minus the resistance torque (the sum of the wheel's rolling resistance and it's longitudinal force) to the wheel inertia, creating an angular acceleration of that wheel, update the angular velocity, which would update your slip ratio, which you would then convert to a longitudinal force using whatever a metal-metal slip curve looks like and the vertical load on the wheel. This would be done per driven wheel and these forces could be summed to accelerate the mass of the vehicle.

Without modelling wheel slip, things are much simpler. You can convert the engine torque to a force using the wheel diameter, subtract from this the rolling resistance, and accelerate the total translational inertia of the train. This figure is the mass plus the rotational (moment of) inertia of the wheels divided by their radius squared. Don't forget to include engine inertia too (and the effects gearing, if your train has any).
i think with trains, but cannot be 100 percent, the wheel just slip to take curves, in the siutaion a diff would be more trouble than its worth and isnt really needed


edit:sorta double post bob :P

edit 2: lol fixed it
Quote from james12s :i think with trains, but cannot be 100 percent, the wheel just slip to take curves

That's correct, the motor just drives the whole axle which is solid straight across. The wheels just slip. That's why corners of train tracks have huge radii.
Quote from Bob Smith :Without modelling wheel slip, things are much simpler. You can convert the engine torque to a force using the wheel diameter, subtract from this the rolling resistance, and accelerate the total translational inertia of the train. This figure is the mass plus the rotational (moment of) inertia of the wheels divided by their radius squared. Don't forget to include engine inertia too (and the effects gearing, if your train has any).

Wow, I really over complicate things. I will try using those calculations instead. Thanks.
...If I only could understand a 1000th of what you're talking about...
Good luck with your project !
Totally agree with Ripley, sometimes all those numbers, theories and formulas makes me forget that behind them, theres a train sim awaiting


Good luck with the project, train lover here :ok
I think I may give up on the physics for a bit, and try learning how to program 3d graphics. I already am decent at programming physics. But my knowledge of programming 3d graphics programs is non-existent.
#16 - Vain
For basic/generic 3d programming I found the Irrlicht engine to be very helpful. It's a snap to load simple map data and make it interact with physics routines. For future projects you can also add TrueAxis to your browser bookmarks. Create an object, give it graphics properties using Irrlicht and connect it to a physics object in TrueAxis. Manipulate the TrueAxis object using forces and in a different thread make the Irrlicht object draw itself. That's all you have to do and you can already start implementing the gamedesign.

The Irrlicht project also has an xml engine IrrXML that makes loading config files easy as "int bitdepth = xml_load(pointerToFile, "bitdepth");" and a basic sound engine IrrKlang.

That said, for your programming experience it is useful to do the gfx implementation the hard way once and actually come up with your own ways of drawing real time shadows using stencil buffering instead of telling an engine "IrrlichtGraphicsObject.drawShadow();".

The above structure of "Irrlicht for the graphics, TrueAxis for the physics, SDL_net for networking, IrrXML for loading data, IrrKlang for sounds, etc. ..." will force you to structure your objects very well. You will only look at the code that represents your game design. You will never mix different tasks like game design and sound calls in one c++ object. That makes code look very nice and easy to maintain/restructure. If done well you can exchange the complete graphics engine merely by editing the constructor of your most basic entity-object.

Vain
Quote from Vain :For basic/generic 3d programming I found the Irrlicht engine to be very helpful.

I'll second that, Irrlicht is fantastic.

Quote :That said, for your programming experience it is useful to do the gfx implementation the hard way once and actually come up with your own ways of drawing real time shadows using stencil buffering instead of telling an engine "IrrlichtGraphicsObject.drawShadow();".

Agreed
Railroad wheels have a variable diameters and solid (non differential) axles and not the FLAT surface like a tire against a road. The area nearest a wheel flange is larger diameter, so in the case of a curve where the flange engages to keep the wheel surface on the track, the wheel on the other side of the axle is smaller diameter.

This = less need for slipping of any kind.

Large Radius curves are not necessarily due to the wheel physics. It has to do with a) Car length (distance between Axle sets) b) engaging the wheel flanges, which increases drag forces and a host of other reasons. Logging Railroads with short cars and engines can maneuver through extremely sharp curves that a passenger coach would have problems with... not even taking into account the body overhang from a long car that would cause the car to extend beyond legal track clearances.

I'm no expert... but I know a few things about trains. http://www.railsimstuff.com

Train simulator
(18 posts, started )
FGED GREDG RDFGDR GSFDG