vehicle-lua -> set brakingTorque?

Discussion in 'Programming' started by slimSpencer, Feb 2, 2015.

  1. slimSpencer

    slimSpencer
    Expand Collapse

    Joined:
    Jan 22, 2014
    Messages:
    3
    hello @all,

    first, i want to say that i'm quite new to LUA (coming from VB) and have not really any deep insight/understanding of the beamNG structure...

    I'm currently working on some driving assistance systems (Traction Control and maybe ESC). I try to achieve this using a custom lua-file in vehicle_dir\lua\myfile.lua.

    What i realized so far is that i can read/set many 'interesting' vars inside updateGFX-function per frame.
    For example, i managed to write a simple traction control reading wheel speed from drivetrain.wheels and setting drivetrain.throttle accordingly.

    Now i got 2 questions/problems:

    1) setting brakingTorque doesn't seem to work.
    simple example - i would expect this code to keep brakingTorque at 500 continously but there's no braking applied at all...
    PHP:
    ...
    local function updateGFX(dt)
        for 
    n,wd in pairs(drivetrain.wheels) do
            
    wd.obj.brakingTorque 500    
        end
        
        msg 
    ""
        
    for n,wd in pairs(drivetrain.wheels) do
            
    msg msg .. wd.name .. "->" .. string.format("%.1f"wd.obj.brakingTorque) .. ", "                    
        
    end    
        gui
    .message(msg)            
    end
    ...
    2) reading vars from UI-app
    How can i read vars from my vehicle-lua-file inside my UI-app?
    PHP:
    ...
    local function updateGFX(dt)
        
    testvar "hello"
    end
    ...
    How to get "hello" displayed in my app?


    Thanks in advance and best regards :)

    Spencer
     
  2. Miura

    Miura
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    311
    Maybe it would work with "brakeTorque" instead? It's a bit confusing, but drivetrain.lua uses both "brakeTorque" and "brakingTorque".

    I'm using drivetrain.wheels[wheelID].brakeTorque for brake control, and a code that matches the wheelID with the wheel name.

    I don't know anything about UI apps, so I can't help with that.
     
  3. CarlosAir

    CarlosAir
    Expand Collapse

    Joined:
    Nov 16, 2013
    Messages:
    336
    For the UI app stuff, you'll need to edit the guistreams.lua file inside the main lua folder. Which is the file in charge of sending the needed variables from the lua "system" to the UI.
    If you take a look in the file, you'll see it's divided in the same info sections as used in the apps (electrics, wheelInfo, sensors...), you might want to modify what information is sent on one of the categories, or even create your own "section" if needed :p.

    Ask if you need any further help.
     
    #3 CarlosAir, Feb 2, 2015
    Last edited: Feb 2, 2015
  4. slimSpencer

    slimSpencer
    Expand Collapse

    Joined:
    Jan 22, 2014
    Messages:
    3
    @Miura
    brakeTorque seems to only the change the maximum brake power for the wheels, it will not apply them by itself (which i thought brakingTorque can).
    But that's fine, i just have to apply brakes with drivetrain.brake and then change brake force distribution temporarily with brakeTorque. (need to do that for ESC to brake individual wheels w/o user input).
    Thanks for the hint! :)

    @CarlosAir
    Thank you, too - will look into that later

    BR
     
  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