Skip to content

Commit

Permalink
Updated IRC Communication Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian committed Apr 28, 2020
1 parent dcdf0a0 commit 57a6476
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
*.asv
*.asv
Data/RES101TrainedNET.mat
FSM.slx
FSM_grt_rtw/*
TCP_IP_Test.m
Test Packets/*
slprj/*
2 changes: 1 addition & 1 deletion Modules/Func_Send_Capture_Complete.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function Func_Send_Capture_Complete(tcpConn)
%FUNC_SEND_ROBOT_MSG Signals the robotics system that the image has been
%captured.

bits = [true logical(zeros(1,63))];
bits = [logical(zeros(1,63)) true];

% Convert bits to a uint8 (byte) array
msg = uint8(bi2de(reshape(bits,8,[])','left-msb'))';
Expand Down
2 changes: 1 addition & 1 deletion Modules/Func_Send_Section_Statuses.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Func_Send_Section_Statuses(tcpConn, sectionStatusRegister)

% Right-Pad the section status register to a length of 63, and left-pad
% with one zero (the camera done bit)
bits = [false, sectionStatusRegister, logical(zeros(1,63-length(sectionStatusRegister)))];
bits = [logical(zeros(1,63-length(sectionStatusRegister))), flip(sectionStatusRegister), false];

% Convert bits to a uint8 (byte) array
msg = uint8(bi2de(reshape(bits,8,[])','left-msb'))';
Expand Down
11 changes: 7 additions & 4 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

%% 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
Expand All @@ -34,9 +35,11 @@ function stepFSM(obj,event,fsm)
function msgRcv(obj,event,fsm)
% msgRcv: Event handler for receiving data from the robot

% 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);
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
36 changes: 17 additions & 19 deletions msgHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,32 @@ function msgHandler(msgData,fsm)
%MSGHANDLER Handles Robot-To-PC Messages
% Robot-To-PC Status Packet
% 0-Bit | 1-Bit | Name
% 1(LSB) Robot Ready Bit
% 2 Start Inspection Bit
% 3 Inspection Complete Bit
% 0-7 1-8 PoseID
% 8 9 Robot Ready Bit
% 9 10 Start Inspection Bit
% 10 11 Inspection Complete Bit

% Convert messaage bytes to bit array
msgBits = reshape(de2bi(uint8(msgData),'left-msb')',[],1)';

% Convert to bytes
msgByte = uint8(msgData(1));
% Convert message bytes to bit array
msgBits = logical(reshape(de2bi(uint8(flip(msgData)),'right-msb',8)',[],1)');

%% Trigger events based on the incoming message data

% Start Inspection Bit
if(msgBits(10))
fsm.ev_Req_Begin_Inspection();

% Inspection Complete Bit
elseif(msgBits(11))
fsm.ev_Req_Complete_Inspection();

% Robot Ready Bit (Capture Image)
if(bitand(uint8(1),msgByte,'uint8'))
elseif(msgBits(9))
% Pass the current PoseID to the FSM
fsm.curPoseID = bi2de(msgBits(3:10),'left-msb');
fsm.curPoseID = uint8(msgData(2));
fsm.ev_Req_Image_Capture();
end

% Inspection Complete Bit
if(bitand(uint8(4),msgByte))
fsm.ev_Req_Complete_Inspection();
end

% Start Inspection Bit
if(bitand(uint8(2),msgByte))
fsm.ev_Req_Begin_Inspection();
end



end
Expand Down

0 comments on commit 57a6476

Please sign in to comment.