How can i interact to a Simulinkmodel via Appdesigner in Realtime running on target Hardware?

1 view (last 30 days)
Hello,
i want to ask three questions.
1. How do I launch the simulink model on Hardware Monitor&Tune or Hardware Deploy via Appdesigner?
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartDroneButton
function StartDroneButtonPushed(app, event)
simulinkModel = 'mpu9250_block_test_Kalman_stateflowNEU';
% assigning variables to workspace
open_system(simulinkModel);
set_param(simulinkModel,'HardwareBoard','Raspberry Pi','SimulationCommand','Start');
end
I have created a simulink model for my Raspberry Pi, I want to start the model via Hardware Monitor&Tune and later via Hardware Deploymode. In my code in Appdesigner I could only start the model in Simulationmode. I have not found any documentation on this topic to find the correct parameters.
2. How do i change the Parameters of a Simulinkmodel using the App Designer Tool (in Realtime).
% Value changed function: Button
function ButtonValueChanged(app, event)
app.buttonState = app.Button.Value;
assignin('base','button',app.buttonState);
end
end
I implemented a stateflow chart with conditions. The conditions to change the state were implemented using local variables with boolean data type. I want to change the local variables using the state button in the app designer. How can I implement this in a real-time application? In the previous line of code, I tried using Assignin, but I could not get any results in Simulink.
3. Lastly, how can I output the data of the local variables from the Stateflow or the global variables from the Simulink block to Appdesigner in real-time?
i would be extremely grateful if someone could help me with this.

Answers (1)

SANKALP DEV
SANKALP DEV on 15 Dec 2023
Hello Mikail,
I understand that your goal is to start a Simulink model on a Raspberry Pi from an App Designer interface.
It appears that you are on the right path by configuring the 'HardwareBoard' parameter to 'Raspberry Pi' and utilizing the 'SimulationCommand' parameter with 'Start'. However, to deploy the model to hardware successfully, I recommend using the ‘deploy’ function instead of ‘Start’.
set_param(simulinkModel, 'HardwareBoard', 'Raspberry Pi');
deploy(simulinkModel);
For real-time parameter changes in your Simulink model, the 'set_param' function is indeed the way to go. Ensure that you specify the correct block name and parameter name in the following manner:
% Set the parameter of your Simulink block
simulinkModel = 'mpu9250_block_test_Kalman_stateflowNEU';
blockName = 'YourBlockName'; % Replace with your actual block name
paramName = 'YourParameterName'; % Replace with your actual
paramValue = app.buttonState;
set_param([simulinkModel '/' blockName],paramName,num2str(paramValue));
To retrieve data from your Simulink model and update your App Designer UI in real-time, you can use the 'get_param' function.
paramValue = get_param([simulinkModel '/' blockName], paramName);
For more detailed information on these functions, please refer to the following documentation:
Additionally, I recommend you to refer to the following example to get more clear insights of using the Simulink Real-Time app to configure a model to build and run real-time applications on a target computer.
Thanks, and regards,
Sankalp dev.

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!