-
Notifications
You must be signed in to change notification settings - Fork 2
How to generate code from a Simulink model
Diego Ferigo edited this page Sep 28, 2018
·
1 revision
This guide briefly describes how to generate, compile, and run C++ sources from a Simulink model.
Resources:
- A running version of Matlab, Simulink, and Simulink Coder
- An environment configured with:
- A working controller (it can be either in simulation or the real robot). In this guide a controller from robotology/whole-body-controllers is used.
- Clone robotology/whole-body-controllers
- Configure the project:
mkdir build cd build cmake ..
- Open the controller
- Plug the robot (i.e. open Gazebo or turn on the real robot)
- Press
Ctrl+D
- Press the
Build
button
The code generation process will now start. If there are no errors, a folder <nameofthemdl>_grt_rtw
should be generated in the matlab current folder.
# Clone the repository
git clone https://github.com/robotology-playground/autogenerated-whole-body-controllers.git
# Check the branches
# At the time of writing there are master for iCubGazeboV2_5, and robot/iCubGenova04
cd autogenerated-whole-body-controllers
git branch -a
# Checkout the right branch
git checkout <selected branch>
# Configure robotology/whole-body-controllers
cd <dir>/whole-body-controllers
mkdir build
cd build
cmake -DAUTOGENERATED_WBC_SOURCE_DIR="<dir of autogenerated-whole-body-controllers>"
# Copy the models to the autogenerated-whole-body-controllers repository
make copy-autogenerated-models
# Commit the models
cd <dir>/autogenerated-whole-body-controllers
git add autogenerated/
git commit -a
# Deploy the new models
git push
# Wait the tests to pass. Currently we test Ubuntu and OSX.
At the current stage the sources can be compiled only if Simulink and Simulink Coder are installed due to headers that are not exported during the code generation process. The executable can than be deployed to the target platform.
cd <dir>/autogenerated-whole-body-controllers
cd build
cmake ..
cmake --build .
At this point the executables are generated in the build/bin
folder and they can be executed with ./CoderMain_<nameofthemdl>
. The simulation can be stopped gracefully pressing Ctrl+C
.