Run simulink and beamng

I have MATLAB and BeamNG.tech installed. I was instructed to use Simulink in conjunction with BeamNG.tech. I accessed the GitHub files to run the available examples; however, the step-by-step instructions are not very clear. I initialized the ‘throttle_example’ and set the path to the required ‘.csv’ file. However, when compiling and pressing play in the opened window, a crash error occurs.

Does anyone have a detailed step-by-step guide on how to properly set up and run it?

Hi @matheus,

To use BeamNG.tech with Simulink, here’s a consolidated guide for both S-function and FMI approaches, including fixes for common errors:


Approach 1: Using the S-function

  1. Verify S-function Setup

    • Did you see the BeamNG logo in your S-function block? If yes, proceed to the next step.
    • If not, double-check that the S-function block is correctly configured and linked with BeamNG.tech.
  2. Initialize Connection in BeamNG.tech

    • Open BeamNG.tech and navigate to the Co-Simulation Editor Tool.
    • Load the same .csv file that you’ll use in the S-function block.
    • Start the simulation from the Co-Simulation Editor.
  3. Run Simulation in Simulink

    • Once the connection is active, return to Simulink and compile/play your S-function block.
  4. Fix Common Issues

    • Ensure that you load the same .csv file in both the BeamNG.tech Co-Simulation Editor and the S-function block.
    • If BeamNG.tech isn’t initialized before running the S-function, a crash or failure is expected.

Approach 2: Using FMI (Functional Mock-up Interface)

  1. Load the Required FMI File

    • Download the necessary .fmu file for FMI2 or FMI3:
  2. Initialize Connection

    • Load any level in BeamNG.tech.
    • Use the key combination CTRL + SHIFT + V to start/stop the connection.
    • Configure the FMI block in Simulink with the appropriate .fmu file.
  3. Run the Simulation

  4. Fix Common Issues

    • If you see the error:
      “Invalid setting in ‘FMI2/Bus Creator1’ for parameter ‘OutDataTypeStr’”, follow these steps:
      • Double click on the FMI block, then run the following MATLAB command to create the necessary bus type:
        fmudialog.createBusType('<YOUR_MODEL>/<FMI_BLOCK>')
        
        Replace <YOUR_MODEL> with your Simulink model name and <FMI_BLOCK> with the block name.
        Examples:
        • For FMI3:
          fmudialog.createBusType('FMI3/FMI3')
          
        • For FMI2:
          fmudialog.createBusType('FMI2/FMI2')
          
      • Save your model and retry running the simulation.

Additional Documentation

Refer to the official GitHub repository for BeamNG-MATLAB-Simulink integration:
BeamNG.tech Integration with Simulink


Let me know if you encounter further issues or need more help!

Hi Matheus,

Could you test another example, like the torques_example? I’ve experienced similar crashes before with S-functions, often due to mismatches between the Lua script and the S-function configuration.

Let me know if you notice anything unusual!