Concurrent execution in Simulink real-time - matlab

I have two model references - Slow model and Fast model, each running at its own rate for concurrent execution on the grt "generic real time" . However when I attempt to build the block I get the following error:
Simulink cannot generate code for the signal at output port 1 of block
'Multirate/Fast' because the signal requires data transfer that
generates lock-free code for a rate monotonically scheduled task.
I am not sure what to configure in simulink to overcome this error. I attempted to add rate transition from the Fast model to the Slow model but the error remains.
Any thoughts

Since there are many possibilites I can't give you a simple answer but you can try the following:
Check if simulink can determine your sample rates... Did you configure that correctly (go to view and set sample rate colors) then you see if Simulink detects the execution times correctly.
If your Simulink Block ('Fast') is contained in a single subsystem make it an atomic subsystem... an configure the sample rate on the subsystem properties.
Set the strictest constrains in the rate transition block...
How is your Model configuration? is it set to multitaskig....

Related

Error in All sample times for this block must be discrete. No continuous or constant sample times are allowed

I'm designing DSS System, the problems is when I execute it this error occurs:
Error in 'DSS_System_withANFIS/Synchronization Unit/Acquisition/Integrate and Dump1': All sample times for this block must be discrete. No continuous or constant sample times are allowed.
Here is my overall system design:
and this is my acquisition subsystem of Synchronization unit:
The error occurred at integrate and dump unit.
Any help?
I found the solution.
I just changed the solver to discrete in configuration parameters in simulink UI

Difference in Workspace and Simulink step response. Why this difference?

I had as primary objective to make a controller for the transfer function (5.551* s^2), using root locus I made the controller shown below. Analyzing the step response in the Workspace using the step () function I had a satisfactory answer but when I try to transfer this answer to Simulink the response behaves differently, at steady state for example I wish to have the smallest possible error as it was obtained in Workspace but in Simulink there is a big error and for some reason at 8 seconds time (Simulink simulation time) there is a "jump" as shown on the display and when I change the simulation time there is a change in this "jump" too and I do not know why these changes between one environment and another.
Step response in Workspace
Step response in Simulink with 8s of simulation
Step response in Simulink with 12s of simulation
Simulink controller
Simulink transfer function
I expected to make a controller that has an error less than 5% and an overshoot smaller than 25%, so I first made a controller with two integrators to nullify the effects of zeros on the source, after that I added two more integrators on the source to try decrease the error, the zero at -0.652 I used the angular condition for this and the gain of 0.240251 I used the modular condition.
I wasn't expecting the most optimized behavior possible, just that it has minimum conditions that satisfy the imposed conditions, so I didn't worry for example about the four integrators at the source.
I tried use the sisotool() command thinking that I had done something wrong, but the result changed a lot when I was simulating Simulink so I discarded this option and kept the controller I made using root locus.
Your MATLAB code and your Simulink model are not the same, and hence the different results.
MATLAB allows you to define the non-causal plant model P_ball, then form the causal closed loop CL, which can have its step response generated.
Simulink does not allow you to model non-causal blocks (even if the overall model is causal) and hence will not allow you to implement s^2, which I assume is why you have used two differentiation blocks. But a numerical differentiation is not the same as a Laplace s operator.
You would have to make the plant causal by incorporating two poles that are large enough to not adversely effect the overall simulation. So your plant model needs to be something like 5.551*s^2/((s/1000 + 1)(s/1000 + 1)) which can be implemented using a Transfer Function block with a numerator of 5.551*1000*1000*[1 0 0] and a denominator of [1 2*1000 1000*1000].
Alternatively you could just implement PID * P_ball (where you manually do the 2 zero/pole cancellations) which is causal.

Simulink: get step time in a triggered subsystem

I have a question about my triggered subsystem in Simulink:
So the Susbsystem is executed every 0.01 s.
My question is: how can I get this variable (0.01) inside my subsystem?
NB: I don't need the Simulation step time.
I've already thought to two solutions:
1) use a Digital Clock with a Memory block
2) use a Weighted Sample Time block
but, both of them gave me an initial value of 0.
Do you have an elegant solution for my task
Thank you very much.
Have a nice day
The easiest solution is to have a constant block feeding into the subsystem. Define a MATLAB Workspace variable dt=0.01; and have the constant set to dt, and the sample rate of your Pulse Generator set to dt.
Alternatively you can use the Probe block to get the Sample Rate of the signal coming out of the Pulse Generator, and feed that as an input to the Subsystem.
Another way is to use get_param() command in your workspace.
In your case, it should be:
get_param('<path-to-block>/Pulse Generator','Period')
This should output:
>> ans =
0.01
I had this same problem myself. I received the following feedback from MATHWORKS when I reported it as a bug:
If triggered subsystems are executed on edge detection on the triggering event then it will require at least two model execution time steps in order to satisfy the triggering condition. As a result the triggered subsystem will not execute at 0 causing the results you are seeing. This is expected behavior.
If you require the triggered subsystem to execute on the first timestep you can change the "Trigger type" option to "function call." This option will execute the subsystem or model when the control signal receives a function-call event from a Statflow chart, Function-Call Generator block, or an S-function block." In this case you will just need to confirm that your function call block executes prior to the triggered subsystem block. This can be confirmed using the "Blocks - Execution Order" Debug tool under "Information Overlays."

Why does my Simulink-Model rebuild at every iteration?

I'am trying to speedup my simulink project and want to use the Accelerator-Simulation mode.
The aim of my project is to control a cyclic process and is structured as followes:
matlab-script, where all parameters and a feedforward control with
parameter estimation is implemented. Also it starts simulating the
simulink model for each iteration.
simulink model, where the dynamic system and the feedforward control (basically a lookup-table) together with a feedback control
is implemented. Parameters of all blocks are set by workspace variables/structs generated by the script.
The feedforward control variable is calculated and parameter are estimated from the simulated data after every simulation pass. Then the model is simulated again. The model is not changing during the iterations, but still it is compiling at every cycle. From the first: Is this solution appropriate for using the Accelerator mode?
I tried to follow theses proposed steps to determine, why it is built at every iteration: mathworks
If i run it with the Accelerator-Mode (referring to the documentation of this function, it now compiles for simulation), I still cannot reproduce why it is compiled at every iteration.
csdet1.ContentsChecksum.Value ~= csdet2.ContentsChecksum.Value
is true, but the proposed code does not find any details.
csdet1.InterfaceChecksum.Value ~= csdet2.InterfaceChecksum.Value
is also true, the proposed code outputs that
UserDefinedTypesChecksum
is different. What does that mean and how can I resolve this?
Sidefact: When I run Simulink.BlockDiagram.getChecksum() with the Model opened in Simulink and Normal-Mode chosen, I get this error:
Continuous update specified for this chart chartname This is not
supported for RTW."
But this chart is a Matlab-Function block, not a stateflow chart?!

Simulink and SIL error due to unsupported continuous sample time

I have a 3 simulink models: the first is used as multiple-instance component inside the second; the second is a component inside the third (the third one is just used for testing purpuse and inkect test stimuli on the second).
If I simulate my model in "Normal" way all works fine.
If I set my HW configuration (ARM Cortex) and try to run it in "SIL" mode it doesn't work because "The component has an unsupported continuous sample time. Input and output ports with continuous sample times are not supported. To avoid this error you should update the component so that there are no continuous sample times crossing its boundary."
Same error also trying to simulate the first model (the inner one).
Do you have an idea to solve my problem?
Thank you.
Yes. Use discrete sample times, not continuous ones. You can display the sample times in your model to see which ones are continuous and you need to change, see the documentation for more details.