Simulink model stops when matlab script runs

2 次查看(过去 30 天)
I have the following matlab script which simply configures a disparity map and opens it with imshow. The script runs just fine on its own
load('stereoParams.mat');
vidobj=videoinput('winvideo',1);%,'MJPG_1280x480');
triggerconfig(vidobj, 'manual');
N=500;
start(vidobj)
try
for i=1:N
img=getsnapshot(vidobj);
imgL = img(:,1:640,:);
imgR = img(:,641:1280,:);
[JL,JR] = rectifyStereoImages(imgL,imgR,stereoParams);
IL = rgb2gray(JL);
IR = rgb2gray(JR);
disparityMap = disparitySGM(IL,IR);
imshow(disparityMap,[0,64],'InitialMagnification',50);
end
catch
delete(vidobj);
close all
Additionally, I have a simulink model that I am using to control a robot with a joystick. However, the simulink model and the matlab script are not able to run simultaneously. If the script is running and the model begins, the script freezes. If the model is running and the script is started, the model freezes. Any help would be appreciated.

回答(1 个)

Walter Roberson
Walter Roberson 2022-6-1
Simulink and MATLAB normally run in the same context, not in different threads or processes (you can tell by the way that Simulink has access to MATLAB variables.)
If your model can be run without access to graphics, then potentially you might be able to start it in a Background Pool, if you have a new enough MATLAB.
Question: how is the model getting control information? In particular is it trying to use the same camera?
  2 个评论
Dimuthu Arachchige
Thank you for your suggestion. The answers to your questions, I don't take any information from the camera to the controller. I just need to get the disparity map from the camera and control the robot seperately.
Any suggestion for this?
Walter Roberson
Walter Roberson 2022-6-7
Suppose you get the disparity map from the camera into the MATLAB session. And then you process it, and display results... and you manually use that information to inform you of where you should turn your joystick? But the joystick is connected to the Simulink session ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by