working with triggers -凯发k8网页登录
this example shows how to use the different types of triggering and how to configure other trigger properties.
configuring trigger properties
to obtain a list of configurable trigger settings, use the triggerinfo function with the video input object. triggerinfo will return all possible trigger configurations supported by the image acquisition device associated with the video input object. possible configurations consists of a valid trigger type, trigger condition, and trigger source combination.
note: all image acquisition devices support immediate and manual trigger types. a hardware trigger type is available only if it is supported by the image acquisition device.
% access an image acquisition device. vidobj = videoinput('matrox', 1); % display all valid trigger configurations. triggerinfo(vidobj)
valid trigger configurations: triggertype: triggercondition: triggersource: 'immediate' 'none' 'none' 'manual' 'none' 'none' 'hardware' 'fallingedge' 'digitaltrigger' 'hardware' 'fallingedge' 'optotrigger' 'hardware' 'fallingedge' 'timer1' 'hardware' 'fallingedge' 'timer2' 'hardware' 'risingedge' 'digitaltrigger' 'hardware' 'risingedge' 'optotrigger' 'hardware' 'risingedge' 'timer1' 'hardware' 'risingedge' 'timer2'
to configure the trigger settings for an image acquisition device, use the triggerconfig function with the desired trigger type, trigger condition, and trigger source.
triggerconfig(vidobj, 'hardware', 'fallingedge', 'optotrigger') % view the current trigger configuration. currentconfiguration = triggerconfig(vidobj)
currentconfiguration = triggertype: 'hardware' triggercondition: 'fallingedge' triggersource: 'optotrigger'
note: configuring trigger settings requires a unique configuration to be specified. if specifying the trigger type uniquely identifies a configuration, no further arguments need to be provided to triggerconfig.
hardware triggers are the only trigger type that typically have multiple valid configurations.
immediate triggering
by default, a video input object's trigger type is configured for immediate triggering. immediate triggering indicates that data logging is to begin as soon as the start function is issued.
% configure the trigger type. triggerconfig(vidobj, 'immediate') % initiate the acquisition. start(vidobj) % wait for acquisition to end. wait(vidobj, 2) % determine the number frames acquired. frameslogged = vidobj.framesacquired;
frameslogged = 10
manual triggering
manual triggering requires that the trigger function be issued before data logging is to begin.
% configure the trigger type. triggerconfig(vidobj, 'manual') % initiate the acquisition. start(vidobj) % verify no frames have been logged. frameslogged = vidobj.framesacquired;
frameslogged = 0
% trigger the acquisition. trigger(vidobj) % wait for the acquisition to end. wait(vidobj, 2); % determine the number frames acquired. frameslogged = vidobj.framesacquired;
frameslogged = 10
hardware triggering
hardware triggering begins logging data as soon as a trigger condition has been met via the trigger source.
in this example, we have connected an opto-isolated trigger source from a function generator to our image acquisition device. the image acquisition device will begin logging data upon detecting a falling edge signal from the source.
% configure the trigger settings. triggerconfig(vidobj, 'hardware', 'fallingedge', 'optotrigger')
initially, no signal is sent from the source to the image acquisition device.
% initiate the acquisition. start(vidobj) % verify nothing has been acquired. frameslogged = vidobj.framesacquired;
frameslogged = 0
a square wave signal will now be sent from the trigger source to the image acquisition device.
% wait for the acquisition to end. wait(vidobj, 10) % verify frames were acquired. frameslogged = vidobj.framesacquired;
frameslogged = 10
% once the video input object is no longer needed, delete % it and clear it from the workspace. delete(vidobj) clear vidobj