Does SIMULINK support soft constraint as default?

2 次查看(过去 30 天)
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