VE Lua Documentation

Press F to search!

updateABSCoef

Definition


-- @/lua/vehicle/wheels.lua:504

local function updateABSCoef(wd, brake, invAirspeed, airspeed, airspeedCutOff, dt)
  if brake > 0 then
    wd.absTimer = wd.absTimer - dt
    if wd.absTimer <= 0 then
      local absDT = max(dt, wd.absTime) --if the ABS frequency is smaller than the physics step, we need to use the right dt here
      wd.absTimer = wd.absTimer + wd.absTime
      local slipRatio = min(max((airspeed - abs(wd.angularVelocityBrakeCouple * wd.radius * wd.wheelDir)) * invAirspeed, 0), 1)
      local slipRatioTarget = min(2 * invAirspeed + wd.slipRatioTarget, 1)
      local slipError = slipRatioTarget - slipRatio
      local slipErrorDerivative = (slipError - wd.lastSlipError) / absDT
      wd.slipErrorIntegral = max(min(wd.slipErrorIntegral + slipError * absDT, 1), -1)
      local ABSCoef = airspeedCutOff and min(max(slipError * 5 + wd.slipErrorIntegral * 0.3 + slipErrorDerivative * 0.05, 0), 1) or 1

      wd.absActive = brake > 0.1 and ABSCoef < 0.9
      absActive = wd.absActive or absActive
      absActiveLastPulse = absActive

      brakeABSCoefLimitCache[wd.oppositeWheelSide] = max(min(ABSCoef * 1.15, 1), brakeABSCoefLimitCache[wd.oppositeWheelSide])
      ABSCoef = min(ABSCoef, brakeABSCoefLimits[wd.ownWheelSide])

      wd.lastABSCoef = ABSCoef
      wd.lastSlipError = slipError
      return ABSCoef
    else
      brakeABSCoefLimitCache[wd.oppositeWheelSide] = brakeABSCoefLimits[wd.oppositeWheelSide]
      absActive = absActive or absActiveLastPulse
      return wd.lastABSCoef
    end
  else
    wd.slipErrorIntegral = 0
    wd.lastSlipError = 0
    wd.absActive = false
    absActiveLastPulse = false
    brakeABSCoefLimitCache[wd.oppositeWheelSide] = 1
    return 0
  end
end

Callers

@/lua/vehicle/controller/pneumatics/airbrakes.lua
local function updateWheelBrakeABS(wd, brake, invAirspeed, airspeed, airspeedCutOff, dt)
  local absCoef = wheels.updateABSCoef(wd, brakeTorqueCoef, invAirspeed, airspeed, airspeedCutOff, dt)
  local brakeCoef = max(brakeTorqueCoef * absCoef, springTorqueCoef)
@/lua/vehicle/wheels.lua
    local nonABSBrakingTorque = wd.brakeTorque * (min(brake, brakeInputSplit) + max(brake - brakeInputSplit, 0) * wd.brakeSplitCoef)
    local absCoef = updateABSCoef(wd, brake, invAirspeed, airspeed, airspeedCutOff, dt)
    local desiredBrakingTorque = nonABSBrakingTorque * absCoef