I am working on my Master Thesis project and I have faced a problem which I'm getting crazy with.
I have a model in Simulink and it works as it should. In this model, I have the controller which has 3 input values and 2 output (all of them double type).
I have a software implemented in the Arty Z7 board to calculate this controller.
I've saved the 3 inputs values in a data.mat which I got from the simulation in Simulink and sent them to the board through UDP communication via Matlab command (fwrite and fread). I compared the 2 values from this simulation and the 2 original values from the Simulink and it is very accurate, meaning the software implemented is correct.
I'd like to have this simulation in the board in the loop with the Simulink, for that I have implemented the UDP blocks receive, send and configure. And here is the problem.
The communication is not working properly... I can see in the board terminal that I'm receiving and sending some data however, I'm not getting any value in the simulink.
I'm also sometimes receiving the message 'unable to alloc pbuf in recv_handler' in the terminal, which never happened when using Matlab command.
The main part of the Matlab code is:
vectorSize = size(Vi,1);
Vi(1: vectorSize) = swapbytes(Vi(1: vectorSize));
Vw(1: vectorSize) = swapbytes(Vw(1: vectorSize));
Vwref(1: vectorSize) = swapbytes(Vwref(1: vectorSize));
udp_interface = udp('192.168.7.10', 7, 'LocalPort', 7);
dataToSend = zeros(1,3);
chipProcessedDataVi = single(zeros(2, vectorSize));
disp('UDP communication has been started');
startTime = tic;
for iteration = 1 : 1 : vectorSize
dataToSend(1) = Vi(iteration);
dataToSend(2) = Vw(iteration);
dataToSend(3) = Vwref(iteration);
fwrite(udp_interface, dataToSend, 'float');
chipProcessedDataVi(1:2,iteration) = fread(udp_interface, 2, 'float');
elapsedTime = toc(startTime);
textMessage = sprintf('\nTime spent for processing all sensor stimuli samples: %.4f [sec]\n', elapsedTime);
disp('UDP communication has been stopped');
chipProcessedDataVi(1: 2*vectorSize) = swapbytes(chipProcessedDataVi(1: 2*vectorSize));
The main part of the Simulink is:
How do I implement this in Simulink?
Thank you in advance!!!