Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
classdef AutoOpticalInspection < handle
%AOI Automated Optical Inspection
properties
% Logger Instance
log
% Finite State Machine
fsm
% Timer to handle stepping the FSM
tmr
% Modules
mod_im_proc
mod_im_acq
mod_proc_ctrl
mod_gui
% GUI Binding
app_gui
gui_enabled = 1
end
methods
function self = AutoOpticalInspection()
%AOI Construct an instance of this class
% Add the modules path
addpath('./Modules');
% Set up logging
import logging.logging.*;
logPath = './Logs';
logName = [datestr(datetime('now'),'yyyy_mm_dd__HH_MM_SS') '.log'];
self.log = logging.getLogger('AOI_Logger','path',[logPath '/' logName]);
% Set up Finite State Machine
self.fsm = StateFlowChart();
self.fsm.log = self.log;
% === Instantiate Modules ===
% Image Processing
self.mod_im_proc = Mod_ImageProcessor(self.log);
% Image Acquisition
self.mod_im_acq = Mod_ImageAcquisition(self.log);
% Process Control Master with Event Trigger Methods
methodSignatures = struct();
methodSignatures.method_begin_inspection = @self.ev_Req_Begin_Inspection;
methodSignatures.method_complete_inspection = @self.ev_Req_Complete_Inspection;
methodSignatures.method_capture_image = @self.ev_Req_Image_Capture;
methodSignatures.method_setState_CurrentPose = @self.setState_CurrentPose;
self.mod_proc_ctrl = Mod_ProcessControl(self.log,methodSignatures);
% Provide the FSM with method handles for relavant tasks from
% modules
self.fsm.functions.Send_Section_Statuses = @self.func_send_section_statuses;
self.fsm.functions.Send_Capture_Complete = @self.func_send_capture_complete;
self.fsm.functions.Capture_Image = @self.func_captureImage;
self.fsm.functions.Process_Images = @self.func_processImages;
self.fsm.functions.Update_GUI = @self.update_GUI;
% === Set up timer to Execute FSM ===
self.tmr = timer('ExecutionMode','fixedSpacing');
self.tmr.TimerFcn = {@self.stepFSM_Callback};
% == Initialize GUI ==
if(self.gui_enabled)
self.mod_gui = gui();
end
% === Begin the Process ===
self.mod_proc_ctrl.connect();
self.tmr.start;
end
function self = setState_CurrentPose(self, curPoseData)
%SETSTATE_CURRENTPOSE Passes current pose information to FSM
% CurPoseID should be a member of the curPoseData struct, it is
% pulled out and specified to the FSM, as it is a required
% value for image acquisition.
% Generic Data Container for Current Pose Information
self.fsm.curPoseData = curPoseData;
% Set the current PoseID for the FSM
self.fsm.curPoseID = curPoseData.PoseID;
end
function self = stepFSM_Callback(self,obj,event)
%self.update_GUI();
self.fsm.step;
%self.update_GUI();
end
function self = update_GUI(self)
if(self.gui_enabled)
try
updateGUI(self.mod_gui, self.fsm);
catch exc
disp(exc);
disp(exc.stack);
end
end
end
function self = dispose(self)
self.log.info('AutoOpticalInspection shutting down.');
% Stop and Delete Timer
stop(self.tmr);
delete(self.tmr);
% Close Connection to the Process Controller
self.mod_proc_ctrl.dispose();
% Close Connection to the Camera
self.mod_im_acq.dispose();
% Delete GUI
if(self.gui_enabled)
self.mod_gui.delete;
end
% Delete Instances of Modules
delete(self.mod_proc_ctrl);
delete(self.mod_im_acq);
delete(self.mod_im_proc);
% Delete FSM
delete(self.fsm);
end
end
% Module Functions to be called from FSM
methods
function func_send_section_statuses(self, statusData)
self.mod_proc_ctrl.send_section_statuses(statusData);
end
function func_send_capture_complete(self)
self.mod_proc_ctrl.send_capture_complete();
end
function img = func_captureImage(self,curPoseData)
img = self.mod_im_acq.captureImage(curPoseData);
end
function [statusData filepath] = func_processImages(self,imageContainer)
[statusData filepath] = self.mod_im_proc.processImages(imageContainer);
end
end
% Event Trigger Methods
methods
function self = ev_Req_Begin_Inspection(self)
self.fsm.ev_Req_Begin_Inspection();
end
function self = ev_Req_Complete_Inspection(self)
self.fsm.inspection_ready = true;
end
function self = ev_Req_Image_Capture(self)
self.fsm.capture_ready = true;
end
end
end