Issues with while loop and answer plotting
2 次查看(过去 30 天)
显示 更早的评论
clc
clear all
instrreset
s = serial('COM4','BaudRate',9600,'Terminator','CR/LF')
[f, artificialhorizon, gyro, amb] = setupGraph(1);
fopen(s);
while true
str = fgetl(s);
num = textscan(str, '%f', 'Delimiter',',');
data2 = cell2mat(num)'
roll = data2(1);
pitch = data2(2);
Temp(1) = data2(3)
Temp(2) = data2(4)
artificialhorizon.Value = [roll pitch];
amb.Value = Temp(1);
gyro.Value = Temp(2);
end
fclose(s);
function [f, artificialhorizon, gyro, amb] = setupGraph(checkCondition)
if checkCondition == 1
%Setup matlab UIFIGURE
f = uifigure;
%Setup artificial horizon and its position within the uifigure
artificialhorizon = uiaerohorizon(f);
artificialhorizon.Position = [100 90 120 120];
%Setup ambient temperature gauge and its position within the uifigure
amb = uigauge(f);
amb.Limits = [0 60];
amb.MajorTicks = [0:10:60];
amb.MinorTicks = [];
amb.MajorTickLabels = {'0','10','20','30','40','50','60'};
amb.Position = [300 250 120 120];
%Setup gyro temperature gauge and its position within the uifigure
gyro = uigauge(f);
gyro.Limits = [0 60];
gyro.MajorTicks = [0:10:60];
gyro.MinorTicks = [];
gyro.MajorTickLabels = {'0','10','20','30','40','50','60'};
gyro.Position = [100 250 120 120];
amb.Value = 0;
gyro.Value = 0;
%Setup the text for gauges and its position within the uifigure
lbl = uilabel(f);
lbl.Text = "Ambient Temperature (Celcius)";
lbl.HorizontalAlignment = "center";
lbl.WordWrap = 'on';
lbl.Position = [300 175 120 120];
lbl2 = uilabel(f);
lbl2.Text = "Gyro Temperature (Celcius)";
lbl2.HorizontalAlignment = "center";
lbl2.WordWrap = 'on';
lbl2.Position = [100 175 120 120];
end
end
function condition = warning(temp, pitch, roll,f)
% Setup Panel for warning text
panel = uipanel(f);
panel.Position = [400 100 120 120];
condition = uilabel(f);
condition.WordWrap = 'on';
condition.Position = [400 100 120 120];
% If pitch > +-45, display warning
if abs(pitch) > 45
condition.Text = "Pitch Exceed Range!";
condition = 1;
% If roll > +-45, display warning
elseif abs(roll) > 45
condition.Text = "Roll Exceed Range!";
condition = 1;
% If temp more than 31 or less than 8, display warning
elseif temp(1) <= 8 || temp(1) >= 31 || temp(2) <= 8 || temp(2) >= 31
condition.Text = "Temperature Exceed Range!";
condition = 1;
% Normal operation
else
condition.Text = "Normal Condition";
condition = 0;
end
end
In this code I am reading the data through serial connection from arduino gyro and temperature sensors. I would like to display the data on a artificial horizon and temperature sensors. However the plots of the sensors dont open untill I pause the program. Where is my mistake?
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!