VE Lua Documentation

Press F to search!

initSecondStage

Definition


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

local function initSecondStage()
  if not v.data.refNodes or not v.data.nodes or not v.data.nodes[v.data.refNodes[0].ref] then
    return
  end

  M.wheels = {}
  M.wheelIDs = {}
  M.wheelCount = 0
  invWheelCount = 0
  invSpeedoWheelCount = 0
  speedoWheelCount = 0
  M.wheelPower = 0

  M.rotators = {}
  M.rotatorIDs = {}
  M.rotatorCount = 0

  local avgWheelPos = vec3(0, 0, 0)
  for _, rotator in pairs(M.wheelRotators) do
    if rotator.brakeTorque > 0 then
      local wheelNodePos = v.data.nodes[rotator.node1].pos --find the wheel position
      avgWheelPos = avgWheelPos + wheelNodePos --sum up all positions
    end
    if rotator.isSpeedo == 1 then
      speedoWheelCount = speedoWheelCount + 1
    end
    if rotator.rotatorType == "wheel" then
      M.wheels[M.wheelCount] = rotator
      M.wheelCount = M.wheelCount + 1
      M.wheelIDs[rotator.name] = rotator.wheelID
    elseif rotator.rotatorType == "rotator" then
      M.rotators[M.rotatorCount] = rotator
      M.rotatorCount = M.rotatorCount + 1
      M.rotatorIDs[rotator.name] = rotator.wheelID
    end
  end

  initialWheelRotatorCountDec = M.wheelRotatorCount - 1
  initialWheelCountDec = M.wheelCount - 1
  initialRotatorCountDec = M.rotatorCount - 1
  invWheelCount = M.wheelCount > 0 and 1 / M.wheelCount or 0
  invSpeedoWheelCount = speedoWheelCount > 0 and 1 / speedoWheelCount or 0
  initialSpeedoWheelCount = speedoWheelCount
  avgWheelPos = avgWheelPos * invWheelCount --make the average of all positions

  local vectorForward = vec3(v.data.nodes[v.data.refNodes[0].ref].pos) - vec3(v.data.nodes[v.data.refNodes[0].back].pos) --vector facing forward
  local vectorUp = vec3(v.data.nodes[v.data.refNodes[0].up].pos) - vec3(v.data.nodes[v.data.refNodes[0].ref].pos)
  local vectorRight = vectorForward:cross(vectorUp) --vector facing to the right

  for _, rotator in pairs(M.wheelRotators) do
    local wheelNodePos = vec3(v.data.nodes[rotator.node1].pos) --find the wheel position
    local wheelVector = wheelNodePos - avgWheelPos --create a vector from our "center" to the wheel
    local dotLeft = vectorRight:dot(wheelVector) --calculate dot product of said vector and left vector

    if dotLeft >= 0 then
      rotator.ownWheelSide = "right"
      rotator.oppositeWheelSide = "left"
    else
      rotator.ownWheelSide = "left"
      rotator.oppositeWheelSide = "right"
    end
  end

  for i = 0, initialWheelCountDec do
    local wd = M.wheels[i]

    wd.tireVolume = 0
    if wd.hasTire then
      local hubArea = pi * wd.hubRadius * wd.hubRadius
      local overallArea = pi * wd.radius * wd.radius
      local tireArea = overallArea - hubArea
      wd.tireVolume = tireArea * wd.tireWidth
    end

    wd.dynamicRadiusSmoother = newTemporalSmoothingNonLinear(0.5, 0.5)
    wd.dynamicRadiusSmoother:set(wd.radius)
    wd.dynamicRadius = wd.radius

    damageTracker.setDamage("wheels", wd.name, false)
    damageTracker.setDamage("wheels", "tire" .. wd.name, false)
  end

  for _, v in ipairs(virtualAirspeedMaps) do
    local gainSum = (v.acceleration + M.wheelCount * v.wheelCoef)
    v.invGainSum = gainSum > 0 and 1 / gainSum or 0
  end

  airspeedMapTimer = 0
  lastBrake = 0
  lastVirtualAirspeed = 0
  lastAccSign = 1
  airspeedResetTimer = 0

  --dump(M.wheels)
  --dump(M.rotators)
end

Callers

@/lua/vehicle/controller/drivingDynamics/supervisors/components/brakeControl.lua

local function initSecondStage(jbeamData)
  --todo create jbeam param to determine if component should be used as TC or ESC component
@/lua/vehicle/controller/drivingDynamics/actuators/activeCenterDiffLock.lua

local function initSecondStage(jbeamData)
  if not CMU then
@/lua/vehicle/controller/gauges/analogOdometer.lua

local function initSecondStage(jbeamData)
  --merge config data from multiple parts so that some things can be defined in sub-parts. section name needs to be "configuration_xyz"
@/lua/vehicle/controller/pneumatics/autoLevelSuspension.lua

local function initSecondStage(jbeamData)
  local actuatorName = jbeamData.actuatorName or "airbags"
@/lua/vehicle/controller/drivingDynamics/supervisors/components/aeroControl.lua

local function initSecondStage(jbeamData)
  local yawControl = CMU.getSupervisor("yawControl")
@/lua/vehicle/controller/drivingDynamics/actuators/electronicSplitShaftLock.lua

local function initSecondStage(jbeamData)
  if not CMU then
@/lua/vehicle/controller/gauges/genericGauges.lua

local function initSecondStage(jbeamData)
  local displayData = jbeamData.displayData
@/lua/vehicle/controller/controllerTemplate.lua

-- local function initSecondStage(jbeamData)
-- end
@/lua/vehicle/controller/drivingDynamics/actuators/activeDiffLock.lua

local function initSecondStage(jbeamData)
  if not CMU then
@/lua/vehicle/controller/tirePressureControl.lua

local function initSecondStage(jbeamData)
  local mode = jbeamData.mode or "manualControl"
@/lua/vehicle/controller/drivingDynamics/supervisors/components/awdControl.lua

local function initSecondStage(jbeamData)
  local awdActuatorName = jbeamData.awdActuatorName or "electronicSplitShaftLock"
@/lua/vehicle/input.lua

local function initSecondStage()
  --scale rates based on steering wheel degrees
@/lua/vehicle/controller/drivingDynamics/supervisors/tractionControl.lua

local function initSecondStage(jbeamData)
  tractionControlledWheelGroups = {}
@/lua/vehicle/controller.lua
  if c.initSecondStage then
    c.initSecondStage(controllerJbeamData[controller.name])
  end

local function initSecondStage()
  for _, v in pairs(sortedControllers) do
    if v.initSecondStage then
      v.initSecondStage(controllerJbeamData[v.name])
    end
    elseif v.initSecondStage then
      v.initSecondStage(controllerJbeamData[v.name])
    end
@/lua/vehicle/controller/drivingDynamics/CMU.lua

local function initSecondStage()
  subControllerLookup = {}
@/lua/vehicle/controller/esc.lua

local function initSecondStage()
  escPulse = 0
@/lua/vehicle/controller/drivingDynamics/supervisors/slipProviders/virtualSpeedSlip.lua

local function initSecondStage(jbeamData)
  local tractionControl = CMU.getSupervisor("tractionControl")
@/lua/vehicle/controller/drivingDynamics/actuators/electronicDiffLock.lua

local function initSecondStage(jbeamData)
  if not CMU then
@/lua/vehicle/controller/drivingDynamics/supervisors/components/motorTorqueControl.lua

local function initSecondStage(jbeamData)
  local useForTractionControl = jbeamData.useForTractionControl == nil and true or jbeamData.useForTractionControl
@/lua/vehicle/controller/drivingDynamics/actuators/activeDiffBias.lua

local function initSecondStage(jbeamData)
  if not CMU then
@/lua/vehicle/controller/drivingDynamics/supervisors/yawControl.lua

local function initSecondStage(jbeamData)
  electrics.values.hasESC = true
@/lua/vehicle/controller/drivingDynamics/supervisors/components/diffControl.lua

local function initSecondStage(jbeamData)
  local frontDiffName = jbeamData.frontDiffName or "lockFront"
@/lua/vehicle/controller/drivingDynamics/supervisors/yawProviders/STMEstimate.lua

local function initSecondStage(jbeamData)
  local yawControl = CMU.getSupervisor("yawControl")
@/lua/vehicle/controller/drivingDynamics/sensors/vehicleData.lua

local function initSecondStage(jbeamData)
  M.isActive = false
@/lua/vehicle/main.lua
  profilerPushEvent("3.3 init - second stage")
  wheels.initSecondStage()
  controller.initSecondStage()
  wheels.initSecondStage()
  controller.initSecondStage()
  drivetrain.init()
  props.init()
  input.initSecondStage() -- needs to go after sounds & electrics
  recovery.init()