SimConnect Toolbox for MATLAB/Simulink
This repository provides a Toolbox for MATLAB/Simulink with the following blocks:
- SimConnectSource
- SimConnectSink
- SimConnectInput
0.03) and
a Simulation Pacing set to 1.
- Microsoft Visual Studio 2019 (e.g. Community Edition)
- MATLAB / Simulink (tested with R2020b)
- Microsoft Flight Simulator SDK
- Blockfactory
- CMake (tested with 3.18.4)
Ensure the environment variable MSFS_SDK is properly pointing to the MSFS SDK location.
Use the following commands to get this repository and build it:
# download and build blockfactory
git clone https://github.com/robotology/blockfactory.git
cd blockfactory
cmake -S . -B build
cmake --build build --config Release
cmake --install build --config Release --prefix install
cd ..
# download and build simconnect-toolbox
git clone https://github.com/aguther/simconnect-toolbox.git
cd simconnect-toolbox
cmake -S . -B build
cmake --build build --config Release
In order to use the toolbox in MATLAB you need to do the following:
- add the folder
<simconnect-toolbox>/matlabto MATLAB path - add the folder
<simconnect-toolbox>/matlabto thePATHenvironment variable of your user account (or system)
ℹ️ You can also put the content of directory <simconnect-toolbox>/matlab to a location of your choice and do the steps described above for the new location.
This block allows to read/write data from/to SimConnect.
The blocks have the following parameters:
- Configuration Index
- Connection Name
- Variables
The connection configuration index found in the SimConnect.cfg.
The name of the connection to be used when calling the SimConnect API.
Variables have to be in the following format: VARIABLE NAME, UNIT;
The variable names and units can be found in the SimConnect SDK.
Example:
G FORCE, GFORCE;
PLANE PITCH DEGREES, RADIANS;
PLANE BANK DEGREES, RADIANS;
AIRSPEED INDICATED, KNOTS;
PLANE ALTITUDE, FEET;
STRUCT WORLD ROTATION VELOCITY, STRUCT;
LIGHT STROBE ON, BOOL;
Struct types are provided / consumed as vector to Simulink.
The following struct types are supported:
SIMCONNECT_DATATYPE_LATLONALTSIMCONNECT_DATATYPE_XYZ
This block allows to read input event data from SimConnect.
The block has the following parameters:
- Configuration Index
- Connection Name
- Variables
The connection configuration index found in the SimConnect.cfg.
The name of the connection to be used when calling the SimConnect API.
Variables have to be in the following format: INPUT EVENT ID, SHOULD MASK;
The event ids can be found in the SimConnect SDK. The second parameter specifies if the event id should be
forwarded to the sim or not. A value of TRUE will mask the event id meaning only the Simulink model will receive it.
Example:
AXIS_ELEVATOR_SET, TRUE;
AXIS_AILERONS_SET, TRUE;
AXIS_RUDDER_SET, FALSE;
The following input events are currently supported:
AXIS_ELEVATOR_SETAXIS_AILERONS_SETAXIS_RUDDER_SETAXIS_ELEV_TRIM_SETAXIS_SPOILER_SETAXIS_FLAPS_SETAXIS_LEFT_BRAKE_SETAXIS_RIGHT_BRAKE_SETAXIS_THROTTLE_SETAXIS_THROTTLE1_SETAXIS_THROTTLE2_SETAXIS_THROTTLE3_SETAXIS_THROTTLE4_SETAXIS_MIXTURE_SETAXIS_MIXTURE1_SETAXIS_MIXTURE2_SETAXIS_MIXTURE3_SETAXIS_MIXTURE4_SETAXIS_PROPELLER_SETAXIS_PROPELLER1_SETAXIS_PROPELLER2_SETAXIS_PROPELLER3_SETAXIS_PROPELLER4_SET
ℹ️ The range [-16384, +16384] is converted to [-1.0, 1.0].
This repository includes an example model matlab/SimConnectToolboxExample.slx that demonstrates the functionality.
- Allow configuration index to be set via input
- Improve parameter checking (distinguish between event ids and data variables)
- Documentation of classes and methods
A special thanks to:
- Ferigo, Diego
- Traversaro, Silvio
- Romano, Francesco
- Pucci, Daniele
They provide a nice framework to make development of Simulink blocks an toolboxes easier and the code better understandable than using plain MATLAB/Simulink API.
See also here: https://github.com/robotology/blockfactory



