Simultaneous Video Display with continuous serial communication
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mo
il 8 Apr 2013
Commentato: Mariam Castañeda
il 15 Lug 2016
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 Commento
Mariam Castañeda
il 15 Lug 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.
Risposta accettata
David Tarkowski
il 8 Apr 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);
0 Commenti
Più risposte (1)
Mo
il 9 Apr 2013
Modificato: Mo
il 9 Apr 2013
1 Commento
David Tarkowski
il 9 Apr 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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!