Lua Script VW Thing

Lua Script VW Thing 5

So I checked my VWThing against Orbiter 2024 and found that it works quite well, but there does seem to be a bug with the visuals. When I apply the brakes with the spacebar, the car body visuals as seen from the cockpit disappear, and they reappear when I release the brakes. I have no idea why this is occurring.

I don't know if this is a bug in Orbiter 2024 or a bug in my script that is coming to light in Orbiter 2024. If someone can confirm that they see this behavior in their installs I'd appreciate it.
  • Like
Reactions: Matias Saibene
Added a simple thermodynamic model of an Otto cycle spark ignition engine which provides realistic power and fuel consumption for a VW 1600 cc air-cooled engine. The only inputs needed are the engine displacement and compression ratio.

Other code changes are mostly organizational with some code broken out into modules. Some minor bugs were squashed.

I eventually want to clean up the mesh and add a dashboard and a steering wheel for better immersion.
  • Like
Reactions: misha.physics
Minor improvement, but you can now toggle from forward view from the driver's seat to a forward camera set up outboard of the left front wheel so you can see the suspension animations. It's a pretty interesting vantage point.
I fixed some items and improved my understanding of the steering model. It was incorrectly failing to transition from the static friction to the dynamic friction skid model as I was calculating those forces simultaneously, and the vehicle dynamics caused the calculation for the alternative model to be incorrect.

I also related the stiffness of the pseudo spring forces to prevent skid to the shear forces of a rubber tire with a known tread height and contact patch area. It yields a stiffness very close to the ad hoc stiffness I applied previously, which is nice that it relates to a reasonable physical model for the tires.

Looking at this spring model for static friction, I realized that the algorithm to calculate the force needed to keep the wheels from slipping sideways was rather identical to a PI controller where the integral gain was the stiffness and the proportional gain was the damping constant. It seems to be working very nicely now.

Some additional user improvements:
  • Can shift up and down through forward, neutral, and reverse.
  • Now transitions between skid and turning model appropriately.
  • Indicators are provided to show which steering model is in effect for each wheel. (probably should implement some skid sounds for immersion).
  • A simple positive caster model that slowly reduces the steering angle to zero when no steering inputs are given. This replaces suddenly sending it to 0 degrees with the keypad 5 key as activated the skid model inappropriately.
  • Minor code cleanup, whitespace, comments, etc..
Feedback welcome, either here or on the related thread.
This update contains:
  • Generalization of code to set suspension and touchdown points under any gravitational acceleration. You can drop this on any planet and the contact points will be correct and the suspension will be tuned to the local gravity.
  • Fixes for some logic errors that caused erroneous implementation of the dynamic skid model instead of the static rolling model.
  • Refinements of the static rolling model.
  • Improved steering control and animation.
  • General code cleanup and organization and removal of cruft, comments, etc..
Some aesthetic refinements include a small cheat sheet for vehicle controls and gear and speed indicators. When this code stabilizes some more I might invest some time in putting in an animated dashboard and steering wheel.
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!
  • Like
Reactions: misha.physics
Back
Top