Desktop Real-Time slow initialization
Mostrar comentarios más antiguos
I am using the input from an mcc usb-231 daq to feed data into my simulink model through a function block. The issue I am running into is that when the simulation first starts up. it takes almost an entire minute before my simulation begins simulating through the desktop realtime kernal.
Here is my function block.
function output = fcn()
coder.extrinsic('daq','read','addinput'); %lets simulink know to read commands as MATLAB commands
d = daq('mcc');
addinput(d,'Board0',0,'Voltage')
data = read(d,'OutputFormat','Matrix');
output = zeros(1,1);
output = data(1,1);
Is there a way to get rid of this initialization buffer at the start?
Respuestas (1)
Manikanta Aditya
el 5 de Jul. de 2024
Hi,
To improve the initialization time and overall performance, you can try the following workaround approach:
- Initialize the DAQ session outside of the function block, perhaps in a MATLAB Function block that runs only once at the start of the simulation.
- Use a persistent variable in your function block to maintain the DAQ session across function calls.
Here's how you might modify your code:
- Create a new MATLAB Function block for initialization:
function d = initDAQ()
coder.extrinsic('daq', 'addinput');
d = daq('mcc');
addinput(d, 'Board0', 0, 'Voltage');
- Modify your existing function block:
function output = fcn(d)
coder.extrinsic('read');
persistent daqSession
if isempty(daqSession)
daqSession = d;
end
data = read(daqSession, 'OutputFormat', 'Matrix');
output = data(1,1);
- In your Simulink model, use the initialization function to create the DAQ session, then pass it to your main function block.
This approach should significantly reduce the initialization time because you're setting up the DAQ session only once at the start of the simulation, rather than every time the function block is called.
I hope this helps!
2 comentarios
william
el 8 de Jul. de 2024
Manikanta Aditya
el 9 de Jul. de 2024
- Perform DAQ read operations in a separate MATLAB Function block that runs asynchronously from the real-time kernel. This will help prevent the DAQ read latency from affecting the real-time execution.
- Implement a circular buffer to store the DAQ data. The DAQ read operation can write data to this buffer at its own pace, while the real-time kernel can read data from the buffer without waiting for the DAQ operation to complete.
Categorías
Más información sobre Model Preparation for Real-Time Simulation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!