Simulink vehicle and controls simulation. The torque vectoring controller runs the firmware C++ code from Consolidated-Firmware through C Function blocks.
- MATLAB R2025b with Simulink, Vehicle Dynamics Blockset, Simulink 3D Animation, DSP System Toolbox and Simscape Electrical
- Visual Studio 2022 with the "Desktop development with C++" workload
- CMake, Git, and the Python setup from the Consolidated-Firmware README
-
Clone this repo and Consolidated-Firmware side by side:
Formula-Electric/ ├── sim/ └── Consolidated-Firmware/ -
Build the torque vectoring library (from
Consolidated-Firmware/):cmake -S . -B build_fw_test_msvc -G "Visual Studio 17 2022" -A x64 -DPLATFORM=firmware -DTARGET=test -DUSE_COMMIT_INFO=MINIMAL cmake --build build_fw_test_msvc --target hexray_VC_torque_vectoring --config DebugThe build folder must be named
build_fw_test_msvc. -
In MATLAB, run once per computer (from
sim/):setup_firmware_pathThis stores your Consolidated-Firmware path and selects Visual C++ 2022 as the compiler. If the firmware repo is not next to
sim/, it asks you for the folder. -
Open
driver_sim(driver in the loop) orcontrols_testing(scripted inputs) and run it. Keepsim/as the MATLAB current folder. The first run is slow because the custom code compiles.
| Change | Then |
|---|---|
| Torque vectoring C++ | Rebuild the library (step 2) and run the sim. If it still uses old code, delete slprj/. |
| A vehicle constant | Edit vehicle_params.m. Section 1 mirrors the firmware constants.hpp; keep both in sync. |
tv_debug.h |
Nothing. The model imports the bus types on every run. |