% Parameters:
imdir = 'C:\...\2014-11-07-Y4-Home';
pref = 'testY4-2014-11-07-Home-';
ext
= 'jpg';
ntest = 20; % Number of repetitions
settletime = 0.2; % Settling
time in seconds
targetposX = 10000; targetposY = 10000; % Target position
count = 0;
% Before use open serial port.
[s,erro] =
EZStepperOpenSerial('COM3');
% Create XYStage object:
xy = XYStage('PortObj',
s, 'ControllerNameX', 3, 'ControllerNameY', 4, ...
'LeadUmX',
1000, 'LeadUmY', 1000, ...
'MotorStepsX', 400, 'MotorStepsY',
200, ...
'HoldCurrentX', 5, 'HoldCurrentY', 5, ...
'RunCurrentX', 65, 'RunCurrentY', 65, ...
'StepDivideX',
256, 'StepDivideY', 256, ...
'SlewVelocityX', 15000, 'SlewVelocityY',
15000, ...
'InitVelocityX', 0, 'InitVelocityY', 0, ...
'RampX', 50, 'RampY', 50, ...
'WithLimits', 1, 'Log', 1);
% Start Camera (GigE color camera AVT Manta G282C)
vid1 = videoinput('gige',1,'Mono8');
vid1.FramesPerTrigger = 1;
vid1.ROIPosition = [500 300 900 800];
triggerconfig(vid1, 'manual');
vid1.TriggerRepeat = 1000000000;
src1 =
getselectedsource(vid1);
src1.PacketSize = 9014;
src1.PacketDelay = 100;
src1.ExposureAuto = 'Off';
src1.ExposureTimeAbs = 80;
src1.AcquisitionFrameRateAbs = 46;
src1.Gamma = 0.8;
start(vid1);
% Test
for j = 1 : ntest
% Home
errh = XYHome2Phase(xy,5000,5000);
% Move to Target
Position
err2 = XYAbsolute(xy,targetposX,targetposY);
XYWait(xy);
% Wait to Settle
pause(settletime);
% Snap image
frame = getsnapshot(vid1);
% Show and Save image
figure(1); imshow(frame); drawnow;
count = count+1;
imwrite(frame,[imdir '\' pref sprintf('%03d',count)
'.' ext],ext,'Quality',95);
end
% Close camera
stop(vid1);
delete(vid1); clear vid1;
% Delete XYStage object
delete(xy); clear xy;
%After use close serial port
[errc] = EZStepperCloseSerial(s);