truck lua object

I'm currently trying to get telemetry from the game, and have had some success by modifying the truck.lua to save the wheel rpm, ground speed, engine tension (difference between what you've asked for, and what the engine can/is giving), selected gear, and some other basic things.
I'm wondering though, what other properties do the wheels and truck objects have? I tried dumping it to a table using something along the lines of:

for key, value in pairs(truck) do
    .....export each key and value pair from the table 

but it didn't seem to work for some reason.
Gives me:

 K is: isBreakPulled, V is:  K is: prevGear, V is: -1

Which is great, but I'd prefer more!

Anyone with more lua experience, or a dev able to shed some light on some of the other properties of the objects?

The ones I've got thus far are:

  • truck.engineTension

  • truck.heavy (seems to follow tension closely, but shows a greater difference)

  • truck.turbo (doesnt seem to give any output)

  • truck.trans(also, nothing, and neither does truck.transReverse)

  • truck.revving (seems to indicate the clutch being down, as it goes high on gear change, but engine tension remains the same, more or less...So not sure)

  • wheel.radius (this seems to come from the xml file for the specific wheel)

  • wheel.angVel (angular velocity - this is the rotational speed of the wheel I think (i get these two mixed up though...)

  • wheel.linVel (Linear velocity - correlates with ground speed - +value for forward, -value for reverse

  • difference between angVel and linVel gives you a nice wheel spin factor

Currently, I've got some key ones exporting to a csv file so I can plot them in excel (or read them in Python and parse the result onto an arduino - driving a voltmeter as a speedo/rpm gauge etc.

If you want my code (its not very neat) :

if (truck.engineTension > 0.0001) then

		file ="rpm.csv", "a")

This lives in the ProcessTruck function, so it is called regulally. It dumps it all to a CSV file called rpm.csv (because I was trying to find the rpm)
There are two global variables, groundspeed and angularspeed, which are defined under process wheels...

last edited by skipper_is
Community Moderator - Spintires

Hi again 🙂
I've tried to get some data and do the math as we spoke.
Blue is angular speed, red gear number, green gear ratio and purple suppose to be RPMs...
Sample is based on G25 with shifter, B131 truck, testing ground, tarmac road.
However rest looks promising, 1st gear seems to behave strangely.
I'll take another look into it later today, so far I feel it could give me better results with some load, empty truck is simply too jumpy, which spoils data...

last edited by Sodoma

[0_1519040481839_truck.lua](Uploading 100%) Ah nice! Yea, interim method of getting RPM, like you mentioned on Discord, would be a lookup table for each truck..
Would be easier if we pass the data to Python - then we could have a little GUI allowing for easy truck selection
The fact that the game passes some details from the xmls through to the lua script (like the wheel radius), there must be other parts of the xmls that can be accessed.
I wonder whether wheel radii are different enough to be used as a "fingerprint" for the different trucks...Probably not

Some of the trucks have reasonably unique radii, the K700 for example, but most share wheels with other vehicles, for example, the D535 has the same wheels as the E7310

:Edit 2:
Figured out how to get AWD, diff lock and handbrake status to file. Was trying to write a boolean to file, and it wasn't having it, so converted to string and its all good.

Here is my modified lua file if you're interested

Headings for the CSV would be:
Tension, Ground Speed, Wheel Speed, Gear, Wheel Radius, Revving/Clutch?, Class, All Wheel Drive, Diff Lock, Handbrake

last edited by skipper_is
Community Moderator - Spintires

Ok, I'll take a look at it for sure, have some new ideas, different from what we discussed already.
I feel we are on a good way 🙂

Idk whay you guys got going on....i wish I knew more coding/programming but i love seeing this type of stuff! Following! Hoping too learn a bit of something! 👌

Edit: I'm assuming your just recording the data?!?

last edited by DrGoNzO1489

Well, looking at it is the hard part, once you've got the data, you can do all sorts, from simpits to just custom dials

Community Moderator - Spintires

Or many other things...
Sorry, need to show-off a bit 😂

Nice! Yea, just needs some dials there now! Well, you can already put in a speedometer

Lot of resisters! What are they all doing?

last edited by skipper_is

@sodoma i was curious as to where this was going, very cool set up idea. wheel control with working gauges and shifter, i can dig it. big thumbs up

last edited by 8up local
Community Moderator - Spintires

Digital input for analog inputs
Had some unused analogs and lack of buttons...
Also have tons of same resistors and was lazy to buy few differents 😄
However, coding part is not my job at all, everything was downloaded from internet. Wanna share?

Hopefully, just an idea so far 🙂

last edited by Sodoma

Ah, fair enough
This is my shifter:
Need to do some lettering, some sort of cover on the threaded bar, and maybe a new knob... Doesn't look nearly as professional as yours though!
Just powering it through an Arduino Micro - using up 8 digital pins, but I wasn't really planning on adding much more to it..

last edited by skipper_is
Community Moderator - Spintires

Shifter was what I start with (due to achievement in ST) and then I add analog pedals, then a wheel, then FFB... Don't need to say, I've rebuild whole thing with every iteration from almost begining. When I will bilding another one, I will save a lot of time and effort 😂

However, I think I've got something with our original topic, I will:
a) walk my dog
b) take a shower
c) think a bit more
d) do some testing

and then hopefully share results.
Seems VERY promising after a first run...😱 🤐

Edit: And by the way, speaking about your shifter, my is maybe better just because it is welded, working principle is probably identical and honestly, I WILL go for H-pattern soon, this is useless...
Or at least not a brightest idea...

last edited by Sodoma

@sodoma said in truck lua object:

Or many other things...
Sorry, need to show-off a bit 😂

wow man thats some cool ass wheel

Community Moderator - Spintires

Ok, for today, I have to admit defeat.
My idea was combined together throttle pedal position (players wish of RPMs) and engine tension (difference between that wish and "reality"). But I have to be missing something
As you can see, even with constant full trottle (orange) speed keeps going up (dark red), while engine tension drops (blue).
This is what we (probably) have on cockpit dial as "RPMs" it doesn't make sense.
Obviously I have to get back to downscaleing of angular speed of wheels...
Tomorrow, Have to takse some sleep for today...

Community Moderator - Spintires

May I ask you for some kind of presentation how physics of trucks, more specificaly propelling of trucks (engine+gearbox) works? Something as it was there for mud and water. This could be very helpful in here...
Pretty please...😇

And ideally a list of the truck object properties....

Community Moderator - Spintires

I think I am finally getting somewhere. It needs a bit (lot) more research, but so far, seems nicely.
This is based on E7310, proving ground, uphill, downhill, turn and again up and down and then bit stright away on flat ground.
Still not perfect, but it is based on angular wheels speed and shifted gear...
Purple line 😉

Lead Developer - Spintires MudRunner

@sodoma said in truck lua object:

May I ask you for some kind of presentation how physics of trucks, more specificaly propelling of trucks (engine+gearbox) works? Something as it was there for mud and water. This could be very helpful in here...
Pretty please...😇

Hello! There is not too much to tell, and gearbox physics is not something I'm particularly proud of. So just let me know what exactly you need!

Choose number of gears and "optimal wheels angular velocity" (fGearAngVel) for each gear ("Gear/AngVel" XML file parameter).
And engine power (fEngineTorque, "Motor/Torque" XML file parameter)

For each gear, game operates with following parameters:
fGearAngVelMin = fGearAngVel * 0.25 - 2.0
fGearAngVelOpt = fGearAngVel
fGearAngVelMax = fGearAngVel * 2.0 + 5.0
fGearEngineTorque = fEngineTorque / pow(max(fGearAngVel / 2.0, 1.0), 0.5)

"High" (1+) gear:
fGearAngVelMin = 0.4
fGearAngVelOpt = fGearAngVel
fGearAngVelMax = fGearAngVel + 2.0
fGearEngineTorque = fEngineTorque * 1.25

Game computes "engine force multiplier" (engineCoef), based on
minAngVel,maxAngVel - minimum/maximum angular velocity of any wheel (that has torque)

float engineAngVel = lerp(maxAngVel, minAngVel, .5f);
float engineCoef;
if (engineAngVel < fGearAngVelMin) {
engineCoef = 0;
} else if (engineAngVel < fGearAngVelOpt) {
engineCoef = (engineAngVel - fGearAngVelMin) / (fGearAngVelOpt - fGearAngVelMin);
} else if (engineAngVel < fGearAngVelMax) {
engineCoef = (engineAngVel - fGearAngVelOpt) / (fGearAngVelMax - fGearAngVelOpt);
} else {
engineCoef = 0;

(lerp - linear interpolation of 2 parameters)
So the actual force that is applied to the wheel is computed like that:

wheelForceMultiplier = engineCoef * fGearEngineTorque * fAngVelSlowdownMult * pWheel->fCurrentTorqueRatio;
(I dropped some of parameters for simplicity)

fAngVelSlowdownMult is a parameter that prevents the vehicle from accelerating too fast (it compensates for lack of real-world inertia of mechanical parts of the engine), computed like that:

fAngVelSlowdownMult = saturate(0.0 - pWheel->fDeltaAngVel / fMaxDeltaAngVel * 2.0);
fAngVelSlowdownMult = saturate(fAngVelSlowdownMult +
max(pWheel->fWheelLinVel - 2.0, 0.0) / 10.0 +
1.0 - saturate((fabs(pWheel->fWheelAngVel) - 1.0) / 2.0));

Here fMaxDeltaAngVel is XML file parameter "Motor/MaxDeltaAngVel".

pWheel->fCurrentTorqueRatio is computed for each wheel based on diff lock mode. Let me know if you need documentation for that (It's a lot of hardcoded math too).

Hope this helps,
Best regards!

last edited by Pavel
Community Moderator - Spintires

WOW, Nice to see your response here, this is what I wished for, but haven't expecting it much.
I am impressed!
I will go thru it, hopefully I'll be able to manage some more accurat-ish RPMs 🙂
Thanks a LOT!

This is neat guys, I'd love to see telemetry in this game.

Looks like your connection to Focus Home Interactive - Official Forums was lost, please wait while we try to reconnect.