Reading multiple signed digits from serial port
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm using simulink support package for arduino to read serial data from port2 in Arduino due. My plan is to read signed integers (-415 for example) representing motor speed and feed it to the pid controllers as in the image.
from the far end i'm sending delimited data in the following shape . The matlab function in sumlink is supposed to read the received ASCII characters and add them to a variable until it reaches the end character '>'. I'm using the following simple code just to give the output on both the Right and Left to check if I'm receiving the correct data, However I'm not.
function [Right ,Left] = fcn(data,status)
SON = '<';
EON = '>';
persistent receivedNumber;
receivedNumber = 0;
persistent negative;
negative = false;
if(status ==1)
switch(data)
case EON
if (negative)
receivedNumber = -1*receivedNumber;
else
receivedNumber = 1*receivedNumber;
end
case SON
receivedNumber = 0;
negative = false;
case {'0','1','2','3','4','5','6','7','8','9'}
receivedNumber = 10*receivedNumber;
receivedNumber = receivedNumber + double((data - 48));
case '-'
negative = true;
end
end
Right = receivedNumber;
Left = receivedNumber;
end
Can anybody tells if there are any other approaches to read multiple signed digits in simulink? Taking into consideration that I have to use the support package for Arduino since my pid controllers are already configured in Simulink and interfaced with port2 in Arduino (which will be connected to BeagleBone black)
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Run on Target Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!