Haven't written the code yet, but I'm planning to.
I'll probably start simple, then work my way up to tables and crv files.
Simplest string to read:
This would go into an array with basically the points (0,0), (0.2, 5), (0.4, 10), (0.6, 15), (0.8, 20), (1.0, 23)
Then I'll write a lookup function, lookup(array data, float value) that uses the same array structure as above, where value is within [0, 1] and returns the lookup value, linearly interpolated.
Once that works to my satisfaction, I can implement the multi-line file stuff into another function, that outputs a similarly formatted array.
The lookup function for gear shifting would probably be something like lookupshift(array data, float throttle, float currentGear, float toGear)
This would return a speed. So the loop in the script itself would just be something like
Nice and easy to use for any car, just need to write out the table.
If you can see an easier way to make the functions work, or have a request for another type of lookup, now's the time to tell me Still need to work out the exact format of the stored shift tables, and the more I know what it'll be used for the better I can manage.
The most basic table would have 2 speeds per gear change (no throttle shift-up, full throttle shift-up) which you could approximate pretty quickly. Just make sure shift-up speed is higher than shift-down speed at the same throttle in the next gear, cause then it'll pop back and forth.
I'll probably start simple, then work my way up to tables and crv files.
Simplest string to read:
Code:
0 5 10 15 20 23
Then I'll write a lookup function, lookup(array data, float value) that uses the same array structure as above, where value is within [0, 1] and returns the lookup value, linearly interpolated.
Once that works to my satisfaction, I can implement the multi-line file stuff into another function, that outputs a similarly formatted array.
The lookup function for gear shifting would probably be something like lookupshift(array data, float throttle, float currentGear, float toGear)
This would return a speed. So the loop in the script itself would just be something like
Code:
float $shiftarray = readShiftTable("../../shift.tsv")
float $velocity = 0
... // other variables
while 1
{
$velocity = get $car velocity
$gear = get $car gear
if $velocity > lookupShift($shiftarray, $throttle, $gear, $gear+1)
{
set $car gear ($gear + 1)
}
else if $velocity < lookupShift($shiftarray, $throttle, $gear, $gear-1)
{
set $car gear ($gear - 1)
}
// then include torque converter code here, other transmission function, etc.
interrupt
}
If you can see an easier way to make the functions work, or have a request for another type of lookup, now's the time to tell me Still need to work out the exact format of the stored shift tables, and the more I know what it'll be used for the better I can manage.
The most basic table would have 2 speeds per gear change (no throttle shift-up, full throttle shift-up) which you could approximate pretty quickly. Just make sure shift-up speed is higher than shift-down speed at the same throttle in the next gear, cause then it'll pop back and forth.