Display the length of a beam in real time?

Discussion in 'Programming' started by mrkelkel, Mar 15, 2023.

  1. mrkelkel

    mrkelkel
    Expand Collapse

    Joined:
    Aug 18, 2013
    Messages:
    61
    Hi y'all,

    So I'm trying to develop an UI app to display the displacement of a coilover in real time; a coilover is just two nodes joined together with a beam in the Jbeam file, so I'm thinking the most straightforward approach would be to just display the length of this beam. The vehicle would drive through corners, run over bumps, and the UI app would show the displacement in real time.

    Then I did some reading into the Streams function, and didn't find anything regarding suspension data. So would I be able to add a stream that spits out the beam length data, or a stream that outputs the position of the two coilover nodes? (I'll calculate the length outside of BeamNG) And any ideas on how to approach this?

    Sorry if I'm mixing up some functions/concepts :)
     
  2. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,442
    Obj:getBeamLength(cid) - current distance between nodes
    Obj:getBeamLengthRefRatio(cid) - ratio between the current and starting distance between nodes (with precompression)
    Obj:getBeamLengthRestRatio(cid) - ratio between the current and starting distance between nodes (no precompression)
    Obj:getBeamRefLength(cid) - starting distance between nodes (with precompression)
    Obj:getBeamRestLength(cid) - starting distance between nodes (no precompression)
     
    • Like Like x 1
  3. mrkelkel

    mrkelkel
    Expand Collapse

    Joined:
    Aug 18, 2013
    Messages:
    61
    Thanks so much, gonna give this a look
     
  4. mrkelkel

    mrkelkel
    Expand Collapse

    Joined:
    Aug 18, 2013
    Messages:
    61
    Another quick question:
    So I'm implementing the Obj:getBeamLength(cid) function on the front left coilover of my vehicle, but I'm having difficulty finding the correct value for cid. The front coilover is defined as nodes "sf6","a9" and has its name defined as "name":"damper_FL", but both these values do not work when placed directly in Obj:getBeamLength(cid).

    Where would I define the cid? Thanks!
     
  5. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,442
    Each beam has its own cid that is invisible on the Jbeam side, you need to make a loop through all beams of the vehicle and find the cid manually, for example:
    Code:
    local yourCid = nil
    for _, b in pairs (v.data.beams) do
      if b.name = "damper_FL" then yourCid = b.cid end
    end 
     
    • Like Like x 1
  6. mrkelkel

    mrkelkel
    Expand Collapse

    Joined:
    Aug 18, 2013
    Messages:
    61
    I see, no wonder the LUA didn't throw out any errors when I put a random number in the cid field. I tried putting 1 just for giggles, it ran with no issues but I had no way of seeing which beam was 1.
     
  7. mrkelkel

    mrkelkel
    Expand Collapse

    Joined:
    Aug 18, 2013
    Messages:
    61
    So the beam name approach ("name":"damper_FL") seems to be a dead end. The loop doesn't seem to be able to find the damper's beam, and the cid values keep coming back as nil. I've tried to approach this by comparing the node names, but so far no luck.

    Code:
    for _, beam in pairs (v.data.beams) do
               if beam.id2 == "a9" and beam.id1 == "sf6" then
                   yourCid = beam.cid
               end
           end

    Does anything look off?
     
  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