Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #1 from dscl/development
Development
- Loading branch information
Showing
22 changed files
with
1,122 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.asv | ||
*.log | ||
Data/RES101TrainedNET.mat | ||
FSM.slx | ||
FSM_grt_rtw/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
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 | ||
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(); | ||
|
||
|
||
% === 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; | ||
|
||
% === Set up timer to Execute FSM === | ||
self.tmr = timer('ExecutionMode','fixedSpacing'); | ||
self.tmr.TimerFcn = {@self.stepFSM_Callback}; | ||
|
||
% === 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.fsm.step; | ||
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 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 = func_processImages(self,imageContainer) | ||
statusData = 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function clearLogger(name) | ||
[~, destructor] = logging.getLogger(name); | ||
destructor(); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function [obj, deleteLogger] = getLogger(name, varargin) | ||
persistent loggers; | ||
logger_found = false; | ||
if ~isempty(loggers) | ||
for logger = loggers | ||
if strcmp(logger.name, name) | ||
obj = logger; | ||
logger_found = true; | ||
break; | ||
end | ||
end | ||
end | ||
if ~logger_found | ||
obj = logging.logging(name, varargin{:}); | ||
loggers = [loggers, obj]; | ||
end | ||
|
||
deleteLogger = @() deleteLogInstance(); | ||
|
||
function deleteLogInstance() | ||
if ~logger_found | ||
error(['logger for file [ ' name ' ] not found']) | ||
end | ||
loggers = loggers(loggers ~= obj); | ||
delete(obj); | ||
clear('obj'); | ||
end | ||
end |
Oops, something went wrong.