Simultaneous Video Display with continuous serial communication

6 visualizaciones (últimos 30 días)
Hello,
I am currently developing software for a vision based SMT pick and place machine. I have made a GUI in MATLAB that has continous video display and is able to communicate to the stepper motors in the machine through serial commands. The problem I am having is that I am unable to have the video display running whilst communicating to the motion controller to move the stepper motors. The relevant sections of the code are as follows:
1) Video Display Function:
if true
function startStopCamera_Callback(hObject, eventdata, handles)
set(handles.vid,'FramesPerTrigger',1);
set(handles.vid,'TriggerRepeat',Inf);
triggerconfig(handles.vid, 'manual');
start(handles.vid);
while 1
trigger(handles.vid);
RGB = getdata(handles.vid,1);
subimage(RGB);
end
end
2) Stepper Motor Serial Communication:
if true
function AutoStart_Callback(hObject, eventdata, handles)
s = serial(serial_port_string); % COM4
fopen(s);
for w = 1:rows
fprintf(s,Loaded_Data{w}); % Loaded_Data is array of coordinate
fprintf(s,'PD2000;'); % 2 sec time delay command
end
fclose(s);
end
The problem is me being unable to run both at the same time. Say I start the camera video display and then click the button which iterates through Loaded_Data to go to the specified coordinates, what happens is the camera stops updating, the motors move and after the for loop is finished the camera starts updating.
This is a big problem to me as I need to be able to see the pick and place machine video whilst the stepper motors are moving.
I bought the Parallel Toolbox yesterday hoping it would solve the problem and I have tried parfor but not sure if this is what I am looking for.
Your help would be really appreciated.
Kind Regards,
Mo
  1 comentario
Mariam Castañeda
Mariam Castañeda el 15 de Jul. de 2016
Hi! I know this is a topic from 2013 but I have the same problem now lol. Do you found an answer? I'm pretty stressed right now because I cannot make the buttons of my GUI responds with a while that use the camera, the while cycled and the buttons never respond. Any solution I'll appreciate.

Iniciar sesión para comentar.

Respuesta aceptada

David Tarkowski
David Tarkowski el 8 de Abr. de 2013
The big problem that I see is in your startStopCamera_Callback function. You are continuously calling trigger and then getdata in the loop. When you call getdata like that it will block execution of any further MATLAB commands until a frame is acquired. Unless your subimage function is doing the serial communication (which it doesn't look like it is), the serial communication will never have time to execute.
I would start by investigating the FramesAcquiredFcn of the videoinput object. You can configure this to be called every time a frame is acquired but MATLAB will be free to run other commands while waiting for the frame. Your code would look something like this (I haven't tried to actually run this code, there may be typos):
if true
function startStopCamera_Callback(hObject, eventdata, handles)
set(handles.vid,'FramesPerTrigger',1);
set(handles.vid,'TriggerRepeat',Inf);
set(handles.vid, 'FramesAcquiredFcn', @frameAcquired);
set(handles.vid, 'FramesAcquiredFcnCount', 1);
triggerconfig(handles.vid, 'manual');
start(handles.vid);
trigger(handles.vid);
end
function framesAcquired(vid, eventdata)
RGB = getdata(vid,1);
subimage(RGB);

Más respuestas (1)

Mo
Mo el 9 de Abr. de 2013
Editada: Mo el 9 de Abr. de 2013
Hi David,
Thank you for your reply. I think that's definetly whats causing the problem. I have tested your suggestions and the serial commands are now sent perfectly. However, I am unable to get a video display on the designated GUI axes.
Here's the code used:
if true
function startStopCamera_Callback(hObject, eventdata, handles)
set(handles.video,'FramesPerTrigger',1);
set(handles.video,'TriggerRepeat',Inf);
set(handles.video, 'FramesAcquiredFcn', @framesAcquired);
set(handles.video, 'FramesAcquiredFcnCount', 1);
triggerconfig(handles.video, 'manual');
start(handles.video);
trigger(handles.video);
function framesAcquired(video, eventdata)
RGB = getdata(video,1);
subimage(RGB);
axis off;
end
I get a snapshot figure displayed outside the GUI axes I made. It is also a picture not a video. Do I need to run part of the code in a continuous while loop or does the infinine trigger repeat handle that?
Thanks a lot! Really appreciate it.
Regards,
Mo
  1 comentario
David Tarkowski
David Tarkowski el 9 de Abr. de 2013
Did you use GUIDE to create your GUI? If so, you probably need to change the 'HandleVisibility' property for the figure to make it accessible from the FramesAcquiredFcn callback. You can see Doug's tutorial for more information.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by