Project Making a Lua Script Vessel Car: The VW Thing

@Gondos I seem to recall that we discussed how to get contact point forces and/or their deflections in Lua. I had to drop the project for a time and I don't remember if anything came of this. I know there is a get_forcevector( ) method that gives the total contact forces, but I need the individual contact normal forces on each wheel. I think I can calculate them through available methods, but these must be available internally to Orbiter - if they are accessible to the user I'd naturally rather do that instead.
 
@Gondos I seem to recall that we discussed how to get contact point forces and/or their deflections in Lua. I had to drop the project for a time and I don't remember if anything came of this. I know there is a get_forcevector( ) method that gives the total contact forces, but I need the individual contact normal forces on each wheel. I think I can calculate them through available methods, but these must be available internally to Orbiter - if they are accessible to the user I'd naturally rather do that instead.
There is a prototype branch (#470) that makes contact information ("vertical" depth and normal but not forces) available.
This is too experimental to make it for the next release, it'll have to wait for the next one I guess.
 
There is a prototype branch (#470) that makes contact information ("vertical" depth and normal but not forces) available.
This is too experimental to make it for the next release, it'll have to wait for the next one I guess.
Thanks. I'll take a look at that.
 
Last edited:
I have a car that drives around and can drift around corners if I take them too fast :p:

Screenshot at 2024-10-15 19-43-05.png

It's a rudimentary model. I compute an angular velocity from the vehicle forward ground speed and the Ackermann turning radius and set that angular velocity to turn the vehicle. I then calculate what the lateral friction force would need to be to prevent skidding sideways during such a turn. I then calculate a dynamic friction force between all the tires and the ground. I take the lesser of the two forces and apply that to the vehicle in the -X direction at the elevation of the wheel contact points. So at low speeds the tires stick to the surface and I can drive around without skidding. At higher speeds, if I take a corner too fast, I skid.

It works pretty well and it's easy to drive, and is pretty easy to implement. The only thing I dislike is that the vehicle doesn't heel the suspension in turns. Unfortunately this doesn't model the forces on each wheel which would be needed to do that.

I'd like to put some particle streams on this, but I am having problems formatting the PARTICLESTREAMSPEC table in Lua.
 
Setting the angular velocity for turns works OK if you are driving on a perfectly flat surface, but it has some issues on any terrain, or if the vehicle is tilted in any manner.

I am trying to add side forces to each wheel individually, but that really doesn't work well as I really can't determine the normal contact force on each wheel.

Testing continues...

Screenshot at 2024-10-16 19-50-19.png
 
Of course, at one point, its no longer a bug, but proper physics. 😉
 
Of course, at one point, its no longer a bug, but proper physics. 😉

I am very much from the "break things faster" school of add-on development. :)

One thing I am very pleased with is the wheel suspension animations. They are not perfect, but the wheels travel up and down while traversing rough terrain pretty convincingly. If I can sort out the physics, 4WD off road vehicles and rovers could be a thing.

Getting the steering to behave appropriately using general contact forces on terrain will be a challenge. Getting something that drives appropriately on a flat surface is relatively straightforward by setting angular velocities, but that does not generalize beyond a flat surface. I would need to have a reference frame aligned with the normal of the local terrain to use that method generally.

It occurs to me that I could potentially use the altitude calculations that describe each wheel's animated travel to determine normal contact forces through their defined touchdown point stiffness values. I might experiment with that later today.
 
Could someone take the code and do a C++ vessel? I can do that. But the suspension animation is what I interested in
 
It occurs to me that I could potentially use the altitude calculations that describe each wheel's animated travel to determine normal contact forces through their defined touchdown point stiffness values. I might experiment with that later today.
Hmm...this seems to work. I calculated the normal force on each wheel using this method and the sum of those forces matches the vehicle weight exactly, and that seems to hold up when the vehicle moves and turns. The normal force changes on each wheel (as expected) but the sum of all those forces is the vehicle weight.

Now I should be able to calculate the lateral forces needed to keep each individual wheel from skidding, compare those forces to the dynamic friction force on each wheel, and apply the lesser of the two to each wheel. I'll have to do this in the local reference frame of the steering front wheels, but this should yield a general steering model. If that works, I will just need to apply thrust and braking forces in the longitudinal axis of the front wheels.

Onward!
 
Had to update some code, but in some ways this code got a lot simpler. I can determine the degree of travel of all four wheel struts independently and animate heel in turns and when accelerating:

Screenshot at 2024-10-18 17-04-14.png

I can calculate the normal force on each wheel, and when not accelerating those computed forces match the weight of the vessel:

Screenshot at 2024-10-18 17-17-43.png

Now to calculate the lateral loads on all four tires in turns for the steering model. And brakes would be nice.
 
OK, The Thing is available as an addon:


It works in OpenOrbiter 05142024, and I would expect that it would work in later versions so long as the methods haven't changed.

It will NOT work in Orbiter 2016.

It's pretty basic right now but it's fun to drive. It unfortunately still relies on dynamic friction coefficients for steering, but it behaves pretty nicely despite that. It's rather fun to drive around the small access roads all around KSC with terrain on. It does OK in moderate terrain, but if you flip it into the trees you'll have to restart the session as there isn't a wrecker available to flip you right side up.
 
Last edited:
The Thing has been updated to version 1:



Thunder Chicken said:
I was struggling with how to model static friction. Attempting to calculate the forces needed to prevent skidding often lead to extremely high forces that would flip the car or send it to Alpha Centauri. What I hit upon was a more compliant means to enforce no side skid. I determine the lateral velocity of each wheel (in the wheel frame of reference) relative to the ground, and I multiply that by the simulation time step to yield an effective displacement dx for each wheel, and I integrate this displacement with time. I then multiplied this total displacement by a pseudo "stiffness" that increases the lateral forces to negate side skid. I apply the lesser of this static force and the dynamic friction force.

So now the car turns in nice circles at low speed, but if you suddenly turn while going fast you'll skid. Whether the static or dynamic forces are applied are determined wheel by wheel, so steering into the turns will allow the front wheels to "catch" while the rear wheels may still be skidding. You can do donuts now!
 
I need someone to make a Nürburgring add-on. I'm racing up and down the SLF runway and doing power slides everywhere and I'm deeply wishing for a windy road to drive on.
 
I have both the Nord and Sud Schleife in a GTR2 install, and some really nice DDR circuits that don't exist anymore (thank god for simulations!). Best tracks in the world IMO. Maybe you could "cut" a circuit with Flat Area Wizard?
This certainly makes O24 even more interesting! Especially the offroad possibilites for buggys and rovers.
 
I have both the Nord and Sud Schleife in a GTR2 install, and some really nice DDR circuits that don't exist anymore (thank god for simulations!). Best tracks in the world IMO. Maybe you could "cut" a circuit with Flat Area Wizard?
This certainly makes O24 even more interesting! Especially the offroad possibilites for buggys and rovers.
Something with some light terrain, rises and such, would be fun. The suspension travel for the VWThing is kinda excessive (deliberately so, so I could see the car heel in turns and during acceleration / braking), and it does behave somewhat like a dune buggy at the moment. Just tearing off south of KSC outside of the high resolution terrain is a lot of fun.
 
Exploring the terrain and lost back roads all around KSC:

Screenshot at 2024-10-22 19-49-18.png
Screenshot at 2024-10-22 19-56-43.png

Made it back to civilization!

Screenshot at 2024-10-22 20-10-48.png

It's an interesting driving challenge to make it through this stuff. You need to drive it like a rock crawler, going slow and using your brakes and thinking about traverses.

If I could get a mesh of an Apollo rover this code would be great for it on the Moon.
 
Last edited:
So I am thinking of a rudimentary automatic "transmission" that will allow forward drive, reverse, neutral, park.

My biggest question - what is the most sensible key mappings for this? I'm rather interested in making this easy and intuitive to drive using a keyboard, but the keys are a problem.

I think D can be safely used for drive, and I think N is safe for neutral. But reverse is less obvious to me. I can't use up/down arrows for forward/reverse as that interferes with the camera pan functions. I can't use R for reverse as that is needed for time acceleration control. Back space maybe?

I similarly am wondering about a key for Park. P is out as that is needed for pausing (but that is Ctrl+P, so maybe just P is fine?)

Thoughts?

As far as each function - they seem like trivial ideas at first, but it's important to elucidate what should occur in each transmission mode.:
  • Drive should only allow forward motion. The car should not roll backward even if no throttle is applied, even on a hill with the brakes off.
  • Reverse should only allow reverse motion. The car should not roll forward even if no throttle is applied, even on a hill with the brakes off.
  • Neutral should allow free rolling in forward or reverse directions.
  • Park should NOT allow free rolling in forward or reverse directions.
And before anyone asks, no, I am not making a manual transmission (yet). In the far future maybe, but not anytime soon. We must learn to deal with our glorified Orbiter golf cart before we can have our Orbiter Bugatti.
 
Last edited:
So it seems that my idea to model lateral static friction forces using a spring displacement has some issues that were masked by the dynamic skid model. It seems that these side springs, all by themselves, cause the car to oscillate laterally as they are completely undamped, which makes sense, but is clearly undesirable. Some damping may be required.

I am also dimly thinking that, for lateral static friction, side slip is essentially an "error" that could be used as a PID control input to set a lateral force that would drive side slip to 0. In essence my lateral spring model is a P-only controller, and apparently the proportional gain is far too high.

Practically though I think this is the right path. Applying side forces to prevent lateral velocity are utterly necessary for steering, and this would also permit general driving on inclined surfaces. My add-on already does this, but it's a rather crude implementation. I think it can be improved.
 
So I am thinking of a rudimentary automatic "transmission" that will allow forward drive, reverse, neutral, park.

My biggest question - what is the most sensible key mappings for this? I'm rather interested in making this easy and intuitive to drive using a keyboard, but the keys are a problem.

I think D can be safely used for drive, and I think N is safe for neutral. But reverse is less obvious to me. I can't use up/down arrows for forward/reverse as that interferes with the camera pan functions. I can't use R for reverse as that is needed for time acceleration control. Back space maybe?

I similarly am wondering about a key for Park. P is out as that is needed for pausing (but that is Ctrl+P, so maybe just P is fine?)

Thoughts?

As far as each function - they seem like trivial ideas at first, but it's important to elucidate what should occur in each transmission mode.:
  • Drive should only allow forward motion. The car should not roll backward even if no throttle is applied, even on a hill with the brakes off.
  • Reverse should only allow reverse motion. The car should not roll forward even if no throttle is applied, even on a hill with the brakes off.
  • Neutral should allow free rolling in forward or reverse directions.
  • Park should NOT allow free rolling in forward or reverse directions.
And before anyone asks, no, I am not making a manual transmission (yet). In the far future maybe, but not anytime soon. We must learn to deal with our glorified Orbiter golf cart before we can have our Orbiter Bugatti.
Hi Thunder,
Great stuff this "Thing"!!

I'd be happy with Shift + N, D, R, or P.

Not sure about the "not roll backward or forward if no throttle applied even on a hill".....
Isn't that what an auto car would do?
All the ones I've owned anyway (except a 3.8 Jag that wouldn't move till you touched the throttle.)

I attempted to address the suspension thing with a couple of my birds, F-35B and A4E Skyhawk but you're tackling it from a much more technical angle.
Please keep up this excellent project.:cheers:
 
Back
Top