Does SIMULINK support soft constraint as default?

3 visualizaciones (últimos 30 días)
순호 권
순호 권 el 12 de Ag. de 2024
Comentada: 순호 권 el 14 de Ag. de 2024
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 comentarios
Anurag Ojha
Anurag Ojha el 13 de Ag. de 2024
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
순호 권
순호 권 el 14 de Ag. de 2024
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by