Configure Block Interface
When you use the S-function block you can configure the inputs and outputs that are communicated to BeamNG using the Co-Simulation Editor in BeamNG.
Note
This feature is not yet available for the FMU blocks. Those blocks come with a fixed interface.
Introduction
The Co-Simulation Editor allows the BeamNG.tech user to set up a tightly-coupled system between a BeamNG vehicle and third-party software (such as Mathworks Simulink). A GUI-based tool facilitates the creation of .csv files which are used as a contract to describe the parameters of the message-passing between the two sides of the coupling. The user can use the mouse to choose from a multitude of properties across the vehicle (kinematic properties, wheel data, vehicle electrics data, powertrain data, etc) - properties which are to be sent to the third party. Incoming properties (from the third party) are also selected in a similar way.
Configuration
To establish a tight-coupling communication with Simulink through S-function, follow the following steps:
Start the BeamNG.tech simulation in your favorite map.
Press
F11to open the World Editor.Click on the Co-Simulation Editor.

Figure 1: The
Co-Simulation EditorwindowIf you have a your coupling-configuration csv file in your user-folder (it is located in
%USERPROFILE%\AppData\Local\BeamNG.tech\0.3xby default), you have to reload the csv by clicking onStart coupling with 3rd partybutton, then anotherFile dialog windowwill appear to load your csv.
Figure 2: The File dialog window to load your csv.
If you want to create your signals file, click on
Open the available signal for this vehiclebutton, it will open another window where you can select your signalsFromandTofor sending and receiving signals.
Figure 3: The
available signal listwindow.Save your csv by click on
save the current signals configuration, for this vehicle, to diskbutton.
Figure 4: The File dialog window to save your configuration as csv file.
Click on
Start coupling with 3rd partybutton at your Co-Simulation Editor window to start the coupling.Open your Simulink model, add your S-function.
double-click on your S-function, and type the path of your csv file.
Load your csv signals file to your S-function.

Figure 5: Loading csv file window in S-function.
Set the Simulation time in Simulink in model settings use
Fixedsteptype and calculate yourFixed-step sizeto match the simulation time in BeamNG, using the following formula:ceil(SimulinkDt / physicsDt) * physicsDtwhere
SimulinkDtis the Simulink computation time,physicsDtis the BeamNG physics step time (fixed at 0.0005 seconds), and ceil is the ceiling operator. Figure below shows where this is set (highlighted in yellow).
Figure 6: The Configuration Parameters window of Simulink model.
Run your S-function model in Simulink.
To stop coupling, stop coupling at BeamNG.tech end by pressing on the same button that started the coupling i.e.,
Stop coupling with 3rd party, or press CTRL+R to reload the vehicle, then click onStopin Simulink.