running a simulink desktop real-time model as .m file

조회 수: 2 (최근 30일)
Ali Albaidhani
Ali Albaidhani 2022년 7월 28일
답변: Altaïr 2025년 3월 26일
Hello everyone,
So i have made a controller as a simulink model and im trying to run it from matlab editor. The simulink model runs in simulink desktop real-time, and it's output is connected to a hardware and the input is connected back to the software.
The problem is that when i run the simulation from simulink, the controller works fine and it does it's job, but when i run it from matlab editor, it goes crazy. The controlled variable keeps rising and the controller does not work.
Im using the following code to run the simulation:-
clc
clear all
x=0.004
simout = sim('PI_Controller.slx');
Im guessing the problem is with sim command. Maybe there is a different command for running a simulation that runs in ream-time?
Im attachment is a Photo of my Model.
What am i missing here?
Regards
Ali

답변 (1개)

Altaïr
Altaïr 2025년 3월 26일
While more details about the model would help pinpoint the issue, here is a useful documentation page that offers general guidance on running an application from the MATLAB command line:
web(fullfile(docroot, 'sldrt/ug/run-application-from-matlab-command-line.html'))
Note: Run the command in MATLAB command window to open the doc page.
There are three simulation modes mentioned in the documentation:
  1. For a moderate sample rate, up to 1 kHz, Connected IO mode or accelerator mode is recommended. In these modes, the Simulink model runs within MATLAB, while only the I/O module drivers operate in the Simulink Desktop Real-Time kernel.
  2. For a higher sample rate, up to 20 kHz, Run in Kernel mode is suggested. This mode uses Simulink Coder to generate a real-time application from the model, with both the real-time application and the I/O module drivers running in the Simulink Desktop Real-Time kernel.
Additionally, a Real-Time Controller example can be found here:
web(fullfile(docroot, 'sldrt/ug/real-time-controller.html'))
Kernel Mode simulation might be suitable for the use case. For more information on preparing a model for Kernel Mode simulation, refer to:
web(fullfile(docroot, 'sldrt/ug/simulink-run-in-kernel-mode.html'))
Providing more information about the model or a dummy model would be helpful for further assistance.

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by