Deploy Simulink model to Arduino using App designer

조회 수: 10 (최근 30일)
Daniele Crimella
Daniele Crimella 2023년 1월 25일
답변: Amal Raj 2023년 3월 13일
Hello,
as described in the summary I would like to build a standalone app that runs Simulink models on external Arduino hardware.
There are several models from which the user can select from and parameters that may be modified before the deployment (assigned from model workspace).
I need to understand how to replicate the "Build, deploy & Start" button from Simulink HARDWARE tab into a Standalone App. This way the model is loaded into the board after the user has selected the appropriate parameters and started.
Can you please put me in the right direction on how to solve this problem?
Thank you

답변 (1개)

Amal Raj
Amal Raj 2023년 3월 13일
Hi Daniele,
Here's a rundown of the steps you can take to build a standalone app that runs Simulink models on external Arduino hardware:
  1. Create your Simulink model and configure it for Arduino deployment. Check that the model is compatible with the Arduino hardware and that all necessary blocks are included in the Simulink model.
  2. Define the parameters that the user will be able to change before deployment. You can use MATLAB's App Designer to create a graphical user interface (GUI) for your app that allows the user to choose the appropriate parameters. You can also use the model workspace to store parameters so that the Simulink model can easily access them.
  3. Build and deploy the Simulink model to the Arduino hardware using MATLAB code. You can generate code for your model using the "deploy" function, and then use the "compile" and "deploy" functions to build and deploy the code to the Arduino.
  4. Add a "start" button to your App Designer GUI that launches the Simulink model on the Arduino. The MATLAB code you wrote in step 3 will be executed when the user clicks the "start" button, and the Simulink model will be deployed to the Arduino hardware.
  5. Run your app to ensure that the Simulink model is successfully deployed to the Arduino hardware.
Sample code:(This code can be tweaked to suit your Simulink model and Arduino hardware.)
% Load the Simulink model
model = 'my_model';
load_system(model);
% Set model parameters from the app GUI or model workspace
param1 = getappdata(app.UIFigure, 'param1');
param2 = getappdata(app.UIFigure, 'param2');
set_param(model, 'param1', num2str(param1));
set_param(model, 'param2', num2str(param2));
% Generate code for the model
deploy(model);
% Build and deploy the generated code to the Arduino
compileBuildInfo = rtwdemodbbuild(model);
deployBuildInfo = rtwdemodbdeploy(model);

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by