Issues with while loop and answer plotting

2 visualizaciones (últimos 30 días)
czakar
czakar el 14 de Mzo. de 2022
Comentada: Voss el 14 de Mzo. de 2022
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?

Respuesta aceptada

Voss
Voss el 14 de Mzo. de 2022
Editada: Voss el 14 de Mzo. de 2022
Try putting a drawnow() in your code after the plots are created/updated in order to refresh the graphics.
  2 comentarios
czakar
czakar el 14 de Mzo. de 2022
It worked, thank you.
Voss
Voss el 14 de Mzo. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by