Problem in communicating MATLAB with Simulink via UDP communication..

1 Ansicht (letzte 30 Tage)
JAIN VIRAG
JAIN VIRAG am 6 Apr. 2023
Beantwortet: Vinayak Choyyan am 10 Apr. 2023
Hello Sir/Mam,
I am trying to send real time coordinates of tracked ball from MATLAB to Simulink with UDP communication.
This is my code:
vid = videoinput('winvideo',1);
set(vid, 'FramesPerTrigger', 1);
set(vid, 'TriggerRepeat', Inf);
triggerconfig(vid, 'manual');
start(vid);
mdl = 'udpsim';
open_system(mdl);
ball_diameter = 20;
ball_radius = ball_diameter/2;
ball_min_size = round(ball_diameter / 0.07);
gray_threshold = 200;
sat_threshold = 0.2;
ball_color = [190, 190, 190];
localIP = '10.53.126.43';
remoteIP = '10.53.126.43';
u = udpport(remoteIP, 'RemotePort', 51002, 'LocalPort', 51001, 'OutputBufferSize', 1024);
fopen(u);
i=1;
while i<10000
img = imread(vid);
gray_img = rgb2gray(img);
sat_img = rgb2hsv(img);
sat_img = sat_img(:,:,2);
gray_mask = gray_img > gray_threshold;
sat_mask = sat_img > sat_threshold;
mask = gray_mask & sat_mask;
mask = bwareaopen(mask, ball_min_size);
stats = regionprops(mask, 'Centroid');
if isempty(stats)
ball_coord = [-1, -1];
else
ball_centroid = stats(1).Centroid;
ball_coord = [ball_centroid(1), ball_centroid(2)];
end
write(u, sprintf('[%f,%f]', ball_coord(1), ball_coord(2)));
end
stop(vid); %#ok<UNRCH>
delete(vid);
fclose(u);
Simulink Model:
Problem:
When I run Simulink model 1st then Matlab code not run and If I run Matlab code 1st, I am getting this error
Expected input number 1 to match one of these values:
'byte', 'datagram', 'IPV4', 'IPV6', 'LocalHost', 'LocalPort', 'Timeout', 'ByteOrder', 'OutputDatagramSize', 'EnablePortSharing'
The input, '10.53.126.43', did not match any of the valid values.
How to run simultaneously both ?
Please Help! I will be very grateful to you...

Antworten (1)

Vinayak Choyyan
Vinayak Choyyan am 10 Apr. 2023
Hi JAIN VIRAG,
As per my understanding, you are getting an error message related to input mismatch when trying to use ‘udpport’ function.
In your code, it looks like you have used ‘udpport’ function but passed it with parameters of ‘udp’ function. Please refer to the following documentation to know more about the functions:
Please note, ‘udp’ function will be removed in a future release. Use ‘udpport’ instead.
I hope this resolves the issue you are facing.

Community Treasure Hunt

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

Start Hunting!

Translated by