Active AWS

Discussion in 'Programming' started by SlickNick924, Jun 1, 2020.

  1. SlickNick924

    SlickNick924
    Expand Collapse

    Joined:
    Aug 19, 2018
    Messages:
    300
    I am currently working on an SVX active all-wheel steer system and I am trying to create my own all-wheel steer script. This is being used with a modified ETK multi-link rear suspension. With little knowledge of the actual mathematics behind all-wheel steer and plain guessing, is this effective at all? The desired effect is that the aws system recognizes if the car is making a hard turn or over/understeering, so air speed is averaged with wheel speed and yaw, pitch, and roll are recorded.

    Code:
    -- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
    -- If a copy of the bCDDL was not distributed with this
    -- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt
    local M = {}
    
    local function onInit()
        electrics.values['4ws'] = 0
    end
    
    local function updateGFX(dt)
        if not electrics.values['steering_input'] then return end
        local speed = electrics.values["wheelspeed"]
        local dirVector = obj:getDirectionVector()
        local dirVectorUp = obj:getDirectionVectorUp()
        local airSpeed = electrics.values["airspeed"] / 2
        local steer = -electrics.values['steering_input']
        local roll = math.abs(dirVectorUp.x * -dirVector.y + dirVectorUp.y * dirVector.x) / 2
        local pitch = math.abs(dirVector.z)
        local absSteer = math.abs(steer)
        local rws = 0  
      
        if airSpeed <= 24 then
            speed = speed + (speed * 0.75)
        end
      
        if math.abs(roll) > pitch then
        rws = (((speed + airSpeed) / 2 - 12) / 10) * absSteer
        else  
        rws = (math.sin(absSteer * 1) * math.cos((absSteer * 3.3))) * 1.21
        end  
      
        rws = rws * fsign(steer) --Use the sign of the steering input to know the sign of rws output
      
        electrics.values['4ws'] = rws
    end
    
    -- public interface
    M.onInit      = onInit
    M.onReset     = onInit
    M.updateGFX = updateGFX
    
    return M
    
     
    #1 SlickNick924, Jun 1, 2020
    Last edited: Jun 1, 2020
    • Like Like x 2
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice