[ODE] Driving boxes on the arc or curve.
tsorrells at breakawayltd.com
Thu Oct 12 15:40:15 MST 2006
I guess I'll take a stab at answering this, although I'm not an expert at ODE. That may not matter since it sounds like you're asking more "how do I make physics work?" instead of "how do I make ODE work?"
It sounds like you want cars to follow a Bezier curve and to accelerate based on their distance from the car in front of them. You've simplified the problem tremendously by treating the car as a box and not doing any detailed car physics.
If you want your cars to simply be floating boxes, you can just turn off gravity, by setting it to (0,0,0), which I believe it defaults to. You could also reset the position of the car every frame to its current x and y, but the constant z to get it to hover off the ground. But this won't be necessary unless you have forces acting on the z axis.
You want your cars to have some known mass, so you can use ODE's density functions, or simply assign a mass value directly, say 2000 lbs per car.
Your acceleration force should be based on the car's known mass and the distance to the car in front of it. I believe ODE has a ray collision object that can be used to trace from the current car directly in front of it to find how far the next car is away from it. From that you'll need to calculate whether you want to speed up, stay the same speed, or slow down and then determine your acceleration from that. If your cars hover off the ground, there will be no friction, so you wouldn't want to always apply a force from the wheels like in a real car. Instead you probably want to apply some constant force in the case that you want the car to speed up, stop applying the force when it's going fast enough, and apply a force in the opposite direction when you need to slow down. How fast you want your cars to speed up or slow down is something you'll likely want to tweak so it looks good, as long as it doesn't need to represent real world values. But if did, you'd have to start taking into account the variety of cars on the road and differences in acceleration and mass between say a Dodge Viper and a school bus.
If you want your cars to turn along a spline of some sort it's certainly easiest to just set their orientation according to the values given by the spline. In other words you don't have to use torque, just set the orientation of the car to what you want as you go along the spline. Once a car has impacted with another car or has entered any sort of out-of-control scenario, you would need to stop manipulating its orientation directly and let it be controlled by collision response or AI behavior. So you'd want to keep track of whether the car had hit something or not and use that to determine if it should continue along its spline or not.
Of course you could also find some real equation for determining the torque to apply to turn an object of known mass a known angle. Keep in mind there's no friction unless you add it in yourself or have wheels touching the ground. So if you add torque to turn you will have to add counter-torque to stop turning. But I imagine that's more complicated than your traffic model needs to be.
Good luck getting 8000-16000 vehicles working smoothly without a super computer, I find having around 50 colliders in a world uses around 10% of my CPU time. You'll see much better speeds if you don't care for them to crash and simply want them to drive around.
Anyway that's my simple answer, but there are a fair number of experienced car simulators in the mailing list so someone may be able to provide better advice for you or actual equations.
From: ode-bounces at q12.org [mailto:ode-bounces at q12.org] On Behalf Of Seweryn Habdank-Wojewódzki
Sent: Thursday, October 12, 2006 5:44 AM
To: ode-list mailing_list
Subject: [ODE] Driving boxes on the arc or curve.
I want to join ODE library as a base for my open source simulator of the
road traffic. I have some models, how drivers are generally
driving, and there are some problems to fit them with ODE. This rather not a
problem with ODE, but with models. So I am asking form small help. I want to
understand ho can I fit models to ODE.
Models are working on the assumption that not acceleration is important, but
velocity. However I have calculated acceleration as a function dependent of
the velocity and bumper-to-bumper distance. What is my problem? I do not
really know what is optimal to set in to ODE world.
If I know absolute with sign value of the acceleration (from model) I know the
absolute with sign value of the force which has to be set. So the way is to
take force vector from ODE world, then calculate singular vector of it and
multiply by the absolute force. Then I will set the needed force vector, in
the direction of the movement.
The problem is when I want to turn right or left the modelled
car. I do not know what I should use? Let say that I know linear acceleration
or force at the begin of the movement, calculated like before. Then I could
calculate relative Torque (or Torque) as M = F x r, where x is cross product,
r is known radius, F is known force. At the next step I need to take the
linear velocity from the car, to calculate next value of the acceleration.
Interesting thing is further, when I try to use curvature radius, which
changes from point to point if the movement is _not_ on the circle but on the
curve e.g. Bezier curve parametrised by the length recalculated to the real
value (0,1). I have some formulas for such a curvature radius, but I do not
really know how to make an optimal code for that using ODE. Especially it is
important that I have no other physical elements in the world like in
Can anyone tell me how can I better organize such a calculations? Maybe
something I missed, probably something I complicate too much.
Important for me is to create very abstract vehicle, without wheels, just
floating box, but this box have to have a mass, and I need to set the
acceleration or force to it from outside. The simplification is done because
I need to simulate about 8000-16000 vehicles. I the future I want to let them
influence each other like in demo test_crash. So this is the reason tha I
choose the ODE library.
|\/\/| Seweryn Habdank-Wojewódzki
ODE mailing list
ODE at q12.org
More information about the ODE