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
%% 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