//Focus on the car used by the script owner
rcar $car=get scriptowner car
 
shared float $slipratio0
shared float $slipratio1
shared float $slipratio2
shared float $slipratio3
shared float $brake0stat = 2650
shared float $brake1stat = 2650
shared float $brake2stat = 2650
shared float $brake3stat = 2650
shared float $brake0 = 2650
shared float $brake1 = 2650
shared float $brake2 = 2650
shared float $brake3 = 2650
shared float $wheel0optimum = -0.16
shared float $wheel1optimum = -0.16
shared float $wheel2optimum = -0.15
shared float $wheel3optimum = -0.15
 
//Base frequency at speed for an 'off' cycle (total on/off cycle would be double this value in ms)
shared float $abs_base = 50
//At what speed (m/s) to start to reduce the frequency of the ABS
shared float $abs_slow = 12
//Factor that slows the ABS down linearly from the start of speed reduction to 0 (bigger = slower)
shared float $abs_slow_factor = 22
 
 
shared float $brake
shared float $speed
 
shared float $abs_speed
 
 
while 1
{
$brake = get $car brake
 
$speed = get $car tachovelocity
$abs_speed = $abs_base 
if $speed < $abs_slow
{
$abs_speed += ($abs_slow - $speed) * $abs_slow_factor
}

 
 
$slipratio0 = get $car wheel 0 slipratio
$slipratio1 = get $car wheel 1 slipratio
$slipratio2 = get $car wheel 2 slipratio
$slipratio3 = get $car wheel 3 slipratio
 
//WHEEL0
if $slipratio0 < $wheel0optimum
{
if $brake0 > 0
{
$brake0 -= ($brake0stat / $abs_speed)
}
else
{
$brake0 = 0
}
}
else
{
if $brake0 < $brake0stat
{
$brake0 += ($brake0stat / $abs_speed)
}
else
{
$brake0 = $brake0stat
}
}
 
//WHEEL1
if $slipratio1 < $wheel1optimum
{
if $brake1 > 0
{
$brake1 -= ($brake1stat / $abs_speed)
}
else
{
$brake1 = 0
}
}
else
{
if $brake1 < $brake1stat
{
$brake1 += ($brake1stat / $abs_speed)
}
else
{
$brake1 = $brake1stat
}
}
 
//WHEEL2
if $slipratio2 < $wheel2optimum
{
if $brake2 > 0
{
$brake2 -= ($brake2stat / $abs_speed)
}
else
{
$brake2 = 0
}
}
else
{
if $brake2 < $brake2stat
{
$brake2 += ($brake2stat / $abs_speed)
}
else
{
$brake2 = $brake2stat
}
}
 
//WHEEL3
if $slipratio3 < $wheel3optimum
{
if $brake3 > 0
{
$brake3 -= ($brake3stat / $abs_speed)
}
else
{
$brake3 = 0
}
}
else
{
if $brake3 < $brake3stat
{
$brake3 += ($brake3stat / $abs_speed)
}
else
{
$brake3 = $brake3stat
}
}
 
set system "car0.wheel0.max_braking" to $brake0;
set system "car0.wheel1.max_braking" to $brake1;
set system "car0.wheel2.max_braking" to $brake2;
set system "car0.wheel3.max_braking" to $brake3;
 
interrupt
}