Permalink
Cannot retrieve contributors at this time
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?
Surface_Inspection_Integration/main.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45 lines (36 sloc)
1.27 KB
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
%% Setup Settings | |
% Load Modules | |
addpath('./Modules'); | |
% Integrated Robot Controller System Connection Configuration: | |
setup = struct(); | |
setup.IRC_IP_Address = 'localhost'; % IP Address of IRC | |
setup.IRC_IP_Port = 60451; % Connection Port on IRC | |
setup.IRC_Packet_Terminator = 'CR'; % Carriage Return | |
%% Load the Finite State Machine | |
fsm = StateFlowChart(); | |
%% Begin TCP Communication with the IRC | |
tcpConn = tcpip(setup.IRC_IP_Address,setup.IRC_IP_Port) | |
%tcpConn.ByteOrder = 'littleEndian'; | |
fsm.dataStore.tcpConn = tcpConn; | |
fsm.dataStore.tcpSetup = setup; | |
tcpConn.BytesAvailableFcn = {@msgRcv,fsm}; % Edit the callback function here | |
tcpConn.BytesAvailableFcnMode = 'terminator'; | |
tcpConn.Terminator = setup.IRC_Packet_Terminator; | |
fopen(tcpConn); | |
%% Use a timer to step the fsm | |
tmr = timer('ExecutionMode','fixedDelay'); | |
tmr.TimerFcn = {@stepFSM,fsm}; | |
tmr.start; | |
%% Callback Functions | |
function stepFSM(obj,event,fsm) | |
fsm.step; | |
end | |
function msgRcv(obj,event,fsm) | |
% msgRcv: Event handler for receiving data from the robot | |
if(obj.BytesAvailable > 0) | |
% Read data from the buffer | |
msgData = fread(obj,obj.BytesAvailable); | |
% Pass the relevant bytes along (last byte is message terminator) | |
msgHandler(msgData(1:end-1),fsm); | |
end | |
end |