More data in OutGauge packet

Discussion in 'Programming' started by Mattew, May 30, 2022.

  1. Mattew

    Mattew
    Expand Collapse

    Joined:
    Dec 1, 2013
    Messages:
    5
    Hello guys and girls.
    Been working on connecting real instrument cluster to game (second version that is) and while communication itself is working fine (UDP through WiFi) I do find the current amount of data from the game very lacking at the best. I would like to have more data in outgauge packed to get more use of my cluster's indicators and custom lcd.

    Is it possible to add more things? Or how to do it. I did try some experimenting with outgauge.lua but no success, resulting in a bunch of lua exceptions when loaded.

    I am looking for various things like basic fog lights or low beam, low fuel indicator, 4x4 modes with Hi-Lo, diff locks. More complicated stuff like esc modes (with separate active and on/off flags), damage to various parts like engine damage flags to trigger CEL light, brakes damage or steering damage to light up proper indicators. Maybe even a flat tire flag to show the TPS indicator.

    I did dig through lua files and for most things mentioned I did find what looks like appropriate data to use. Check engine lights do exist for instance. Fog lights, diff locks exist too. Most damage indicators exist in some form. Also I did come across gaugeData.electrics.* which are used to control indicators on dash in-game I presume? That contains a lot of useful data .


    Make the question short: how to get more data out of the game into an outgauge data packet?

    1. It is something that devs have to do?

    2. Modifying original outgauge.lua with more stuff (not worked for me so far)?

    3. Learn more of lua programming and write some custom telemetry data output plugin like outgauge if possible?

    Any input is much appreciated! Ty!


    Btw, abs indicator do not work at all now.
     
  2. Mattew

    Mattew
    Expand Collapse

    Joined:
    Dec 1, 2013
    Messages:
    5
    Well answering my own question. It is indeed possible to get more stuff into OutGauge packet. Digging thru lua files and messing with outgauge.lua it self I was able to add fog lights, low beams, 4wd mode, transfercase range mode, TPMS (flat tire). Trying to get low fuel, checkengine light and esc off indicators to work and looking for diff locks and how to get esc modes. Also while working on outgague.lue I did find this file kinda outdated.
     
    • Like Like x 1
  3. angelo234

    angelo234
    Expand Collapse
    Junior Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    433
    Sorry for getting to you late but yeah the outgauge stuff is pretty old. And yes you can send over pretty much anything that you would like from BeamNG .

    Here's how you get some of the things you are looking for if you haven't figured them out yet (are you looking specifically for a flag when ESC is fully deactivated or just when the ESC light is activated?):
    Code:
    electrics.values.lowfuel -- lowfuel light enabled, boolean
    electrics.values.checkengine -- check engine light enabled, boolean
    electrics.values.esc -- esc light enabled, number (0 = light off, 1 = light on)
    electrics.values.escActive -- esc active, bool
    electrics.values.abs -- abs light enabled, number (0 = light off, 1 = light on)
    electrics.values.absActive -- abs active, number (0 = inactive, 1 = active)
    
    For the diff locks, what exactly would you like? Let me know if you need anything else :)
     
    #3 angelo234, Jun 16, 2022
    Last edited: Jun 19, 2022
    • Like Like x 1
    • Agree Agree x 1
  4. Mattew

    Mattew
    Expand Collapse

    Joined:
    Dec 1, 2013
    Messages:
    5
    Thank you very much for info. I did figured out some of data, but even you little input help clarify things. I did not know some values are numbers and some are booleans. Fixed bunch of things now!
    About ESC, my cluster have one indicator for when esc is working (doing ist' thing) and one when esc if turned of. So what I am looking for to know when esc is on and working (we have that in "electrics.values.esc" and "electrics.values.tcs" and when esc is turned off. I tried use "electrics.values.escActive" but it seems to have almost similar behaviour to "electrics.values.esc". Also is there way to know current ESC mode? I plan for LCD so I can show current esc mode. Only thing I find is "electrics.values.dseColor = currentESCConfiguration.activeColor" that could be used in someway but since I have no idea what values it returns no luck getting it wotking.
    About diffs, again I have indicators for rear diff lock and center diff lock. So far I am not aware we have center diff that can be locked (even I did came after mentions of center diff in lua files) but rear we have. Simple I am looking for state "locked/unlocked". And talking about drivetrain, I run in little issue wiht 4wd/range indicators. They do work but on cars without 4wd/range both outputs are keept HIGH, thus lights up both indicators as like functions have been activated.
    One more question, is there outpus to get various damages? I would like to activate CEL sooner since game do not care about some damages that would trigger CEL in real car. For instance some cars can have induction system easly damaged resulting in loss of intake pressure that would cause CEL to lights up.

    Thanks again for info provided and thanks for any futher info!
     
  5. angelo234

    angelo234
    Expand Collapse
    Junior Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    433
    Here's stuff for ESC stuff, I'll post later for the other things you mentioned:

    For whether ESC is enabled or disabled (I know its kinda a lot of code since newer ESC systems don't expose the data unfortunately so its a workaround/hack :( ):
    Code:
    local escEnabled = false
    
    if controller.getController("esc") then
      -- For older ESC systems
      escEnabled = controller.getController("esc").getCurrentConfigData().escEnabled
    
    elseif controller.getController("driveModes") then
      -- For newer ESC systems
      escEnabled = true
     
      local currentMode = controller.getController("driveModes").serialize().activeDriveModeKey
    
      for k,t in pairs(v.data.driveModes.modes[currentMode].settings) do
        if t[2] and t[2].controllerName == "yawControl" then
          escEnabled = t[2].isEnabled
        end
      end
    end
    
    print("ESC Enabled: " .. tostring(escEnabled))
    For Current ESC/TC Mode:
    Code:
    local escMode = nil
    
    if controller.getController("esc") then
      -- For older ESC systems
      escMode = controller.getController("esc").getCurrentConfigData().name
    
    elseif controller.getController("driveModes") then
      -- For newer ESC systems
      local currentMode = controller.getController("driveModes").serialize().activeDriveModeKey
    
      escMode = v.data.driveModes.modes[currentMode].name
    end
    
    print("ESC Mode: " .. tostring(escMode))
     
  6. angelo234

    angelo234
    Expand Collapse
    Junior Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    433
    For front and rear diffs:
    Code:
    local diffFrontState, diffRearState -- will return "locked" or "open" or nil if didn't find differentials
    
    for k,v in pairs(powertrain.getDevicesByType("differential")) do
      if v.name == "differential_F" then
        diffFrontState = v.mode
      elseif v.name == "differential_R" then
        diffRearState = v.mode
      end
    end
    
    print(diffFrontState .. ", " .. diffRearState)
    For 4WD stuff (seems to hold correct values for me when trying out different vehicles with and w/o 4WD):
    Code:
    electrics.values.mode4WD -- 4WD Enabled, number (0,1) or nil if doesn't have 4WD
    electrics.values.modeRangeBox -- Low Range Enabled, number (0,1) or nil if doesn't have 4WD
    Will post the last stuff later :)
     
  7. Mattew

    Mattew
    Expand Collapse

    Joined:
    Dec 1, 2013
    Messages:
    5
    Oh, so much information! Thank you very much! Now I have o lot of work to do, heh. ESC stuff looks very complex to be honest, hopefully it will be worth it. I could not figure out any of it on my own. I did look basically only at "electrics.values" for data :)
    For 4WD/Range I do use values you mentioned and if you say they work as expected then problem maybe with my implementation. It's high possible that I wrongly read and/or implement value into data packet. I do learn LUA and C++ on the fly :D
    Again, thanks very much. Information you provided is golden!

    Edit: 4WD stuff fixed! As mentioned, wrong implementation in outgauge protocol.
    Edit2: DiffLocks successfully added!
    Edit3: Implemented all ESC code. Have esc mode shown on my prototyping lcd now. Later I will moddify code so normal esc/tc light won't be on when esc/tc is turned off.
     
    #7 Mattew, Jun 21, 2022
    Last edited: Jun 21, 2022
    • Like Like x 1
  8. angelo234

    angelo234
    Expand Collapse
    Junior Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    433
    Hey thats great to hear its working for you :) Yeah it was a little difficult for me to find out the information too since Vehicle Lua stuff isn't my forte ;)

    For the vehicle damage, this function will output a table of all the parts that have been damaged (parts that have not been damaged won't be part of the list):
    Code:
    beamstate.getPartDamageData()
    Example of the contents of the table:
    a.png

    Btw, you can use the dump() function to print out the contents of a table like how I did in the screenshot.
     
    • Like Like x 1
  9. Mattew

    Mattew
    Expand Collapse

    Joined:
    Dec 1, 2013
    Messages:
    5
    Even if it isn't you know way more than me and already provided valuable information! And you know where to look for specific data, while I was just staring at various lua files not knowing exactly what I am looking at :D Some stuff I didn't even believe to get ever working but now it is possible.

    I played with damage function. It does provide necessary information. I will have to write some code to filter out what I need and make it using some kind of wildcard since parts seem to be tied to specific vehicles, so use of exact names is not possible. But the amount of data is good, in theory I can even make the bulb fail indicator to work! If the tail light or headlight go over some % of damage, turn on the indicator. Question: Is there such a command available for drivetrain and engine as well? Thanks!
     
  10. esesel

    esesel
    Expand Collapse

    Joined:
    Feb 18, 2019
    Messages:
    583
    unrelated but congratulations for getting hired! i love your mods...
     
    • Like Like x 1
  11. angelo234

    angelo234
    Expand Collapse
    Junior Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    433
    After more exploring around, I found some more information!

    You can use this function to get the damage of a bunch of powertrain parts without needing to do any parsing of the part names:
    Code:
    damageTracker.getDamage(group, name)
    Where group refers to one of the "parent" variables below (e.g. body, energyStorage, engine) and name refers to the child variable inside of the group

    This is the list of damage variables with example values:
    Code:
    {
      body = {
        FL = 0,
        FR = 0,
        ML = 0,
        MR = 0,
        RL = 0,
        RR = 0
      },
      energyStorage = {
        mainTank = false
      },
      engine = {
        blockMelted = false,
        catastrophicOverTorqueDamage = false,
        catastrophicOverrevDamage = false,
        coolantHot = false,
        cylinderWallsMelted = false,
        engineDisabled = false,
        engineHydrolocked = false,
        engineIsHydrolocking = false,
        engineLockedUp = false,
        engineReducedTorque = false,
        exhaustBroken = false,
        headGasketDamaged = false,
        impactDamage = false,
        mildOverTorqueDamage = false,
        mildOverrevDamage = false,
        oilHot = false,
        oilStarvation = false,
        overRevDanger = false,
        overTorqueDanger = false,
        pistonRingsDamaged = false,
        radiatorLeak = false,
        rodBearingsDamaged = false,
        turbochargerDamaged = false,
        turbochargerHot = false
      },
      powertrain = {
        clutch = false,
        differential_R = false,
        driveshaft = false,
        gearbox = false,
        mainEngine = false,
        spindleFL = false,
        spindleFR = false,
        spindleRL = false,
        spindleRR = false,
        torsionReactorR = false,
        transfercase = false,
        wheelaxleRL = false,
        wheelaxleRR = false
      },
      wheels = {
        FL = false,
        FR = false,
        RL = false,
        RR = false,
        brakeFL = false,
        brakeFR = false,
        brakeOverHeatFL = 0,
        brakeOverHeatFR = 0,
        brakeOverHeatRL = 0,
        brakeOverHeatRR = 0,
        brakeRL = false,
        brakeRR = false,
        tireFL = false,
        tireFR = false,
        tireRL = false,
        tireRR = false
      }
    }
    So for example you can do as such:
    Code:
    local mildOverrevDamage = damageTracker.getDamage("engine","mildOverrevDamage")
    local radiatorLeak = damageTracker.getDamage("engine","radiatorLeak")
     
    #11 angelo234, Jun 26, 2022
    Last edited: Jun 27, 2022
  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