Does SIMULINK support soft constraint as default?

조회 수: 2 (최근 30일)
순호 권
순호 권 2024년 8월 12일
댓글: 순호 권 2024년 8월 14일
Hello,
Does SIMULINK support soft constraint as default?
Here's my understanding of the concepts:
Hard constraint: In a 1kHz loop, if a loop started at time 't ms' exceeds 1ms, it stops processing the current sensor value (t ms) and moves to the next sensor value at 't+1 ms'.
Soft constraint: If the loop exceeds 1ms, it completes processing the current loop(t ms) and skips the next cycle(t+1 ms), moving to the loop with value at 't+2 ms'.
Thank you in advance.
  댓글 수: 2
Anurag Ojha
Anurag Ojha 2024년 8월 13일
Hello
While SIMULINK does not directly support soft constraints as a default feature, you can achieve this behavior through custom implementation using MATLAB Function blocks and custom scheduling logic. This approach allows you to handle timing overruns and manage the execution of tasks in a way that aligns with the concept of soft constraints.
Here is a basic outline of how you might implement this:
function [nextTimeStep] = customScheduler(currentTime, executionTime)
% Custom Scheduler for Soft Constraints
% Inputs:
% currentTime - The current simulation time
% executionTime - The time taken to execute the current loop
% Output:
% nextTimeStep - The next time step to execute
% Define the fixed time step
fixedTimeStep = 1e-3; % 1ms
% Check if execution exceeded the time step
if executionTime > fixedTimeStep
% Skip the next cycle
nextTimeStep = currentTime + 2 * fixedTimeStep;
else
% Proceed to the next cycle
nextTimeStep = currentTime + fixedTimeStep;
end
end
순호 권
순호 권 2024년 8월 14일
Thank you for your previous response.
I have a few additional questions that I would appreciate your help with:
1. Is the fixed step size set in Simulink independent of the loop's execution time? Is there a method within Simulink to calculate the loop's execution time? (I have tried using tic toc in the past.)
%% matlab code %%
function [num, y] = fcn(a,b)
persistent t
if isempty(t)
t = 0;
end
t = t+1;
num = t;
startTime = tic;
A = rand(a,b);
y = toc(startTime);
end
%%
2. When using the "Simulink Support Package for Arduino Hardware" in External mode or when deploying the model, does the loop automatically run with a soft constraint?
3. In the case of running in External mode with the "Simulink Support Package for Arduino Hardware," how can the execution time be calculated on the Arduino? (I previously attempted to use tic toc, but it did not work on the Arduino board.)
Thank you very much for your assistance.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by