[ODE] Train on a track

Started by
5 comments, last by Patrick Polzin 14 years, 5 months ago
I'm trying to implement train track physics using ODE. I'm describing the track as a parameterized curve (a+bx, for example) where x goes from 0 through 1 and you can get a reference frame (orientation + position) for every x. I don't think triangulating the tracks and then adding them as trimesh geoms would work any good, would it? My criteria: * Constraints caused by the track should be like in the real world; a car can be lifted away from the tracks but can't move sideways or down into the ground * Cars can speed up and slow down when going down/up hills, or when pushed by another object. ie, react to forces * If the car strays too much from the track in the "up" direction, the car should be able to derail * Numerical stable, I want to connect multiple cars together and pull them along using a ball joint, which also makes it important for a car to be affected by forces projected onto the track I'm thinking I should implement the whole track as a joint, a joint that can somehow break or get automatically created if a car is in proper position on a rail. What I'm trying now is to move a rigid box geom along the parameterized curve which will then pull the train car sitting on top using joints, but it will cause many problems. I'm thankful for any ideas!
Advertisement
While not actually useful for your situation,
">this is an interesting watch.
What if you made a U shape on the bottom of the train from 3 boxes that fit onto a long box track or long series of boxes for curves, both would have zero friction and the track boxes would not produce collisions from contact with anything but the train bottom to hide this simplification.
Quote:Original post by Ezbez
While not actually useful for your situation,
">this is an interesting watch.

Holy cow, just blew my mind. I really wish he would have dropped a couple more f bombs though. Nothing could make his story any better except excessive profanity.

'I mean those wheels are just connected by a big 'ol mother f'er. I mean a real solid son of a bitch.'

Anyways. I would solve your problem by using some modified point/spline constraints. The modification being that they don't control the a velocity up and off the track. You could make the modification by clipping the output impulse and position correction by a plane whose normal is the rail's up direction.

I'm not sure what the standard way to do a point/spline constraint would be. I'm sure there are a few active topics on just the subject. But basically you have a target. Each frame you try to keep the output on the target by keeping their derivatives the same. You then apply any addition required position correction as a fail safe.

In other words. If the train is placed on to the track at the start and the contact points have the same position derivative as the track, the contact points will remain on the track for all T values. T being the input to the spline interpolation function. You can find the target T value by finding the closet point on the spline's T value and then take into account the appropriate T or positional velocity.

So basically each frame you modify the contact point's (the point where the wheels meet the rail) velocity to be that of the rails derivative at T. You do so by applying an impulse at the contact point.

Eventually it's going to drift off due to discreet integration and numerical accuracy issues. So each frame you should also re correct the position of the contact points to actually coincide with the track. This position fudge stage will invalidate other parts of the train slightly, but if updated at a high enough rate, will come to a steady state error which is unnoticeable.

Don't forget to clip the velocity and position corrections by the up plane. That way the train can ramp off the track if it goes 100mph over a steep hill crest. If you simulate each side of the track, the train will also be able to tip off the track since either side will not be restrained from moving up and away. If the point leaves the track though you'll need to stop constraining it or there will be no valid solution as the train would make an arc in its roll.

If you don't simulate both rails, you'll need to constrain the roll of the train to match the track through a similar constraint.

Because each contact point is rigidly attached to the train car, any impulse or position adjustment would actually happen to the train car itself (the rigid body). You can see why this would only be stable at very small dt.

These constraints are based on Lagrange multipliers i believe. But i could be making that up.

While also not useful for your project, this video is epic (mute sound first):
">


This thread is about as close to the topic as it gets: http://www.gamedev.net/community/forums/topic.asp?topic_id=551763

[Edited by - bzroom on November 1, 2009 8:55:25 PM]
Quote:Original post by bzroom
Quote:Original post by Ezbez
While not actually useful for your situation,
">this is an interesting watch.

Holy cow, just blew my mind. I really wish he would have dropped a couple more f bombs though. Nothing could make his story any better except excessive profanity.

'I mean those wheels are just connected by a big 'ol mother f'er. I mean a real solid son of a bitch.'

Anyways. I would solve your problem by using some modified point/spline constraints. The modification being that they don't control the a velocity up and off the track. You could make the modification by clipping the output impulse and position correction by a plane whose normal is the rail's up direction.

I'm not sure what the standard way to do a point/spline constraint would be. I'm sure there are a few active topics on just the subject. But basically you have a target. Each frame you try to keep the output on the target by keeping their derivatives the same. You then apply any addition required position correction as a fail safe.

In other words. If the train is placed on to the track at the start and the contact points have the same position derivative as the track, the contact points will remain on the track for all T values. T being the input to the spline interpolation function. You can find the target T value by finding the closet point on the spline's T value and then take into account the appropriate T or positional velocity.

So basically each frame you modify the contact point's (the point where the wheels meet the rail) velocity to be that of the rails derivative at T. You do so by applying an impulse at the contact point.

Eventually it's going to drift off due to discreet integration and numerical accuracy issues. So each frame you should also re correct the position of the contact points to actually coincide with the track. This position fudge stage will invalidate other parts of the train slightly, but if updated at a high enough rate, will come to a steady state error which is unnoticeable.

Don't forget to clip the velocity and position corrections by the up plane. That way the train can ramp off the track if it goes 100mph over a steep hill crest. If you simulate each side of the track, the train will also be able to tip off the track since either side will not be restrained from moving up and away. If the point leaves the track though you'll need to stop constraining it or there will be no valid solution as the train would make an arc in its roll.

If you don't simulate both rails, you'll need to constrain the roll of the train to match the track through a similar constraint.

Because each contact point is rigidly attached to the train car, any impulse or position adjustment would actually happen to the train car itself (the rigid body). You can see why this would only be stable at very small dt.

These constraints are based on Lagrange multipliers i believe. But i could be making that up.

While also not useful for your project, this video is epic (mute sound first):
">


This thread is about as close to the topic as it gets: http://www.gamedev.net/community/forums/topic.asp?topic_id=551763

Thanks, I'm not sure I understood everything nor how I'm going to implement that using ODE, but I will have to put it on hold until I get some more free time. I should also learn how to do custom joints and stuff like that.

One question though; if I use two rails aren't there going to be a lot of instability? I mean, the train car would have to be constrained to both tracks, which would result in opposite forces.
I'll try to implement this soon as an example. I just dont have a physics system in my library so i've been putting off any physics demos.

One thing i realied, after reading that other thread. My methods for constraining bodies have always been the so called penalty constraints. Which means they work, and they're cheap, but they're far from accurate. They disapate energy by constantly doing work against the body.

Oh well, it might matter for a rollercoaster simulation for a real life rollercoaster. But for a train game, quick n dirty is probably the way to go.
Hi,

do you mean direct train simulation? There are existing none good SDKs to solve it.

Using "normal" physics functions like collision testing will give very hard numeric errors and not "the" simulation.

For trains especially there are existing different formulars dependend on acceleration or how the driver drives (gears, brake ect.). For only drive physics you have to solve the following equation (abstract and simplyfied):

F_result = F_acc - F_roll - F_air - F_gr - F_train - F_switch - F_track

F_acc = force of acceleration (advanced: eg. motor gears, steam pressure)
F_roll = force of rolling (advanced: eg. major while speed is small)
F_air = force of air (0.5 * µ * p * v^2 * A)
F_gr = sin(a) * m * g

Simplified and abstracted equations to simulate train forces:
F_train = (F_a%)*v^2 + (F_b%)*v + F_c (F = Cubic + Linear + Constant)
F_switch = W%. * v * m * g (mostly small, W%. in promille)
F_track = (Ta%. * v * m * g) + Tb% * lg(d * v^2) + Tc% * exp(-ev)
(F = Linear + logarithmic (small increasing in high speeds) + exponential part (high in slow speed, near 0 in high speed))

I hope this was the entrance to get involved with trains. But beware: They are not so easy as they will look. This topic is filling many books and if you are able to understand german you will find in Amazon some good books about this topic (but with many physics and formulas).

I hope my english is good enough to understand what is meant, because I'm not very good in it ;).

3D BYTE | WEBSITE | FACEBOOK | TECH BLOG

This topic is closed to new replies.

Advertisement