%% function DPI_check_calibration_N() % DPI_setup_N Jeff Pelz May 2007 %% USE_DEMO_BOARD = 0 verbose = 0; preview = 10; base_voltage = 1.0; % base voltage range (+/-) running = 1; % initialize voltage_log_scale = 1; % used to scale voltage output range. % range = +/-1V * 10^scale %% H_l = 1; % Horizontal left: A/D Ch0 -> Matlab index 1 H_r = 2; % Horizontal right: A/D Ch1 -> Matlab index 2 V_l = 3; % Vertical left: A/D Ch2 -> Matlab index 3 V_r = 4; % Vertical right: A/D Ch3 -> Matlab index 4 TnB_l = 5; % TrackNoBlink left: A/D Ch8 -> Matlab index 5 TnB_r = 6; % TrackNoBlink right: A/D Ch9 -> Matlab index 6 Aux_A = 7; % Aux A: A/D Ch10 -> Matlab index 7 Aux_B = 8; % Aux B: A/D Ch11 -> Matlab index 8 % I want to have the A/D run continuously until the program ends. I can % either put in a pushbutton object to stop(ai) or use a CloseRequestFcn % that executes before the figure closes. % Create a device object: Create the analog input object AI for an mcc box. % Add channels — Add ten hardware channels to AI. format_string = '%5.2f'; if ~USE_DEMO_BOARD try AI = analoginput('mcc',0); addchannel(AI,[0 1 2 3 8 9 10 11]); % Polls (and fills Matlab array) figure_name = 'DPI CALIBRATE:'; duration = inf; % N second acquisition set(AI,'SampleRate',1000); % 100 Hz ActualRate = get(AI,'SampleRate'); set(AI,'SamplesPerTrigger',duration*ActualRate); catch beep; pause(0.33); beep; pause(0.33); beep; display('WARNING: In DEMO-BOARD mode. '); AI = analoginput('mcc',1); % Note: make the demo board position 1 addchannel(AI,[0 1 2 3 4 5 6 7]); duration = inf; % N second acquisition set(AI,'SampleRate',10); % 100 Hz ActualRate = get(AI,'SampleRate'); set(AI,'SamplesPerTrigger',duration*ActualRate); % Sunce we're using demo-board data, recycle it for these channels too H_l = 1; % Horizontal left: A/D Ch0 -> Matlab index 1 H_r = 2; % Horizontal right: A/D Ch1 -> Matlab index 2 V_l = 3; % Vertical left: A/D Ch2 -> Matlab index 3 V_r = 4; % Vertical right: A/D Ch3 -> Matlab index 4 TnB_l = 5; % TrackNoBlink left: A/D Ch8 -> Matlab index 5 TnB_r = 6; % TrackNoBlink right: A/D Ch9 -> Matlab index 6 Aux_A = 7; % Aux A: A/D Ch10 -> Matlab index 7 Aux_B = 8; % Aux B: A/D Ch11 -> Matlab index 8 figure_name = '**** ERROR Opening A/D Board: Using DEMO-BOARD Mode *** Warning: The ID value selected is associated with Measurement Computing''s virtual DEMO_BOARD'; end else beep; pause(0.33); beep; pause(0.33); beep; display('WARNING: In DEMO-BOARD mode. '); AI = analoginput('mcc',1); % Note: make the demo board position 1 addchannel(AI,[0 1 2 3 4 5 6 7]); duration = inf; % N second acquisition set(AI,'SampleRate',10); % 100 Hz ActualRate = get(AI,'SampleRate'); set(AI,'SamplesPerTrigger',duration*ActualRate); % Sunce we're using demo-board data, recycle it for these channels too H_l = 1; % Horizontal left: A/D Ch0 -> Matlab index 1 H_r = 2; % Horizontal right: A/D Ch1 -> Matlab index 2 V_l = 3; % Vertical left: A/D Ch2 -> Matlab index 3 V_r = 4; % Vertical right: A/D Ch3 -> Matlab index 4 TnB_l = 5; % TrackNoBlink left: A/D Ch8 -> Matlab index 5 TnB_r = 6; % TrackNoBlink right: A/D Ch9 -> Matlab index 6 Aux_A = 7; % Aux A: A/D Ch10 -> Matlab index 7 Aux_B = 8; % Aux B: A/D Ch11 -> Matlab index 8 figure_name = '************** Warning: The ID value selected is associated with Measurement Computing''s virtual DEMO_BOARD ******* DPI SETUP: 16-Channel'; end Analog_Obj = AI; % global variable for callback % Configure property values — I want to collect data indefinately, until Quit % Define infinite acquisition, set up the plot, and store the plot handle % in the variable P. The amount of data to display is given % by preview. % set limits on plot windows. MinYval = -base_voltage * 10^voltage_log_scale; MaxYval = +base_voltage * 10^voltage_log_scale; % Open figure; make it almost full screen % figure('Position', [left bottom width height]) % scrsz = get(0,'ScreenSize'); scrsz = [1 1 1024 768]; % so that it will always be the right size for the small display figure('MenuBar','none', ... 'Name',figure_name, 'NumberTitle','off') set(1,'Position', [scrsz(1)+5 scrsz(2)+40 scrsz(3)-10 scrsz(4)-70]); % figure('Position', [scrsz(1)+5 scrsz(2)+40 scrsz(3)-10 scrsz(4)-120]); uicontrol('Style', 'pushbutton', ... % Quit_button_h = 'String', 'Quit',... 'FontSize', 24, ... 'Position', [2 650 100 50], 'Callback', @quit_callback); uipanel('Title','H_left (0)', ... 'FontSize',12,'FontWeight', 'Normal', ... 'BackgroundColor', [0.8 0.8 0.8],... 'Position',[0.14 0.93 0.11 0.075]); uipanel('Title','V_left (2)', ... 'FontSize',12,'FontWeight', 'Normal', ... 'BackgroundColor', [0.8 0.8 0.8],... 'Position',[0.28 0.93 0.11 0.075]); uipanel('Title','H_right (1)', ... 'FontSize',12,'FontWeight', 'Normal', ... 'BackgroundColor', [0.8 0.8 0.8],... 'Position',[0.60 0.93 0.11 0.075]); uipanel('Title','V_right (3)', ... 'FontSize',12,'FontWeight', 'Normal', ... 'BackgroundColor', [0.8 0.8 0.8],... 'Position',[0.74 0.93 0.11 0.075]); H_left_label_h = uicontrol('Style','text',... 'String','Volts',... 'BackgroundColor', [0.8 0.8 0.8],... 'FontSize', 22, 'FontWeight', 'Bold', 'FontName', 'FixedWidth', ... 'Position',[150 652 100 32]); V_left_label_h = uicontrol('Style','text',... 'String','Volts',... 'BackgroundColor', [0.8 0.8 0.8],... 'FontSize', 22, 'FontWeight', 'Bold', 'FontName', 'FixedWidth', ... 'Position',[295 652 100 32]); H_right_label_h = uicontrol('Style','text',... 'String','Volts',... 'BackgroundColor', [0.8 0.8 0.8],... 'FontSize', 22, 'FontWeight', 'Bold', 'FontName', 'FixedWidth', ... 'Position',[620 652 100 32]); V_right_label_h = uicontrol('Style','text',... 'String','Volts',... 'BackgroundColor', [0.8 0.8 0.8],... 'FontSize', 22, 'FontWeight', 'Bold', 'FontName', 'FixedWidth', ... 'Position',[760 652 100 32]); uipanel('Title','', ... 'FontSize',12,'FontWeight', 'Normal', ... 'BackgroundColor', [0.8 0.8 0.8],... 'Position',[0.14 0.005 0.33 0.05]); Volt8_label_h = uicontrol('Style','text',... 'String','Voltage',... 'BackGroundColor', [0.8 0.8 0.8], ... 'FontSize', 16, 'FontWeight', 'Bold', 'FontName', 'FixedWidth', ... 'Position',[375 10 95 24]); uipanel('Title','', ... 'FontSize',12,'FontWeight', 'Normal', ... 'BackgroundColor', [0.8 0.8 0.8],... 'Position',[0.545 0.005 0.335 0.05]); Volt9_label_h = uicontrol('Style','text',... 'String','Voltage',... 'BackGroundColor', [0.8 0.8 0.8], ... 'FontSize', 16, 'FontWeight', 'Bold', 'FontName', 'FixedWidth', ... 'Position',[800 10 90 24]); uicontrol('Style','text',... % TrNBl_l_voltage_label_h = 'String','Left: TrackNoBlink (Ch8)', ... 'FontSize', 16, ... 'BackGroundColor', [0.8 0.8 0.8], ... 'Position',[145 12 250 25]); uicontrol('Style','text',... % TrNBl_r_voltage_label_h = 'String','Right: TrackNoBlink (Ch9)', ... 'FontSize', 16, ... 'BackGroundColor', [0.8 0.8 0.8], ... 'Position',[555 12 250 25]); % Acquire data — % Start AI and update the display using peekdata every % time an amount of data specified by preview is stored in % the engine by polling SamplesAcquired. % The drawnow command forces MATLAB to update the plot. After % all data is acquired, it is extracted from the engine. Note that whenever peekdata is used, all acquired data might not be % displayed. % set(gcf,'doublebuffer','on') plot(100,100,'b<') hold on plot(100,100,'r>') axis ([MinYval MaxYval MinYval MaxYval]) % title('Plot title', 'FontSize', 16) set(gca, 'color', [0.85 0.85 0.85]); % darken the axes background ylabel('Signal Level (Volts)') start(AI) while AI.SamplesAcquired < preview end while (running && (AI.SamplesAcquired < duration*ActualRate)) % grab the preview data data = peekdata(AI,preview); % clip to min and max so that all data will be seen on plot preview_H_l = min(max(data(:,H_l),MinYval),MaxYval); preview_H_r = min(max(data(:,H_r),MinYval),MaxYval); preview_V_l = min(max(data(:,V_l),MinYval),MaxYval); preview_V_r = min(max(data(:,V_r),MinYval),MaxYval); preview_TnB_l = min(max(data(:,TnB_l), MinYval),MaxYval); preview_TnB_r = min(max(data(:,TnB_r),MinYval),MaxYval); preview_Aux_A = min(max(data(:,Aux_A),MinYval),MaxYval); preview_Aux_B = min(max(data(:,Aux_B),MinYval),MaxYval); % It will be more efficient to calculate the means once, and check the % absolute values once if we put it in an array: previewCh = [preview_H_l preview_H_r preview_V_l preview_V_r preview_TnB_l preview_TnB_r preview_Aux_A preview_Aux_B]; previewMeans = mean(previewCh); % update data set(Volt8_label_h, 'String', sprintf('%5.2f', previewMeans(:,TnB_l))); set(Volt9_label_h, 'String', sprintf('%5.2f', previewMeans(:,TnB_r))); set(H_left_label_h, 'String', sprintf(format_string, previewMeans(:,H_l))); set(H_right_label_h, 'String', sprintf(format_string, previewMeans(:,H_r))); set(V_left_label_h, 'String', sprintf(format_string, previewMeans(:,V_l))); set(V_right_label_h, 'String', sprintf(format_string, previewMeans(:,V_r))); text(previewMeans(:,H_l),previewMeans(:,V_l), '<', 'Color', 'b', ... 'fontsize', 22, 'fontname', 'fixedwidth', 'fontweight', 'normal'); text(previewMeans(:,H_r),previewMeans(:,V_r), '>', 'Color', 'r', ... 'fontsize', 22, 'fontname', 'fixedwidth', 'fontweight', 'normal'); drawnow % update plot text(previewMeans(:,H_l),previewMeans(:,V_l), '<', 'Color', [0.85 0.85 0.85], ... 'fontsize', 22, 'fontname', 'fixedwidth', 'fontweight', 'normal'); % so that it's erased next time text(previewMeans(:,H_r),previewMeans(:,V_r), '>', 'Color', [0.85 0.85 0.85], ... 'fontsize', 22, 'fontname', 'fixedwidth', 'fontweight', 'normal'); % so that it's erased next time legend('Left', 'Right'); end % Clean up — display('Cleaning up'); delete(AI) clear AI close all %% %% function quit_callback(varargin) % global Analog_Obj; %This is nested, so it doesn't have to be % declared here. % This should get called when you push the pushbutton. This routine will % stop the AI object and close the window. display('Flushing data and stopping analog object'); flushdata(Analog_Obj); % clear the engine; stop(Analog_Obj) running = 0; % clear flag so that it drops out of data collection loop close all end % quit_callback end