diff --git a/Administrator_Input_Screen.m b/Administrator_Input_Screen.m index 0500977b..681d392a 100644 --- a/Administrator_Input_Screen.m +++ b/Administrator_Input_Screen.m @@ -51,7 +51,7 @@ function Administrator_Input_Screen_OpeningFcn(hObject, eventdata, handles, vara handles.myData.wsi_files = []; handles.myData.graphics = struct; - addpath('gui_graphics', 'icc_profiles', 'tasks'); + addpath('gui_graphics', 'icc_profiles', 'tasks','stages/Prior','stages/Ludl'); handles.myData.sourcedir = [cd, '\']; @@ -215,7 +215,6 @@ function ExtractROIsButtonPressed(hObject, eventdata, handles) %#ok handles.myData.tasks_out{i} = taskinfo; end - guidata(handles.Administrator_Input_Screen, handles); close(wtb); @@ -334,7 +333,7 @@ function align_eye_cam(handles) %#ok<*INUSD> try settings = handles.myData.settings; - handles.cam = camera_open(settings.cam_format); + handles.cam = camera_open(settings.cam_kind,settings.cam_format); handles.cam_figure = camera_preview(handles.cam, settings); pos_eye = [0,0]; pos_cam = [0,0]; @@ -528,7 +527,6 @@ function ModeSelectionPopUpMenu_Callback(hObject, eventdata, handles) %#ok if handles.myData.stage.Pos == 0 return @@ -545,7 +543,7 @@ function ModeSelectionPopUpMenu_Callback(hObject, eventdata, handles) %#ok + axis image + set(handles.ImageAxes, 'Visible', 'off'); + fontsize=0.05; + text('Parent', handles.ImageAxes,... + 'FontName', 'Times',... + 'FontUnits', 'normalized',... + 'FontSize', fontsize,... + 'HorizontalAlignment', 'center',... + 'VerticalAlignment', 'middle',... + 'Position', [position(3)/2, position(4)/2],... + 'String', desc); + +catch ME + error_show(ME) +end +end diff --git a/GUI.m b/GUI.m index 01e3f3ce..dcb0f7b7 100644 --- a/GUI.m +++ b/GUI.m @@ -180,7 +180,7 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin) % The mode_index and the filename for the test are extracted from the % cell structure varargin. varargin stores the input arguments for the % whole Matlab application - addpath('gui_graphics', 'icc_profiles', 'tasks'); + addpath('gui_graphics', 'icc_profiles', 'tasks','stages/Prior','stages/Ludl'); handles_old = varargin{1}; handles.Administrator_Input_Screen = handles_old.Administrator_Input_Screen; myData = handles_old.myData; @@ -198,14 +198,13 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin) handles.reticle = 1; settings = myData.settings; guidata(handles.GUI, handles) - % Open communications to camera and begin preview % Open communications to stage switch myData.mode_desc case 'MicroRT' if myData.yesno_micro==1 % Open communications to camera and begin preview - handles.cam=camera_open(); + handles.cam=camera_open(settings.cam_kind,settings.cam_format); handles.cam_figure = ... camera_preview(handles.cam, settings); % To close: @@ -213,7 +212,7 @@ function GUI_OpeningFcn(hObj, eventdata, handles, varargin) % close(cam_figure) % Open communications to stage - handles.myData.stage = stage_open(handles.myData.stage.label); + handles.myData.stage = stage_open(handles.myData.stage.label); % To close: % delete(handles.stage) % If communications with the stage cannot be established, @@ -780,7 +779,7 @@ function Fast_Register_Button_Callback(hObject, eventdata, handles) %#ok [roi_h, roi_w] = size(roi_image); % Get the stage position - handles.myData.stage = stage_get_pos(handles.myData.stage,myData.stage.handle); + handles.myData.stage = stage_get_pos(handles.myData.stage,myData.stage.handle); stage_current = int64(handles.myData.stage.Pos); % Cross correlate the stage and wsi images @@ -809,7 +808,6 @@ function Fast_Register_Button_Callback(hObject, eventdata, handles) %#ok stage_new = stage_current + offset_roi; offset_stage = int64(myData.settings.offset_stage); stage_new = stage_new - offset_stage; - handles.myData.stage = stage_move(handles.myData.stage,stage_new, handles.myData.stage.handle); catch ME error_show(ME) @@ -1074,12 +1072,12 @@ function Best_Register_Button_Callback(hObject, eventdata, handles) [roi_h, roi_w] = size(roi_image); % Get the stage position and snap a picture: cam_image - handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle); + handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle); stage_current = int64(handles.myData.stage.Pos); offset_stage = int64(myData.settings.offset_stage); stage_new = stage_current + offset_stage; handles.myData.stage = stage_move(handles.myData.stage,stage_new,handles.myData.stage.handle); - handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle); + handles.myData.stage = stage_get_pos(handles.myData.stage,handles.myData.stage.handle); stage_current = int64(handles.myData.stage.Pos); cam_image = camera_take_image(handles.cam); @@ -1133,7 +1131,6 @@ function Best_Register_Button_Callback(hObject, eventdata, handles) stage_new = stage_current + offset_roi; offset_stage = int64(myData.settings.offset_stage); stage_new = stage_new - offset_stage; - handles.myData.stage = stage_move(handles.myData.stage,stage_new, handles.myData.stage.handle); catch ME error_show(ME) diff --git a/Load_Input_File.m b/Load_Input_File.m index bbee15d5..aa0a5735 100644 --- a/Load_Input_File.m +++ b/Load_Input_File.m @@ -182,6 +182,14 @@ function Load_Input_File(handles) end tline = fgets(fid); [setting_name, setting_value]=strread(tline, '%s %s', 'delimiter', '='); + name = 'cam_kind'; + if strcmp(strtrim(setting_name),name)==1 + settings.cam_kind=char(setting_value); + else + io_error(name); + end + tline = fgets(fid); + [setting_name, setting_value]=strread(tline, '%s %s', 'delimiter', '='); name = 'cam_format'; if strcmp(strtrim(setting_name),name)==1 settings.cam_format=char(setting_value); diff --git a/SerialPortSetUp.m b/SerialPortSetUp.m index 930f58ba..4ff904cb 100644 --- a/SerialPortSetUp.m +++ b/SerialPortSetUp.m @@ -3,7 +3,7 @@ success = 0; - for i=1:1:12 + for i=1:1:20 Ports{i}=strcat('COM',num2str(i)); end diff --git a/Stage_Allighment.m b/Stage_Allighment.m index eee615a2..0c43c171 100644 --- a/Stage_Allighment.m +++ b/Stage_Allighment.m @@ -39,15 +39,13 @@ function Stage_Allighment_OpeningFcn(hObject, eventdata, handles, varargin) %#ok reg_flag = current.reg_flag; %#ok slot_i = current.slot_i; wsi_info = myData.wsi_files{slot_i}; - + addpath('stages/Prior','stages/Ludl'); % Initiate the camera preview window % handles.cam = camera object if myData.yesno_micro==1 - handles.cam = camera_open(settings.cam_format); + handles.cam = camera_open(settings.cam_kind,settings.cam_format); handles.cam_figure = camera_preview(handles.cam, settings); - myData.stage = stage_set_origin(myData.stage); - myData.stage=stage_move(myData.stage,[50000,50000]); - + myData.stage = stage_set_origin(myData.stage); end % Set the default size of the window and the axes @@ -664,7 +662,7 @@ function take_stage1_Callback(hObject, eventdata, handles) %#ok if handles.current.load_stage_data(1) == 1 display('automatically navigate to position 1') - handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(1,:)); + handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(1,:)); set(handles.take_stage1,'String','Take Stage Position 1'); handles.current.load_stage_data(1) = 2; guidata(handles.Stage_Allighment,handles); @@ -704,8 +702,7 @@ function take_stage2_Callback(hObject, eventdata, handles) %#ok if handles.current.load_stage_data(2) == 1 display('automatically navigate to position 2') - handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(2,:)); - + handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(2,:)); set(handles.take_stage2,'String','Take Stage Position 2'); handles.current.load_stage_data(2) = 2; guidata(handles.Stage_Allighment,handles); @@ -743,8 +740,7 @@ function take_stage3_Callback(hObject, eventdata, handles) %#ok if handles.current.load_stage_data(3) == 1 display('automatically navigate to position 3') - handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(3,:)); - + handles.myData.stage=stage_move(handles.myData.stage,handles.myData.stagedata.stage_positions(3,:)); set(handles.take_stage3,'String','Take Stage Position 3'); handles.current.load_stage_data(3) = 2; guidata(handles.Stage_Allighment,handles); diff --git a/camera_open.m b/camera_open.m index ac442b00..1f0b5735 100644 --- a/camera_open.m +++ b/camera_open.m @@ -1,5 +1,5 @@ -function cam=camera_open(cam_format) +function cam=camera_open(cam_kind,cam_format) try % imaqtool: launches an interactive GUI to allow you to explore, @@ -25,12 +25,16 @@ % delete any currently running (stale) video inputs objects = imaqfind; delete(objects); - + if strcmp( cam_kind,'USB') + cam_adaptor = 'pointgrey'; + elseif strcmp( cam_kind,'Firewire') + cam_adaptor = 'dcam'; + end % Create the video object to communicate with the camera if exist('cam_format','var') - cam = videoinput('dcam',1,cam_format) %#ok + cam = videoinput(cam_adaptor,1,cam_format) %#ok else - cam = videoinput('dcam',1) %#ok + cam = videoinput(cam_adaptor,1) %#ok end imaqhwinfo(cam) cam.Tag = 'Microscope Camera Object'; @@ -57,7 +61,9 @@ % Set value of a video source object property. cam_src = getselectedsource(cam); cam_src.Tag = 'Microscope Camera Source'; - + if strcmp( cam_kind,'USB') + cam_src.WhiteBalanceRBMode = 'Off'; + end catch ME error_show(ME) end diff --git a/sample_inputfiles/thorlabs20x-axioplan2i.dapsi b/sample_inputfiles/thorlabs20x-axioplan2i.dapsi index 1afdf14e..4a2ec296 100644 --- a/sample_inputfiles/thorlabs20x-axioplan2i.dapsi +++ b/sample_inputfiles/thorlabs20x-axioplan2i.dapsi @@ -38,6 +38,7 @@ wsi_slot_1 = C:\000_whole_slides\100113_ThorLabs_20x.ndpi rgb_lut_slot_1 = icc_profiles\rgb_lut_identity.txt label_pos = 6 reticleID = KR-32536 +cam_kind = Firewire cam_format = RGB24_1024x768 cam_pixel_size = 6.9 mag_cam = 1.0 diff --git a/sample_inputfiles/thorlabs20x-axioplan2i_RK871.dapsi b/sample_inputfiles/thorlabs20x-axioplan2i_RK871.dapsi index 492756d9..5c1262ff 100644 --- a/sample_inputfiles/thorlabs20x-axioplan2i_RK871.dapsi +++ b/sample_inputfiles/thorlabs20x-axioplan2i_RK871.dapsi @@ -38,6 +38,7 @@ wsi_slot_1 = C:\000_whole_slides\100113_ThorLabs_20x.ndpi rgb_lut_slot_1 = icc_profiles\rgb_lut_identity.txt label_pos = 6 reticleID = KR-871 +cam_kind = Firewire cam_format = RGB24_1024x768 cam_pixel_size = 6.9 mag_cam = 1.0 diff --git a/sample_inputfiles/thorlabs20x-olympus.dapsi b/sample_inputfiles/thorlabs20x-olympus.dapsi index d574e7ba..f2f212e2 100644 --- a/sample_inputfiles/thorlabs20x-olympus.dapsi +++ b/sample_inputfiles/thorlabs20x-olympus.dapsi @@ -38,6 +38,7 @@ wsi_slot_1 = C:\000_whole_slides\100113_ThorLabs_20x.ndpi rgb_lut_slot_1 = icc_profiles\rgb_lut_identity.txt label_pos = 12 reticleID = KR-32536 +cam_kind = Firewire cam_format = RGB24_1024x768 cam_pixel_size = 6.9 mag_cam = 0.5 diff --git a/sample_inputfiles/tissue40x-8B-axioplan2i.dapsi b/sample_inputfiles/tissue40x-8B-axioplan2i.dapsi index 6e73f07c..92d1a2b2 100644 --- a/sample_inputfiles/tissue40x-8B-axioplan2i.dapsi +++ b/sample_inputfiles/tissue40x-8B-axioplan2i.dapsi @@ -44,6 +44,7 @@ wsi_slot_1 = C:\000_whole_slides\tissue40x-8B.ndpi rgb_lut_slot_1 = icc_profiles\rgb_lut_gamma_inv1p8.txt label_pos = 6 reticleID = KR-871 +cam_kind = Firewire cam_format = RGB24_1024x768 cam_pixel_size = 6.9 mag_cam = 1.0 diff --git a/sample_inputfiles/tissue40x-8B-olympus - USB.dapsi b/sample_inputfiles/tissue40x-8B-olympus - USB.dapsi new file mode 100644 index 00000000..e4f25ce2 --- /dev/null +++ b/sample_inputfiles/tissue40x-8B-olympus - USB.dapsi @@ -0,0 +1,63 @@ +Author: +Date: +Time: + +For the Hamamatsu scanning at 20x + scan_scale = .4558 +For the Hamamatsu scanning at 40x + scan_scale = .2279 + +Point Grey Grashopper Color (GRAS-03K2C-C) + cam_format = RGB24_640x480 + cam_pixel_size = 7.4um +Point Grey Flea2 Color (FL2G-50S5C-C): Full resolution, full format + cam_format = F7_RGB24_2448x2048 + cam_pixel_size = 3.45 +Point Grey Flea2 Color (FL2G-50S5C-C): Standard format, aspect ratio = 1.33 + cam_format = RGB24_1024x768 + cam_pixel_size = 6.9 + +Reminder: +taskorder=2 user specified order +taskorder=1 listed order +taskorder=0 random order +saveimages = 1 save WSI and camera images +saveimages = 2 only save WSI image +saveimages = 3 only save camera image +saveimages = 4 don't save WSI and camera images + + +Input File Task Formats +Task,TaskID,TaskOrder,Slot,ROI_X,ROI_Y,ROI_W,ROI_H,IMG_W,IMG_H,Qtext,MoveFlag,ZoomFlag,Q_Op1,Q_Op2,Q_Op3,Q_Op4 + + + +SETTINGS +NUMBER_OF_WSI = 1 +wsi_slot_1 = C:\000_whole_slides\tissue40x-8B.ndpi +rgb_lut_slot_1 = icc_profiles\rgb_lut_gamma_inv1p8.txt +label_pos = 12 +reticleID = KR-871 +cam_kind = USB +cam_format = F7_RGB_1224x1024_Mode1 +cam_pixel_size = 6.9 +mag_cam = 0.5 +mag_lres = 10 +mag_hres = 40 +scan_scale = 0.2279 +stage_label = H101-Prior +BG_Color_RGB = 0.55 = 0.55 = 0.55 +FG_Color_RGB = 0.00 = 0.00 = 0.00 +AxesBG_Color_RGB = 0.10 = 0.20 = 0.10 +FontSize = 13 +saveimages = 1 +taskorder = 0 + +BODY +start +finish +radio1of4,1st0001,-1,1,038459,16192,300,300,300,300,Qtext_radio1of1,1,1,Q_Op1,Q_Op2,Q_Op3,Q_Op4 +count,2nd0001,-1,1,027728,11381,300,300,300,300,Qtext_count,1,1,description +slider,3rd0001,-1,1,19220,49879,300,300,300,300,Qtext_slider,1,1,Q_Op1,Q_Op2,Q_Op3,Q_Op4 +mark1,4th0001,-1,1,041163,33208,300,700,300,700,Qtext_select_region,1,1,Q_Op1,Q_Op2,Q_Op3,Q_Op4 +mark1_out,5th0001,-1,1,041163,33208,700,700,700,700,Qtext_select_region,1,1,Q_Op1,Q_Op2,Q_Op3,Q_Op4 diff --git a/sample_inputfiles/tissue40x-8B-olympus.dapsi b/sample_inputfiles/tissue40x-8B-olympus.dapsi index d7b23686..112378a8 100644 --- a/sample_inputfiles/tissue40x-8B-olympus.dapsi +++ b/sample_inputfiles/tissue40x-8B-olympus.dapsi @@ -38,6 +38,7 @@ wsi_slot_1 = C:\000_whole_slides\tissue40x-8B.ndpi rgb_lut_slot_1 = icc_profiles\rgb_lut_gamma_inv1p8.txt label_pos = 12 reticleID = KR-32536 +cam_kind = Firewire cam_format = RGB24_1024x768 cam_pixel_size = 6.9 mag_cam = 0.5 diff --git a/stage_get_pos.m b/stage_get_pos.m index 132b90e4..e9ce5c00 100644 --- a/stage_get_pos.m +++ b/stage_get_pos.m @@ -8,51 +8,21 @@ % objects can be cleared from memory with % delete(objects) try - - stage.Pos = 0; - % If communications to stage is not open to start, then open. - % Also prepare to close - h_stage_close = 0; - if exist('h_stage', 'var') == 0 - h_stage_close = 1; - [stage] = stage_open(stage.label); - % If communications with the stage cannot be established, - % eeDAP is closing. - if stage.status == 0 - desc = ['Communications with the stage is not established.',... - ' eeDAP is closing.'] %#ok - h_errordlg = errordlg(desc,'Application error','modal'); - uiwait(h_errordlg) - close all force; - return + stage_label = stage.label; + if strcmp(stage_label(end-4:end),'Prior') + if exist('h_stage', 'var') == 0 + stage = stage_get_pos_prior(stage); + else + stage = stage_get_pos_prior(stage,h_stage); + end + else + if exist('h_stage', 'var') == 0 + stage = stage_get_pos_Ludl(stage); + else + stage = stage_get_pos_Ludl(stage,h_stage); end end - % Get the x,y position - % command_str = 'where x y'; - command_str = sprintf('where x y'); - str_current = send_com (stage.handle, command_str); - i=1; - while numel(str_current) == 0 && i<100 - pause(.1) - str_current = send_com (stage.handle, command_str); - i=i+1; - end - if i==100 - i/0; %#ok - end - if str_current(2) ~='A' - 'A'/0; %#ok - end - - temp = textscan(str_current, '%s %d %d'); - stage.Pos = int64([temp{2}, temp{3}]); - - % If communications to stage was not open to start, then close. - if h_stage_close == 1 - stage.status = stage_close(stage.handle); - end - catch ME error_show(ME) end diff --git a/stage_move.m b/stage_move.m index 4a1bddf0..93fcdb43 100644 --- a/stage_move.m +++ b/stage_move.m @@ -18,71 +18,20 @@ % delete(objects) try - % If communications to stage is not open to start, then open. - % Also prepare to close - h_stage_close = 0; - if exist('h_stage', 'var') == 0 - h_stage_close = 1; - [stage] = stage_open(stage.label); - % If communications with the stage cannot be established, - % eeDAP is closing. - if stage.status == 0 - desc = ['Communications with the stage is not established.',... - 'eeDAP is closing.'] %#ok - h_errordlg = errordlg(desc,'Application error','modal'); - uiwait(h_errordlg) - close all force; - return + stage_label = stage.label; + if strcmp(stage_label(end-4:end),'Prior') + if exist('h_stage', 'var') == 0 + stage = stage_move_prior(stage, target_pos); + else + stage = stage_move_prior(stage, target_pos,h_stage); + end + else + if exist('h_stage', 'var') == 0 + stage = stage_move_Ludl(stage, target_pos); + else + stage = stage_move_Ludl(stage, target_pos,h_stage); end end - - % Target position needs to be a 64 bit integer - target_pos = int64(target_pos); - - % Get current poistion - stage=stage_get_pos(stage,stage.handle); - Initial_Pos = stage.Pos; - % Start moving to the desired position - command_str_speed = ['SPEED',... - ' x=', num2str(stage.speed),... - ' y=',num2str(stage.speed)]; - send_com (stage.handle, command_str_speed); - command_str_accel = ['ACCEL',... - ' x=', num2str(stage.accel),... - ' y=',num2str(stage.accel)]; - send_com (stage.handle, command_str_accel); - send_com (stage.handle, 'SPEED X Y'); - send_com (stage.handle, 'ACCEL X Y'); - command_str = ['move',... - ' x=', num2str(target_pos(1)),... - ' y=',num2str(target_pos(2))]; - send_com (stage.handle, command_str); - - % Display the waitbar - wtb=waitbar(0,'Moving the stage...', 'WindowStyle', 'modal'); - % Keep updating the waitbar - while stage_check_busy(stage.handle) - stage=stage_get_pos(stage,stage.handle) ; - current_pos=stage.Pos; - pause(.5) - distance_traveled = pdist2(... - double(Initial_Pos),... - double(current_pos),'euclidean'); - distance_total = pdist2(... - double(Initial_Pos),... - double(target_pos),'euclidean'); - - waitbar(distance_traveled / distance_total); - drawnow; - end - % Close the waitbar - close(wtb); - - % If communications to stage was not open to start, then close. - if h_stage_close == 1 - stage.status = stage_close(stage.handle); - end - catch ME error_show(ME) end diff --git a/stage_open.m b/stage_open.m index 646401cc..7cf9e75a 100644 --- a/stage_open.m +++ b/stage_open.m @@ -2,105 +2,13 @@ function stage = stage_open(label) try - % instrfind returns the instrument object array - % objects = instrfind - % each entry includes the type, status, and name as follows - % Index: Type: Status: Name: - % 1 serial closed Serial-COM4 - % - % objects can be cleared from memory with - % delete(objects) - - objects = instrfind; - delete(objects); - - % Return value if unable to open stage - stage.handle=''; - stage.label=label; - - switch label - case 'SCAN8Praparate_Ludl5000' - stage.speed=50000; - stage.accel=100; - stage.scale=0.1; - case 'SCAN8Praparate_Ludl6000' - stage.speed=200000; - stage.accel=1; - stage.scale=0.025; - case 'BioPrecision2-LE2_Ludl5000' - stage.speed=40000; - stage.accel=100; - stage.scale=0.2; - case 'BioPrecision2-LE2_Ludl6000' - stage.speed=150000; - stage.accel=1; - stage.scale=0.05; - otherwise - stage.speed=50000; - stage.accel=100; - stage.scale=0.1; - end - - % Test to see if the COM port is set in the file PortNames.mat - try - % PortNames.mat contains SerialPortStage, the last port used and - % saved - load('PortNames.mat'); - catch ME - stage.status = SerialPortSetUp(); - if stage.status == 1 - stage = stage_open(stage.label); - end - return + if strcmp(label(end-4:end),'Prior') + stage = stage_open_prior(label); + else + stage = stage_open_Ludl(label); end - stage.handle = serial(SerialPortStage,... - 'RequestToSend','off',... - 'Timeout',3,... - 'Baudrate',9600,... - 'Parity', 'none',... - 'Stopbits', 2); - - % Test to see if the COM port is a legitimate COM port - try - fopen(stage.handle); - catch ME - - delete(stage.handle); - stage.handle = ''; - desc = textscan(ME.message,'%s','delimiter','\n'); - desc = desc{1}; - desc = desc(1,:) - h_errordlg = errordlg(desc,'Application error','modal'); - uiwait(h_errordlg) - - stage.status = SerialPortSetUp(); - if stage.status == 1 - stage = stage_open(stage.label); - end - return - end - - % Test to see if the COM port is attached to the stage - desc_status = send_com (stage.handle, 'STATUS'); - if ~strcmp(desc_status, 'N') && ~strcmp(desc_status, 'B') - - delete(stage.handle); - stage.handle = ''; - desc = 'The selected COM port is not connected to the stage.' - h_errordlg = errordlg(desc,'Application error','modal'); - uiwait(h_errordlg) - - stage.status = SerialPortSetUp(); - if stage.status == 1 - stage = stage_open(stage.label); - end - return - end - - stage.status = 1; - catch ME error_show(ME) end diff --git a/stage_send_com.m b/stage_send_com.m deleted file mode 100644 index 761e184b..00000000 --- a/stage_send_com.m +++ /dev/null @@ -1,57 +0,0 @@ -% ########################################################################## -%% ########################## SEND COMMAND ################################## -% ########################################################################## -function ST_answer=stage_send_com (S, CommandStr) - %-------------------------------------------------------------------------- - % This function sends commands to the stage. THe opened serial port S - % is passed as the first argument. The secong argument is the string of - % the command - %-------------------------------------------------------------------------- - try - - %Get the lenght of the command - for i=1:size(CommandStr,2) - fwrite(S,CommandStr(i)); - end - % send the termination char - fwrite(S,13); - - % The response of the stage to 'STATUS' doesn't have the terminator. - % THerefore if the command it 'STATUS' the code only reads one command - if strcmp(CommandStr,'STATUS') - ST_answer=fscanf(S,'%s',1); - else - ST_answer=fgetl(S); - end - - % These are the error messages that can come from the stage - if strcmp('N: -1',ST_answer) - disp('Unknown command'); - ST_answer=-1; - end - if strcmp('N: -2',ST_answer) - disp('Illegal point type or axis, or module not installed'); - errordlg('Illegal point type or axis, or module not installed!','Stage Error'); - ST_answer=-1; - end - if strcmp('N: -3',ST_answer) - disp('Not enough parameters (e.g. move r=)'); - errordlg('Not enough parameters (e.g. move r=)!','Stage Error'); - ST_answer=-1; - end - if strcmp('N: -4',ST_answer) - disp('Parameter out of range'); - errordlg('Parameter out of range!','Stage Error'); - ST_answer=-1; - end - if strcmp('N: -21',ST_answer) - disp('Process aborted by HALT command'); - errordlg('Process aborted by HALT command!','Stage Error'); - ST_answer=-1; - end - catch - disp('Error in stage_send_com (S, CommandStr)'); - errordlg('Unable to send a command to the stage!','Stage Error'); - ST_answer=-1; - end -end \ No newline at end of file diff --git a/stage_set_origin.m b/stage_set_origin.m index 06236134..4dcd8a59 100644 --- a/stage_set_origin.m +++ b/stage_set_origin.m @@ -3,63 +3,21 @@ % ########################################################################## function stage = stage_set_origin(stage,h_stage) try - - % If communications to stage is not open to start, then open. - % Also prepare to close - h_stage_close = 0; - if exist('h_stage', 'var') == 0 - h_stage_close = 1; - [stage] = stage_open(stage.label); - % If communications with the stage cannot be established, - % eeDAP is closing. - if stage.status == 0 - desc = ['Communications with the stage is not established.',... - 'eeDAP is closing.'] %#ok - h_errordlg = errordlg(desc,'Application error','modal'); - uiwait(h_errordlg) - close all force; - return + stage_label = stage.label; + if strcmp(stage_label(end-4:end),'Prior') + if exist('h_stage', 'var') == 0 + stage = stage_set_origin_prior(stage); + else + stage = stage_set_origin_prior(stage,h_stage); + end + else + if exist('h_stage', 'var') == 0 + stage = stage_set_origin_Ludl(stage); + else + stage = stage_set_origin_Ludl(stage,h_stage); end - end - - % Speed to the top-left corner - success = send_com (stage.handle, 'SPEED X=200000 Y=200000'); %#ok<*NASGU> - success = send_com (stage.handle, 'ACCEL X=1 Y=1'); - success = send_com(stage.handle, 'HOME X Y'); - % Wait til the stage gets to the top-left corner - while stage_check_busy(stage.handle) - pause(.5) - end - % Set the top-left corner to be the origin - success = send_com(stage.handle, 'HERE X=0 Y=0'); - - % For better precision, slow it down, move it away, and go back home - success = send_com (stage.handle, 'SPEED X=100 Y=100'); - success = send_com (stage.handle, 'ACCEL X=255 Y=255'); - success = send_com (stage.handle, 'MOVE X=100 Y=100'); - success = send_com(stage.handle, 'MOVE X=-25 Y=-25'); - while stage_check_busy(stage.handle) - pause(.5) - end - - % Reset the top-left corner to be the origin - success = send_com (stage.handle, 'HERE X=0 Y=0'); - - % If communications to stage was not open to start, then close. - if h_stage_close == 1 - stage.status=stage_close(stage.handle); - end -% ########################################################################## -%% ###################### MOVE STAGE SEQUENCE ############################### -% ########################################################################## -% success=send_com (S, 'SPEED X=50000 Y=50000'); -% success=send_com (S, 'SPEED X Y'); -% success=send_com (S, 'ACCEL X=100 Y=100'); -% success=send_com (S, 'ACCEL X Y'); -% command_str=char(strcat('move',' x=',num2str(Pos(1)),... -% ' y=',num2str(Pos(2)))); -% success=send_com (S, command_str); + end catch ME error_show(ME); diff --git a/stage_check_busy.m b/stages/Ludl/stage_check_busy_Ludl.m similarity index 62% rename from stage_check_busy.m rename to stages/Ludl/stage_check_busy_Ludl.m index 15f80baa..53b60d2e 100644 --- a/stage_check_busy.m +++ b/stages/Ludl/stage_check_busy_Ludl.m @@ -1,7 +1,7 @@ -function busy = stage_check_busy(S) +function busy = stage_check_busy_Ludl(S) try - success=send_com (S, 'STATUS'); + success=stage_send_com_Ludl (S, 'STATUS'); if isempty(success) busy = 1; return diff --git a/stages/Ludl/stage_get_pos_Ludl.m b/stages/Ludl/stage_get_pos_Ludl.m new file mode 100644 index 00000000..966c7303 --- /dev/null +++ b/stages/Ludl/stage_get_pos_Ludl.m @@ -0,0 +1,59 @@ +function stage=stage_get_pos_Ludl(stage,h_stage) +% instrfind returns the instrument object array +% objects = instrfind +% each entry includes the type, status, and name as follows +% Index: Type: Status: Name: +% 1 serial closed Serial-COM4 +% +% objects can be cleared from memory with +% delete(objects) +try + + stage.Pos = 0; + % If communications to stage is not open to start, then open. + % Also prepare to close + h_stage_close = 0; + if exist('h_stage', 'var') == 0 + h_stage_close = 1; + [stage] = stage_open_Ludl(stage.label); + % If communications with the stage cannot be established, + % eeDAP is closing. + if stage.status == 0 + desc = ['Communications with the stage is not established.',... + ' eeDAP is closing.'] %#ok + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + close all force; + return + end + end + + % Get the x,y position + % command_str = 'where x y'; + command_str = sprintf('where x y'); + str_current = stage_send_com_Ludl (stage.handle, command_str); + i=1; + while numel(str_current) == 0 && i<100 + pause(.1) + str_current = stage_send_com_Ludl (stage.handle, command_str); + i=i+1; + end + if i==100 + i/0; %#ok + end + if str_current(2) ~='A' + 'A'/0; %#ok + end + + temp = textscan(str_current, '%s %d %d'); + stage.Pos = int64([temp{2}, temp{3}]); + + % If communications to stage was not open to start, then close. + if h_stage_close == 1 + stage.status = stage_close(stage.handle); + end + +catch ME + error_show(ME) +end +end \ No newline at end of file diff --git a/stages/Ludl/stage_move_Ludl.m b/stages/Ludl/stage_move_Ludl.m new file mode 100644 index 00000000..91ff7e61 --- /dev/null +++ b/stages/Ludl/stage_move_Ludl.m @@ -0,0 +1,90 @@ +% ########################################################################## +%% ###################### MOVE STAGE SEQUENCE ############################### +% ########################################################################## +function stage=stage_move_Ludl(stage, target_pos, h_stage) +%-------------------------------------------------------------------------- +% Move_Stage_Seq starts a []sequence that moves the stage from position A +% to position B. THe function displays a waitbar and also adjusts +% the acceleration and the speed of the stage. Target position is +% specified as a horizontal vector of size 2. +%-------------------------------------------------------------------------- +% instrfind returns the instrument object array +% objects = instrfind +% each entry includes the type, status, and name as follows +% Index: Type: Status: Name: +% 1 serial closed Serial-COM4 +% +% objects can be cleared from memory with +% delete(objects) +try + + % If communications to stage is not open to start, then open. + % Also prepare to close + h_stage_close = 0; + if exist('h_stage', 'var') == 0 + h_stage_close = 1; + [stage] = stage_open_Ludl(stage.label); + % If communications with the stage cannot be established, + % eeDAP is closing. + if stage.status == 0 + desc = ['Communications with the stage is not established.',... + 'eeDAP is closing.'] %#ok + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + close all force; + return + end + end + + % Target position needs to be a 64 bit integer + target_pos = int64(target_pos); + + % Get current poistion + stage=stage_get_pos_Ludl(stage,stage.handle); + Initial_Pos = stage.Pos; + % Start moving to the desired position + command_str_speed = ['SPEED',... + ' x=', num2str(stage.speed),... + ' y=',num2str(stage.speed)]; + stage_send_com_Ludl (stage.handle, command_str_speed); + command_str_accel = ['ACCEL',... + ' x=', num2str(stage.accel),... + ' y=',num2str(stage.accel)]; + stage_send_com_Ludl (stage.handle, command_str_accel); + stage_send_com_Ludl (stage.handle, 'SPEED X Y'); + stage_send_com_Ludl (stage.handle, 'ACCEL X Y'); + command_str = ['move',... + ' x=', num2str(target_pos(1)),... + ' y=',num2str(target_pos(2))]; + stage_send_com_Ludl (stage.handle, command_str); + + % Display the waitbar + wtb=waitbar(0,'Moving the stage...', 'WindowStyle', 'modal'); + % Keep updating the waitbar + while stage_check_busy_Ludl(stage.handle) + stage=stage_get_pos_Ludl(stage,stage.handle) ; + current_pos=stage.Pos; + pause(.5) + distance_traveled = pdist2(... + double(Initial_Pos),... + double(current_pos),'euclidean'); + distance_total = pdist2(... + double(Initial_Pos),... + double(target_pos),'euclidean'); + + waitbar(distance_traveled / distance_total); + drawnow; + end + % Close the waitbar + close(wtb); + + % If communications to stage was not open to start, then close. + if h_stage_close == 1 + stage.status = stage_close(stage.handle); + end + +catch ME + error_show(ME) +end + +end \ No newline at end of file diff --git a/stages/Ludl/stage_open_Ludl.m b/stages/Ludl/stage_open_Ludl.m new file mode 100644 index 00000000..b03d8281 --- /dev/null +++ b/stages/Ludl/stage_open_Ludl.m @@ -0,0 +1,107 @@ + +function stage = stage_open_Ludl(label) +try + + % instrfind returns the instrument object array + % objects = instrfind + % each entry includes the type, status, and name as follows + % Index: Type: Status: Name: + % 1 serial closed Serial-COM4 + % + % objects can be cleared from memory with + % delete(objects) + + objects = instrfind; + delete(objects); + + % Return value if unable to open stage + stage.handle=''; + stage.label=label; + + switch label + case 'SCAN8Praparate_Ludl5000' + stage.speed=50000; + stage.accel=100; + stage.scale=0.1; + case 'SCAN8Praparate_Ludl6000' + stage.speed=200000; + stage.accel=1; + stage.scale=0.025; + case 'BioPrecision2-LE2_Ludl5000' + stage.speed=40000; + stage.accel=100; + stage.scale=0.2; + case 'BioPrecision2-LE2_Ludl6000' + stage.speed=150000; + stage.accel=1; + stage.scale=0.05; + otherwise + stage.speed=50000; + stage.accel=100; + stage.scale=0.1; + end + + + % Test to see if the COM port is set in the file PortNames.mat + try + % PortNames.mat contains SerialPortStage, the last port used and + % saved + load('PortNames.mat'); + catch ME + stage.status = SerialPortSetUp(); + if stage.status == 1 + stage = stage_open_Ludl(stage.label); + end + return + end + + stage.handle = serial(SerialPortStage,... + 'RequestToSend','off',... + 'Timeout',3,... + 'Baudrate',9600,... + 'Parity', 'none',... + 'Stopbits', 2); + + % Test to see if the COM port is a legitimate COM port + try + fopen(stage.handle); + catch ME + + delete(stage.handle); + stage.handle = ''; + desc = textscan(ME.message,'%s','delimiter','\n'); + desc = desc{1}; + desc = desc(1,:) + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + + stage.status = SerialPortSetUp(); + if stage.status == 1 + stage = stage_open_Ludl(stage.label); + end + return + end + + % Test to see if the COM port is attached to the stage + desc_status = stage_send_com_Ludl(stage.handle, 'STATUS'); + if ~strcmp(desc_status, 'N') && ~strcmp(desc_status, 'B') + + delete(stage.handle); + stage.handle = ''; + desc = 'The selected COM port is not connected to the stage.' + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + + stage.status = SerialPortSetUp(); + if stage.status == 1 + stage = stage_open_Ludl(stage.label); + end + return + end + + stage.status = 1; + +catch ME + error_show(ME) +end +end \ No newline at end of file diff --git a/send_com.m b/stages/Ludl/stage_send_com_Ludl.m similarity index 92% rename from send_com.m rename to stages/Ludl/stage_send_com_Ludl.m index 7363affb..19634675 100644 --- a/send_com.m +++ b/stages/Ludl/stage_send_com_Ludl.m @@ -1,7 +1,7 @@ % ########################################################################## %% ########################## SEND COMMAND ################################## % ########################################################################## -function ST_answer=send_com (S, CommandStr) +function ST_answer=stage_send_com_Ludl (S, CommandStr) %-------------------------------------------------------------------------- % This function sends commands to the stage. THe opened serial port S % is passed as the first argument. The secong argument is the string of @@ -51,7 +51,7 @@ end catch - disp('Error in send_com (S, CommandStr)'); + disp('Error in Ludl: stage_send_com (S, CommandStr)'); errordlg('Unable to send a command to the stage!','Stage Error'); ST_answer=-1; end diff --git a/stages/Ludl/stage_set_origin_Ludl.m b/stages/Ludl/stage_set_origin_Ludl.m new file mode 100644 index 00000000..bf036671 --- /dev/null +++ b/stages/Ludl/stage_set_origin_Ludl.m @@ -0,0 +1,69 @@ +% ########################################################################## +%% ###################### MOVE STAGE SEQUENCE ############################### +% ########################################################################## +function stage = stage_set_origin_Ludl(stage,h_stage) +try + + % If communications to stage is not open to start, then open. + % Also prepare to close + h_stage_close = 0; + if exist('h_stage', 'var') == 0 + h_stage_close = 1; + [stage] = stage_open_Ludl(stage.label); + % If communications with the stage cannot be established, + % eeDAP is closing. + if stage.status == 0 + desc = ['Communications with the stage is not established.',... + 'eeDAP is closing.'] %#ok + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + close all force; + return + end + end + + % Speed to the top-left corner + success = stage_send_com_Ludl (stage.handle, 'SPEED X=200000 Y=200000'); %#ok<*NASGU> + success = stage_send_com_Ludl (stage.handle, 'ACCEL X=1 Y=1'); + success = stage_send_com_Ludl(stage.handle, 'HOME X Y'); + % Wait til the stage gets to the top-left corner + while stage_check_busy_Ludl(stage.handle) + pause(.5) + end + % Set the top-left corner to be the origin + success = stage_send_com_Ludl(stage.handle, 'HERE X=0 Y=0'); + + % For better precision, slow it down, move it away, and go back home + success = stage_send_com_Ludl (stage.handle, 'SPEED X=100 Y=100'); + success = stage_send_com_Ludl (stage.handle, 'ACCEL X=255 Y=255'); + success = stage_send_com_Ludl (stage.handle, 'MOVE X=100 Y=100'); + success = stage_send_com_Ludl(stage.handle, 'MOVE X=-25 Y=-25'); + while stage_check_busy_Ludl(stage.handle) + pause(.5) + end + + % Reset the top-left corner to be the origin + success = stage_send_com_Ludl (stage.handle, 'HERE X=0 Y=0'); + + % If communications to stage was not open to start, then close. + if h_stage_close == 1 + stage.status=stage_close(stage.handle); + end + stage=stage_move_Ludl(stage,[50000,50000]); +% ########################################################################## +%% ###################### MOVE STAGE SEQUENCE ############################### +% ########################################################################## +% success=send_com (S, 'SPEED X=50000 Y=50000'); +% success=send_com (S, 'SPEED X Y'); +% success=send_com (S, 'ACCEL X=100 Y=100'); +% success=send_com (S, 'ACCEL X Y'); +% command_str=char(strcat('move',' x=',num2str(Pos(1)),... +% ' y=',num2str(Pos(2)))); +% success=send_com (S, command_str); + +catch ME + error_show(ME); +end + +end + diff --git a/stages/Prior/stage_check_busy_prior.m b/stages/Prior/stage_check_busy_prior.m new file mode 100644 index 00000000..07ebd75a --- /dev/null +++ b/stages/Prior/stage_check_busy_prior.m @@ -0,0 +1,17 @@ + +%% ################# CHECK STAGE STATUS FOR PRIOR ########################## +function busy = stage_check_busy_prior(S) +try + + status=stage_send_com_prior (S, '#'); + if isempty(status) + busy = 1; + return + end + busy = str2num(status); + +catch ME + error_show(ME) +end + +end \ No newline at end of file diff --git a/stages/Prior/stage_get_pos_prior.m b/stages/Prior/stage_get_pos_prior.m new file mode 100644 index 00000000..204bd488 --- /dev/null +++ b/stages/Prior/stage_get_pos_prior.m @@ -0,0 +1,60 @@ + +%% ################# GET STAGE POSITION SEQUENCE FOR PRIOR ########################## +function stage=stage_get_pos_prior(stage,h_stage) +% instrfind returns the instrument object array +% objects = instrfind +% each entry includes the type, status, and name as follows +% Index: Type: Status: Name: +% 1 serial closed Serial-COM4 +% +% objects can be cleared from memory with +% delete(objects) +try + + stage.Pos = 0; + % If communications to stage is not open to start, then open. + % Also prepare to close + h_stage_close = 0; + if exist('h_stage', 'var') == 0 + h_stage_close = 1; + [stage] = stage_open_prior(stage.label); + % If communications with the stage cannot be established, + % eeDAP is closing. + if stage.status == 0 + desc = ['Communications with the stage is not established.',... + ' eeDAP is closing.'] %#ok + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + close all force; + return + end + end + + % Get the x,y position + % command_str = 'where x y'; + command_str = sprintf('PS'); + str_current = stage_send_com_prior (stage.handle, command_str); + i=1; + while numel(str_current) == 0 && i<100 + pause(.1) + str_current = stage_send_com_prior (stage.handle, command_str); + i=i+1; + end + if i==100 + i/0; %#ok + end + if str_current(2) ~='A' + 'A'/0; %#ok + end + temp = textscan(str_current, '%d %d','Delimiter',','); + stage.Pos = int64([temp{1}, temp{2}]); + + % If communications to stage was not open to start, then close. + if h_stage_close == 1 + stage.status = stage_close(stage.handle); + end + +catch ME + error_show(ME) +end +end \ No newline at end of file diff --git a/stages/Prior/stage_move_prior.m b/stages/Prior/stage_move_prior.m new file mode 100644 index 00000000..bc7d1f6f --- /dev/null +++ b/stages/Prior/stage_move_prior.m @@ -0,0 +1,92 @@ +% ########################################################################## +%% ################# MOVE STAGE SEQUENCE FOR PRIOR ########################## +% ########################################################################## +function stage=stage_move_prior(stage, target_pos, h_stage) +%-------------------------------------------------------------------------- +% Move_Stage_Seq starts a []sequence that moves the stage from position A +% to position B. THe function displays a waitbar and also adjusts +% the acceleration and the speed of the stage. Target position is +% specified as a horizontal vector of size 2. +%-------------------------------------------------------------------------- +% instrfind returns the instrument object array +% objects = instrfind +% each entry includes the type, status, and name as follows +% Index: Type: Status: Name: +% 1 serial closed Serial-COM4 +% +% objects can be cleared from memory with +% delete(objects) +try + + % If communications to stage is not open to start, then open. + % Also prepare to close + h_stage_close = 0; + if exist('h_stage', 'var') == 0 + h_stage_close = 1; + [stage] = stage_open_prior(stage.label); + % If communications with the stage cannot be established, + % eeDAP is closing. + if stage.status == 0 + desc = ['Communications with the stage is not established.',... + 'eeDAP is closing.'] %#ok + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + close all force; + return + end + end + + % Target position needs to be a 64 bit integer + target_pos = int64(target_pos); + + % Get current poistion + stage=stage_get_pos_prior(stage,stage.handle); + Initial_Pos = stage.Pos; + % Start moving to the desired position +% command_str_speed = ['SPEED',... +% ' x=', num2str(stage.speed),... +% ' y=',num2str(stage.speed)]; +% send_com (stage.handle, command_str_speed); +% command_str_accel = ['ACCEL',... +% ' x=', num2str(stage.accel),... +% ' y=',num2str(stage.accel)]; +% send_com (stage.handle, command_str_accel); +% send_com (stage.handle, 'SPEED X Y'); +% send_com (stage.handle, 'ACCEL X Y'); + stage_send_com_prior (stage.handle, 'SMS 50'); + stage_send_com_prior (stage.handle, 'SAS 50'); + command_str = ['G ',... + num2str(target_pos(1)),... + ',',num2str(target_pos(2))]; + stage_send_com_prior (stage.handle, command_str); + + % Display the waitbar + wtb=waitbar(0,'Moving the stage...', 'WindowStyle', 'modal'); + % Keep updating the waitbar + while stage_check_busy_prior(stage.handle) + stage=stage_get_pos_prior(stage,stage.handle) ; + current_pos=stage.Pos; + pause(.5) + distance_traveled = pdist2(... + double(Initial_Pos),... + double(current_pos),'euclidean'); + distance_total = pdist2(... + double(Initial_Pos),... + double(target_pos),'euclidean'); + + waitbar(distance_traveled / distance_total); + drawnow; + end + % Close the waitbar + close(wtb); + + % If communications to stage was not open to start, then close. + if h_stage_close == 1 + stage.status = stage_close(stage.handle); + end + +catch ME + error_show(ME) +end + +end \ No newline at end of file diff --git a/stages/Prior/stage_open_prior.m b/stages/Prior/stage_open_prior.m new file mode 100644 index 00000000..2924ef5b --- /dev/null +++ b/stages/Prior/stage_open_prior.m @@ -0,0 +1,84 @@ + +function stage = stage_open_prior(label) +try + + % instrfind returns the instrument object array + % objects = instrfind + % each entry includes the type, status, and name as follows + % Index: Type: Status: Name: + % 1 serial closed Serial-COM4 + % + % objects can be cleared from memory with + % delete(objects) + + objects = instrfind; + delete(objects); + + + % Test to see if the COM port is set in the file PortNames.mat + try + % PortNames.mat contains SerialPortStage, the last port used and + % saved + load('PortNames.mat'); + catch ME + stage.status = SerialPortSetUp(); + if stage.status == 1 + stage = stage_open_prior(label); + end + return + end + stage.scale=1; + stage.label=label; + stage.handle = serial(SerialPortStage,... + 'RequestToSend','off',... + 'Timeout',3,... + 'Baudrate',9600,... + 'Parity', 'none',... + 'Stopbits', 1,... + 'Flowcontrol','none',... + 'Terminator','CR'); + + % Test to see if the COM port is a legitimate COM port + try + fopen(stage.handle); + stage_send_com_prior (stage.handle, 'COMP 0'); + catch ME + + delete(stage.handle); + stage.handle = ''; + desc = textscan(ME.message,'%s','delimiter','\n'); + desc = desc{1}; + desc = desc(1,:) + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + + stage.status = SerialPortSetUp(); + if stage.status == 1 + stage = stage_open_prior(label); + end + return + end + + % Test to see if the COM port is attached to the stage + desc_status = stage_send_com_prior (stage.handle, '#'); + if strcmp(desc_status, '-1') + + delete(stage.handle); + stage.handle = ''; + desc = 'The selected COM port is not connected to the stage.' + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + + stage.status = SerialPortSetUp(); + if stage.status == 1 + stage = stage_open_prior(label); + end + return + end + + stage.status = 1; + +catch ME + error_show(ME) +end +end \ No newline at end of file diff --git a/stages/Prior/stage_send_com_prior.m b/stages/Prior/stage_send_com_prior.m new file mode 100644 index 00000000..ddc0a41c --- /dev/null +++ b/stages/Prior/stage_send_com_prior.m @@ -0,0 +1,57 @@ +% ########################################################################## +%% ########################## SEND COMMAND ################################## +% ########################################################################## +function ST_answer=stage_send_com_prior (S, CommandStr) + %-------------------------------------------------------------------------- + % This function sends commands to the stage. THe opened serial port S + % is passed as the first argument. The secong argument is the string of + % the command + %-------------------------------------------------------------------------- + try + + %Get the lenght of the command + for i=1:size(CommandStr,2) + fwrite(S,CommandStr(i)); + end + % send the termination char + fwrite(S,13); + + ST_answer=fgetl(S); + + + % These are the error messages that can come from the stage + if strcmp('E,1',ST_answer) + disp('NO STAGE'); + errordlg('NO STAGE!','Stage Error'); + ST_answer=-1; + end + if strcmp('E,2',ST_answer) + disp('Stage not idle'); + errordlg('Stage not idle!','Stage Error'); + ST_answer=-1; + end + if strcmp('E,3',ST_answer) + disp('No drive'); + errordlg('No drive for stage!','Stage Error'); + ST_answer=-1; + end + if strcmp('E,4',ST_answer) + disp('String Parse'); + errordlg('String Parse!','Stage Error'); + ST_answer=-1; + end + if strcmp('E,5',ST_answer) + disp('Command Not Found'); + ST_answer=-1; + end + if strcmp('E,8',ST_answer) + disp('Value out of range'); + errordlg('Value out of range!','Stage Error'); + ST_answer=-1; + end + catch + disp('Error in stage_send_com_prior (S, CommandStr)'); + errordlg('Unable to send a command to the stage!','Stage Error'); + ST_answer=-1; + end +end \ No newline at end of file diff --git a/stages/Prior/stage_set_origin_prior.m b/stages/Prior/stage_set_origin_prior.m new file mode 100644 index 00000000..5ad30faf --- /dev/null +++ b/stages/Prior/stage_set_origin_prior.m @@ -0,0 +1,66 @@ +% ########################################################################## +%% ################# MOVE STAGE SEQUENCE FOR PORIOR########################## +% ########################################################################## +function stage = stage_set_origin_prior(stage,h_stage) +try + + % If communications to stage is not open to start, then open. + % Also prepare to close + h_stage_close = 0; + if exist('h_stage', 'var') == 0 + h_stage_close = 1; + [stage] = stage_open_prior(stage.label); + % If communications with the stage cannot be established, + % eeDAP is closing. + if stage.status == 0 + desc = ['Communications with the stage is not established.',... + 'eeDAP is closing.'] %#ok + h_errordlg = errordlg(desc,'Application error','modal'); + uiwait(h_errordlg) + close all force; + return + end + end + + % Speed to the top-left corner + success = stage_send_com_prior(stage.handle, 'G -100000,-100000'); + % Wait til the stage gets to the top-left corner + while stage_check_busy_prior(stage.handle) + pause(.5) + end + % Set the top-left corner to be the origin + success = stage_send_com_prior(stage.handle, 'Z'); + success = stage_send_com_prior(stage.handle, 'G 50,50'); + success = stage_send_com_prior(stage.handle, 'G -50,-50'); + % For better precision, slow it down, move it away, and go back home + % success = stage_send_com_prior(stage.handle, 'G 25,25'); + while stage_check_busy_prior(stage.handle) + pause(.5) + end + + % Reset the top-left corner to be the origin + success = stage_send_com_prior (stage.handle, 'Z'); + + % If communications to stage was not open to start, then close. + if h_stage_close == 1 + stage.status=stage_close(stage.handle); + end + stage=stage_move_prior(stage,[5000,5000]); + +% ########################################################################## +%% ###################### MOVE STAGE SEQUENCE ############################### +% ########################################################################## +% success=send_com (S, 'SPEED X=50000 Y=50000'); +% success=send_com (S, 'SPEED X Y'); +% success=send_com (S, 'ACCEL X=100 Y=100'); +% success=send_com (S, 'ACCEL X Y'); +% command_str=char(strcat('move',' x=',num2str(Pos(1)),... +% ' y=',num2str(Pos(2)))); +% success=send_com (S, command_str); + +catch ME + error_show(ME); +end + +end +