1. Stuck, Having problems with creating your mod? Let us help you: Mod Support

Data collection and logging to a file

Discussion in 'Programming' started by Supermuskox, Oct 31, 2018.

  1. Supermuskox

    Supermuskox
    Expand Collapse

    Joined:
    Jan 18, 2018
    Messages:
    6
    Hey everyone, thanks for taking the time to read my post!

    I'm doing research in the accuracy of games their physics engines and I want to test this game as well. Problem is, I have no clue how to log the data to an external file for analysis. I was hoping there would be some kind of way to export to a CSV file, but thus far I have not found helpful posts on the forum. One thread that had what I wanted ended on an unsatisfactory note, leaving me here. I have looked through the wiki, and I did see this post. It looks like what they use to make UI elements, but maybe it can be used to export data? I don't need to log a lot of data. Preferably just time, speed, coordinates, and g-forces. I did see all of these values in the Sensors Streams, but I'm clueless as what to do next.

    I hope some of you know what I mean and know of a way to fix it.
    Thanks for reading!
     
  2. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    1,175
    Hey,
    what kind of data do you want to export?
     
  3. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,738
    You can convert json to csv:
    https://json-csv.com/

    From UI app list you can find log available stream app which you can use to log json:
    upload_2018-11-1_16-18-25.png

    I guess it records sample each second or so.

    @Diamondback he mentioned "time, speed, coordinates, and g-forces" in the post.
     
  4. Supermuskox

    Supermuskox
    Expand Collapse

    Joined:
    Jan 18, 2018
    Messages:
    6
    Thanks for the replies! I appreciate you guys helping me.

    Anyway, I have looked into the UI app, and it seems like the thing I need. I do believe that the exported file is in "Documents/BeamNG.Drive/loggedStreams.json" and putting it through the converter gave me pretty much all the data, but as far as I could see, only the maximum and minimum values. There are also some ExampleVals, but I'm unsure as to what they do. Graphing the data leaves a lot to be desired.

    Here are some links to the Replay, the Excel and the CSV file. Please note that for the replay I used an automation car. Link can be found here: https://www.beamng.com/resources/bmw-serie-5-2017.6235/
    As for the files, here is a Mediafire folder. The forum would not let me upload my Csv file. http://www.mediafire.com/folder/akrspgl9j7s4s/BeamNG

    I would love to be able to leave out undesired information, like the lights_state, but it's no problem to filter it out afterwards. The most important thing right now is to log data in time intervals. Something like every few frames, to get some nice and accurate graphs. Would that just require some spamming of the logging button or is there another way?
     
  5. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,738
    I think you need @Diamondback for that, he can be busy so you might need to send private message to him.
    There is no possibility to change logging interval that I know of, current logging options are bit less than in other simulators in that sense, but I do hope they will get better in a future.


    What I know is that you can use LUA to print values to file for example and that can be run every frame, but to make that happen requires of course bit of coding. User Arcanox has probably skills needed, not sure how much time or interest he has, but asking him is option too.

    This post however has pretty good information that might help you if all else fails:
    https://www.beamng.com/threads/lua-help.56996/#post-905294

    I'm quite curious of your findings between different games, will there be published article or paper somewhere at sometime?
     
  6. Arcanox

    Arcanox
    Expand Collapse

    Joined:
    Aug 22, 2018
    Messages:
    104
    Supermuskox messaged me about this and I'd be happy to help. I can probably write a script to do this but I may not have time for at least a week, but I can give the general premise. It's probably easiest to do this from a Lua controller rather than a UI app simply because there's less boilerplate required for the controllers. I'm also not positive that the UI apps can write files. I know Angular apps can't natively write files, but there may be a BeamNG API that's provided that I'm not aware of. In the Lua controller, you'd want to open a file such that it gets wiped first, and close/reopen the file when the vehicle is reset (allowing the output stats to be reset). In the update method, you'd use the dt parameter to keep track of how much time has passed since the last log, and if it reaches the threshold to log a new value, do so. It'd be a simple task to write the logs to a CSV since it's a very simple text-based format. Using a controller would also allow keybinds to be set to start/stop/reset the logging, as opposed to a UI app which you would have to click (I don't believe UI apps receive direct keyboard events).
     
    • Like Like x 2
  7. Supermuskox

    Supermuskox
    Expand Collapse

    Joined:
    Jan 18, 2018
    Messages:
    6
    Thanks for posting! I have been trying to find the things I need and I think I've found them. All files mentioned from now are in ..\BeamNG.drive\lua\vehicle.

    Starting off with sensors.lua. This one contains almost everything needed. Line 12 to 14 define M.gx, M.gy and M.gz. Position is found.
    Second thing to log, speed. I have not found a variable that defines this, but the function getVelocity() seems to do the trick. Examples in scriptai.lua, ai.lua and bdebug.lua.
    According to the documentation, updateGFX(dt) should return DeltaTime as an argument, so that might be a way to get time logged.
    For writing the file, WriteFile() seems like the way to go. Should not be too hard.

    Problem is, I have no clue how to continue with this. Like, where do I put the Lua file? Or do I edit the existing Lua files? What code initializes the script? If anyone knows how to continue, please let me know.
    And to answer your question @fufsgfen, it's for a project I'm doing in school called a PWS or "profielwerkstuk". Which is basically a big research project you do at the end of Dutch high school. So, unfortunately no published research, but I can upload some nice graphs from the data I acquired. Deadline for the project is in about two weeks, so I guess you'll get to know pretty soon.
     
    • Informative Informative x 1
  8. Arcanox

    Arcanox
    Expand Collapse

    Joined:
    Aug 22, 2018
    Messages:
    104
    I can write a simple one next week; you'd want to put it in its own mod folder and attach it to a JBeam part. I can give you a place to start off and you can modify it as you see fit :)
     
    • Like Like x 1
  9. Supermuskox

    Supermuskox
    Expand Collapse

    Joined:
    Jan 18, 2018
    Messages:
    6
    With a lot of help from @Arcanox we created a script that can log data to a .csv file. Put the .zip file in your mods folder (Documents\BeamNG.drive\mods), or unpack it and put it in the unpacked folder (Documents\BeamNG.drive\mods\unpacked) if you want to edit the script. Default vehicle for logging is the ETK S Series, which is a modded vehicle. Be sure to edit the script if you want to log other vehicles and or other types of data.
    You can enable the script here:
    upload_2019-1-27_12-31-39.png

    Once again huge thanks to Arcanox, for putting it all together.




    Anyways I have made some graphs from the data I have collected. This is the result from slowing down two similar cars in real life and in BeamNG from 30km/h to 0.
    Real life:
    upload_2019-1-27_12-32-17.png
    Simulation:
    upload_2019-1-27_12-32-41.png

    Graphs are made in Dutch but I think they are self-explanatory.
    It's pretty interesting to see that BeamNG makes a little dip at around 2 m/s and I'm not sure what causes it. If anyone has a theory, please let me know, as I'm pretty interested myself.
     

    Attached Files:

  10. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,738
    Dip is probably because of nodes start to create more rolling resistance at that point, tires are not exactly round, but are like pieces of plank put toghether to resemble a wheel, so there is bit higher rolling resistance at very low speeds.

    At higher speeds that has no effect to rolling resistance anymore. You can also see this when you roll car slowly it kinda shakes, it is also possible to see if you enable debug view.

    Where most other sims have just one contact point to ground per tire, BeamNG has several, which form a contact patch, how many contact points there is depends from tire pressure, size node count etc.

    Then some sims have very simple chassis flex simulation, nothing even nearly as complex as BeamNG, something that is quite challenging to analyze, like is acceleration of car body around 3 axis, which is what I think where other sims are way behind.


    If using modded vehicles to compare game to real world, you might end up with not so good data, for example there has been several changes to game since S series had last update, so I would recommend to use default content in game.
     
    • Informative Informative x 1
  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