Forums
Engine and wheel inertia - Printable Version

+- Forums (https://www.vdrift.net/Forum)
+-- Forum: Project (https://www.vdrift.net/Forum/forumdisplay.php?fid=4)
+--- Forum: Development (https://www.vdrift.net/Forum/forumdisplay.php?fid=9)
+--- Thread: Engine and wheel inertia (/showthread.php?tid=1146)

Pages: 1 2


Engine and wheel inertia - stan.distortion - 07-16-2009

Hiya. New to the list so hello all. Very long time since I had a look at vdrift and very impressed with it, thanks a lot.
I've started going through the source (current SVN as of this morning), there are a few things (mostly related to the game physics) that I would like to have a look at:
Wheel inertia under braking. When releasing the brakes after locking up the wheels they take far too long to spin back up to road speed. It doesn't seem to be the same for all cars, the green F1 car is very bad while with the formula ford it's barely noticeable.
Engine inertia. When revving the engine in neutral it takes a very long time (seconds) for the engine to reach the rev limit. The same 2 cars are a good example with it being obvious in the green F1 car and barely noticeable in the formula ford.
I'm guessing these 2 issues are related and the problem is somewhere in the car files, if someone could point me in the right direction it would be a big help (BTW button delay is set to off).
A couple more if anyone has read this far Wink
Button delay. Being able to set the delay is a great help but it seems to be equal times in both apply and release. It feels like release should be a lot quicker that application, I'd like to have a play around with it and maybe try out using the force feedback values with the steering. Anyone know what functions I should be looking at?
Tyres. I quickly read through the 'magic formula', who am I to argue with it? Wink All the same, the transition between static and sliding friction doesn't seem right. Grip when accelerating or braking hard enough to spin/slide seems far less than when the front wheels are at full lock on a corner and at about 45 degrees to the direction of travel and the transition between rolling and sliding doesn't seem sharp enough for the difference in grip levels. Again, what parts of the source should I be looking at?
Still reading? fair play 'cos I'm sick of typing Wink
Controller calibration, sensitivity, deadzone, etc?
Noise. Where and can multiple sounds be used ie. from each wheel, engine, exhaust, gearbox, diff etc. and different sounds for tickover, coming 'on pipe', bouncing valves, on/off throttle etc.
Thanks for reading through all that,
stan.


- stan.distortion - 07-16-2009

Ok, figured out most of it. RTFM is the short answer Smile
Wheel inertia under braking: In the .car file for the car in the data folder but doesn't seem to make much difference.
Engine inertia: Same as above but definitely makes a difference.
Button delay: Not found it yet.
Tyres: In the .car file too. Not tried messing with it yet.
Controller calibration: In controls.config in $HOME/.vdrift/
Noise: Found some info on the forum here: http://vdrift.net/Forum/viewtopic.php?t=888 didn't look into positioning sounds (sound changes depending on viewpoint) yet though.

Almost forgot, body roll is almost non-existent. Tried messing with the anti-roll bars, center of gravity and suspension pivot heights with no luck, the car rolled over before the suspension showed any roll. The only thing that did work was softening the suspension to around 30% of the original values. Any thoughts or suggestions? This varies between cars so I'm guessing its all to do with the car config.
cheers


- stan.distortion - 07-17-2009

Ok, done some more poking at this and something definitely seems wrong with the wheel inertia, setting it to near zero (ie 0.1) results in practically no grip. Firstly I would imagine inertia would have practically no effect on grip and secondly, could inertia not be calculated from the weight of the wheel? Found the relevant section, cardynamics.cpp 478, can anyone give me few pointers as to what does what with that?
Also there is the max-compression-velocity part of the .car file. What is that doing there? It's the exact opposite of how dampers work (will try and dig out details if anyone wants them). Again, can someone let me know whats supposed to be happening here?
Last thing, is the .car file some kind of standard layout? (seen similar in GTR2/GTL but not dug through it).
cheers


- joevenzon - 07-17-2009

Wow, that's a lot of interesting questions! I'll try to answer some of them. By the way, you probably already found it, but there's a description of the car parameters here:
http://wiki.vdrift.net/Car_parameters

I recently rewrote the car physics code so on the plus side it's on my mind but on the down side I'm sure it has a lot of bugs.

Tires:
As you noticed you can adjust all of the pacejka parameters in the .car file. The only thing you can't adjust is the way that the longitudinal grip (accelerating/braking) and lateral grip (cornering) are combined. The basic pacejka equation models each separately, and it's up to you to figure out how to combine them. I use a combination algorithm that Brian Beckman came up with and describes here:
http://www.miata.net/sport/Physics/Part24.html

The relevant function is CARTIRE::GetForce(). The Beckman method sort of pre-combines them by scaling the inputs to the individual pacejka functions. If you want you could try modifying the function to not do that and then try one of the post-combining schemes that's currently commented out.

Noises:
At the moment, the only supported noises are road noise, a "bump" noise that plays when the suspension compresses suddenly, a crash noise, tire squeal/dirt noises, and engine noises. If you're in a hood or driver view, most of the sounds play without any 3D positioning effects (which are expected to be baked into the sound file), otherwise they're put at the center of the car (the tire squeal/dirt sounds are always put at the wheel locations). I'd like to add a lot more noises but just don't have them. The engine noise can either be an engine.wav file that's in the same folder as the car (in which case it needs to be 7700 RPM), or a bunch of separate files. For an example of the latter, check out the TL2. It's got a sounds folder with wave files in it and a TL2.aud file that has a very similar layout to the GTR type .aud files.

Controller calibration:
No old-school joystick calibration options are used by VDrift anymore (you should use your OS's calibration tools), but individual controls can be adjusted for deadzone, gain, and exponent. To make those adjustments, just go into any "assign controls" type screen in VDrift and click on the little joystick icon for any control that you've added. It'll pop up a screen with adjustment sliders.

Button delay:
Good idea about making the "off" delay ramp out faster. The code for button ramping is in CARCONTROLMAP_LOCAL:TonguerocessInput(). One of the arguments that is passed in when this is called from game.cpp is the button ramp setting. It's used by the joystick button handling code to be passed into Ramp().

Engine inertia:
I think you've figured this one out. There used to be a separate setting for the engine friction (torque-friction) but I now ignore that setting and compute a value algorithmically in CARENGINE::SetTorqueCurve():
Code:
friction = max_power / (max_power_angvel*max_power_angvel*max_power_angvel);

Wheel inertia:
That section of code in cardynamics.cpp@478 is ignored; frictionlimiting is always false so that block never executes -- so just ignore that.

First, there are a couple of parameters in the .car file that could be interpreted as wheel inertia: first, the mass parameters in the wheel sections, and second, the rotational-inertia parameters in the tire sections. By the way, you can see how the .car parameters map onto the car physics classes by looking at the mammoth CAR::LoadDynamics() function.

The mass parameters in the wheel section are used only to add to the computation of the body's inertia tensor and weight (unsprung weight is not simulated separately). The rotational-inertia parameters in the tire section are used by the physics tick of the ROTATIONALFRAME inside of CARWHEEL. This is the simulation of the rotation of the wheel in its forward axis only -- forces (from the engine, from the brakes, from the road) are applied to speed it up or slow it down, and it reacts accordingly based on its inertia. Don't set this too low or the whole simulation breaks down and you'll get wacky results. When I fiddled with the inertia parameter I found low settings caused more wheelspin when starting from a stop -- I think this is just because the engine can spin its wheels with less work and get them past that ideal, maximum-force longitudinal slip %. With a high setting it takes forever to accelerate. I'd expect a lower setting to make the brakes lock up more easily. What were you expecting?

Yes, the inertia could be calculated based on the wheel mass and radius by assuming a cylinder: inertia = mass * radius * radius * 0.5... but that seems to give too low of a value, so either my units are off or the rotational inertia of the other components of the driveline that need to be added in (diff, axle, etc) are much larger than the wheel inertia, though that seems kind of absurd.


- joevenzon - 07-17-2009

Max compression velocity
In Vamos I seem to remember a comment to the effect of this simulating damper lockup due to turbulent flow or something like that. I agree with you that it seems odd so I don't use this setting anymore. If you want to see what it's like to turn this on, comment in the last few lines of CARSUSPENSION::SetDisplacement().

Body roll
You're right, it does seem much too low. It could be that the inertia tensor isn't calculated properly, or a problem with the way the suspension is deflected around the instant center (the "hinge" parameter), or problems with the code that calculates torque due to forces applied away from the CG point (which had some big bugs earlier but I thought I had fixed).


- joevenzon - 07-17-2009

Some other notes. If you start VDrift with the "-debug" option, it displays a bunch of debug data about the car physics calculations, although it's hard to read unless you have the resolution pretty high. Also, you can launch VDrift with the "-cartest 360" option for example (replace 360 with any car), and it'll analyze things like 0-60 time, stopping distance, downforce, etc.


- stan.distortion - 07-18-2009

Thanks for the reply. Sorry about all the questions, I was kind of using the post as a notepad for a while. Smile
Tires: The Euclidean geometry for the rotation calcs has smoke coming out of my ears already, I'll leave this alone for the moment Smile Cheers for the link though, it will be a big help.
Noises: Had a play around with the .wav and .aud files for the TL2, seems straightforward and works well. You mentioned position data baked into soundfiles, is that something similar to audio files like .wav with more data or simple sounds with midi data?
Controller calibration: An external app makes more sense, I was kind of wary about trying it. The last time I was doing anything with joysticks in linux it was nothing like as simple Wink
Button delay: Will try and have a look at this soon.
Engine inertia: Had something unusual with this on a few cars but most noticeable with the green F1 car. In neutral it takes a few seconds for the engine to reach full revs but when the wheels loose traction in gear the engine reaches the rev limit in a fraction of a second, I'll try and figure this out along with the wheel inertia as they seem to share a lot of functions.
Wheel inertia: cardynamics.cpp@478, tried blanking it out and it made no difference, it was the ROTATIONALFRAME code I was looking for, cheers. Scared the crap out of me when I saw it though, thank god there is plenty of info on the net Smile
"With a high setting it takes forever to accelerate. I'd expect a lower setting to make the brakes lock up more easily" That's what I was expecting too, like a little buzzy engine on an icy road compared with a big diesel on the same surface but it seems to effect the amount of grip available which I wouldn't expect. With the traction control on the grip seems the same regardless of the inertia setting, it could well be I'm barking up the wrong tree altogether and its something to do with the difference between static and sliding friction but even with a weightless transmission the torque shouldn't be able to overcome the grip at low throttle openings. Will burn a bit of grey matter on this one as something just doesn't seem right.
"inertia = mass * radius * radius * 0.5" Shouldn't there be a pi in there somewhere? Not gone into this yet but was thinking the majority of the weight will be in the tread of the tyre and the rim of the wheel, I was thinking about 60% of the weight at the wheel diameter as a rough guess but at the end of the day it doesn't do anything a separate inertia value can do.
Max compression velocity: I could have sworn it made a difference but just tried messing around with it and sure enough, it does nothing. Could just be something with the spring values as I backed everything of to about 30% of their original values with a C7 and it behaves just as I would expect. The FF seems to back this up, hit a curb with it and it launches its self off the track.
Thanks for the debug commands etc, they will come in useful Smile
BTW, running this on 64bit gentoo with arch=a64 set, doubt it makes any difference but just in case...
Was watching a friend on vdrift yesterday and it reminded me how much of a big deal GTR and GTL where when they where released and vdrift isn't far behind that standard. nice one Smile
cheers, Stan

EDIT: Found this:
http://gafferongames.com/game-physics/integration-basics/
Wow, its all starting to make sense. Had a good laugh after seeing this one:
http://www.cs.ubc.ca/~rbridson/courses/533d-winter-2005/cs533d-slides-feb23.pdf
That's simplified?!? Wink
EDIT2: Noticed your posts on the first link Smile I cannot get my head around his interpretation of inertia, he has it down as a constant value whereas I always understood inertia to be a variable and pretty much the same as velocity. ANOTHER EDIT: wikipedia set me straight, don't know what I was thinking Smile
One of the links in the comments seems to be making sense of why the inertia value must be well above zero:
http://techhouse.brown.edu/~dmorris/projects/tutorials/inertia.tensor.summary.pdf
Quote:So for example, what would it mean for Ixx to be zero? It would mean that for a given torque, I
would get an infinite rotational acceleration around the x axis. That’s an important lesson. For
real objects, none of the diagonal elements in I can be zero, since we know there’s no real object
where a tiny touch will set it spinning at an infinite rate.
Is that something along the right lines?
cheers


- joevenzon - 07-18-2009

Quote:Noises: Had a play around with the .wav and .aud files for the TL2, seems straightforward and works well. You mentioned position data baked into soundfiles, is that something similar to audio files like .wav with more data or simple sounds with midi data?

What I meant by "position data baked into the soundfiles" is just that, for example with the bump sounds, there's a forward bump sound and a rear bump sound, and I recorded them in my car with a recording device positioned in the driver's seat. They're stereo wave files. When you play back the "forward bump" without any 3d positioning effect then it plays back just the same as if you were sitting in the driver's seat of my car. That's all I meant. I don't do any additional panning or anything to make them sound like they're coming from the front of the car, because the wave files were already recorded ("baked") that way.

Quote:Engine inertia: Had something unusual with this on a few cars but most noticeable with the green F1 car. In neutral it takes a few seconds for the engine to reach full revs but when the wheels loose traction in gear the engine reaches the rev limit in a fraction of a second, I'll try and figure this out along with the wheel inertia as they seem to share a lot of functions.

Hum, you may have found an issue there, it could be that the engine drag is different in-gear due to a bug or something. I'll take a look at this too when I have some time.

Quote:With the traction control on the grip seems the same regardless of the inertia setting, it could well be I'm barking up the wrong tree altogether and its something to do with the difference between static and sliding friction but even with a weightless transmission the torque shouldn't be able to overcome the grip at low throttle openings. Will burn a bit of grey matter on this one as something just doesn't seem right.

Another way to think of it is with extremes: think of a near weightless wheel versus a lead wheel that weights a couple hundred pounds. Imagine the car is on a dyno.

Quote:Could just be something with the spring values as I backed everything of to about 30% of their original values with a C7 and it behaves just as I would expect. The FF seems to back this up, hit a curb with it and it launches its self off the track.

So, you're saying that with the lower spring rates the cars behave more realistically (including body roll)? Could be. I think that in general the spring rate parameter in the .car file should be set to the wheel rate value, not the spring rate, and wheel rates are usually quite a bit lower than spring rates... but I don't have a very in-depth understanding of it... so the car tunings may need quite a bit of adjustment.

Quote:I cannot get my head around his interpretation of inertia, he has it down as a constant value whereas I always understood inertia to be a variable and pretty much the same as velocity. ANOTHER EDIT: wikipedia set me straight, don't know what I was thinking Smile

In common usage, people mistake inertia for momentum and say inertia even though they mean momentum. I think this is where you've gotten confused. Momentum is P = m*v. Mass is m. For non-rotational dynamics (F=ma, etc), inertia is the same thing as mass. For rotational dynamics, we talk about the moment of inertia (which is just the phrase for rotational inertia) instead, but the moment of inertia plays the same role in rotational dynamics equations as mass does in the non-rotational dynamics equations. So for non-rotational dynamics we have F=m*a, for rotational dynamics we have tau=I*alpha where tau is torque, I is the moment of inertia, and alpha is angular acceleration. An inertia tensor is when the moment of inertia is different in each axis of rotation, and is just a matrix. In 3D space, tau and alpha for example become 3-element vectors (x,y,z) and I is a 3x3 matrix. Anyway, having zero moment of inertia is like having zero mass; it just doesn't work.

Quote:"So for example, what would it mean for Ixx to be zero? It would mean that for a given torque, I
would get an infinite rotational acceleration around the x axis. That’s an important lesson. For
real objects, none of the diagonal elements in I can be zero, since we know there’s no real object
where a tiny touch will set it spinning at an infinite rate."
Is that something along the right lines?
cheers

Yep!


- stan.distortion - 07-19-2009

Quote:So, you're saying that with the lower spring rates the cars behave more realistically (including body roll)?
Made a big difference here, after a bit of messing around 45000 front and 35000 rear for the C7 seems about right so nearer 60% than 30%

Probably a horrendous bodge but changing cardynamics.cpp@43 seems to sort out the engine inertia thing:
Quote:void CARDYNAMICS::ApplyClutchTorque ( T engine_drag, T clutch_speed )
{
if ( transmission.GetGear() == 0 )
{
engine.SetClutchTorque ( 0.0 );
}
else
{
if ( clutch.GetEngaged() )
{
//if the clutch is engaged, force the engine speed to the transmission speed
//engine.SetClutchTorque ( 0.0 );
//engine.SetAngularVelocity ( clutch_speed );
engine.SetClutchTorque ( engine_drag );
}
else
{
//if the clutch isn't engaged, send the engine the torque from the clutch
engine.SetClutchTorque ( engine_drag );
}
}
}

Quick question, where does the wheel mass get applied to the momentum?
I have tried messing around with the mass and inertia and a wheel mass of 35 and inertia of 2.5 gives something similar to a mass of 15 and inertia of 6 but I can't find where the mass effects momentum or inertia.
cheers


- joevenzon - 07-19-2009

stan.distortion Wrote:
Quote:So, you're saying that with the lower spring rates the cars behave more realistically (including body roll)?
Made a big difference here, after a bit of messing around 45000 front and 35000 rear for the C7 seems about right so nearer 60% than 30%

Sounds like a good change. Do you have a sourceforge account? I could give you access to the data repo, if you want to check in your changes. I don't think anyone is actively tuning the cars at the moment (speak up if you are).

Quote:Probably a horrendous bodge but changing cardynamics.cpp@43 seems to sort out the engine inertia thing

I looked into this more and you're right, there is a bug where the engine inertia isn't taken into account when in-gear. Your change is very nearly right, but I don't think it's quite right; the way you have it, I'm not sure the engine gets the proper drag from the wheels. This change to carclutch.h gives the correct behavior:
Code:
T GetTorque ( T n_engine_speed, T n_drive_speed )
        {
            engine_speed = n_engine_speed;
            drive_speed = n_drive_speed;
            
            T normal_force = clutch_position * max_pressure * area;
        
            /*if (std::abs (engine_speed - drive_speed) < threshold * normal_force)// || clutch_position >= 1.0)
            {
                engaged = true;
                last_torque = 0.0;
                return 0.0;
            }
            else*/
                engaged = false;
        
            T force = sliding_friction * normal_force;
            if (engine_speed < drive_speed)
                force = -force;
        
            //compute torque by applying force at the radius
            last_torque = force * radius;
            return force * radius;
        }
However, the fix above causes the engine RPMs to jitter a bit around the fixed value because the clutch friction is always over correcting slightly. It's hardly noticeable but bugs me a bit so I'm going to see if I can't come up with something fancier (maybe preventing the clutch friction from over-correcting, or maybe adding the engine inertia to the inertia of the drive wheels when in-gear).

Quote:Quick question, where does the wheel mass get applied to the momentum?
I have tried messing around with the mass and inertia and a wheel mass of 35 and inertia of 2.5 gives something similar to a mass of 15 and inertia of 6 but I can't find where the mass effects momentum or inertia.
cheers

The tire rotational-inertia parameter (from the .car file) sets the wheel's inertia (in the code). The wheel's mass parameter isn't used for the wheel's inertia. If you're adjusting the wheel mass and it's causing different behavior, I don't understand how either... although of course a higher mass wheel will make the car weigh more and so it'll get very slightly more grip.


- stan.distortion - 07-19-2009

Quote:Do you have a sourceforge account?
I do but it's a long time since I used it, will have to dig out the details.
Nice on with GetTorque, it has fixed everything I was having trouble with. I've dropped the wheel inertia right down to 2 front and rear and it's working well, no more sticking brake calipers going into corners Smile
Just tried a few different mass and inertia settings for the wheels, I made a mistake with that, it must have just been the extra weight giving more grip. however with the engine inertia fixed it's no longer an issue.
I'll dig up my sourceforge account details, hope it's Ok with folks to play around with their work. Tried modeling cars for GTR2/GTL and there is a huge amount of work involved, I'd hate to mess it up.
cheers


- stan.distortion - 07-19-2009

My sourceforge account is "stan_distortion", I'll try not to mess anything up Smile
cheers


- joevenzon - 07-19-2009

In SVN R2516 I committed the change with the clutch GetTorque() function, and also implemented a system to prevent the clutch from causing oscillations in the RPMs which is caused by the clutch calculations now always being fully computed.

I don't think anyone will mind you tuning some of the cars up a bit. Even if someone gets upset, everything is in SVN so there's a complete history there if someone doesn't like a change. Also, this latest code change really screws up a lot of cars (the F1-02 seems slow off the line now, and on gear changes it becomes obvious the clutch doesn't have enough friction) -- so they need to be fixed anyway.


- stan.distortion - 07-21-2009

Just looking into the body roll thing. I can't really get my head around the integration1 and 2 steps but it seems like they are getting applied to the body and wheels as a one lump, there doesn't seem to be anything to move the suspension other than bumps in the track.
cheers


- stan.distortion - 07-22-2009

Got a bit further, suspension displacement ( suspension[WHEEL_POSITION ( i ) ].GetDisplacement() ) is showing body roll but the body isn't moving, I think its getting calculated but isn't getting applied to the body so the next frame assumes the body has already moved.