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!