Axis does not plot in app designer
Show older comments
I am making an application in app designer where I use two graphs to show the PWM of a digital controller, the UIAxes of the controller response works fine, but the PWM does not show the graph even when the axes are updated normally.
usada = app.PlacaDropDown.Value;
pcom = app.PuertoCOMEditField.Value;
elcom = strcat('COM', pcom);
app.a = arduino(elcom, usada);
app.parar = false;
app.file_path = uiputfile('*.csv', 'Guardar como');
i = 1;
H1 = 0;
H2 = 0;
selectedTab = app.TabGroup.SelectedTab;
titulo = selectedTab.Title;
switch titulo
case 'P'
K = app.K_P.Value;
t = app.T_P.Value;
q0 = K;
q1 = 0.0;
q2 = 0.0;
case 'PI'
K = app.K_PI.Value;
Ti = app.Ti_PI.Value;
t = app.T_PI.Value;
q0 = K * ( 1 + t/2*Ti );
q1 = -K * ( 1 - t/2*Ti );
q2 = 0.0;
case 'PID'
K = app.K_PID.Value;
Ti = app.Ti_PID.Value;
Td = app.Td_PID.Value;
t = app.T_PID.Value;
q0 = K * (1 + t/2*Ti + Td/t );
q1 = -K * (1 - t/2*Ti + 2*Td/t );
q2 = K*Td/t;
end
while ~app.parar
muestra(i) = i;
lectura1(i) = readVoltage(app.a,'A1')* 25;
lectura2(i) = readVoltage(app.a,'A2')* 25;
if lectura1 >= 40
writeDigitalPin(app.a, 'D7', 1);
else
writeDigitalPin(app.a, 'D7', 0);
end
if lectura2 >= 40
writeDigitalPin(app.a,'D8',1);
else
writeDigitalPin(app.a, 'D8', 0);
end
if app.Q1CheckBox.Value
%Actualizacion del vector de error (etapa 1).
app.e1(1) = app.e1(2);
app.e1(2) = app.e1(3);
app.e1(3) = app.tempRef.Value - lectura1(i);
%Actualizacion del vector de control (etapa 1).
app.u1(1) = app.u1(2);
app.u1(2) = ControlPID(app.u1, app.e1, q0, q1, q2);
H1 = app.u1(2) / 100; %Se mapea el PWM obtenico para enviarlo al arduino.
writePWMDutyCycle(app.a, 'D11', H1);
end
if app.Q2CheckBox.Value
%Actualizacion del vector de error (etapa 2).
app.e2(1) = app.e2(2);
app.e2(2) = app.e2(3);
app.e2(3) = app.tempRef.Value - lectura2(i);
%Actualizacion del vector de control (etapa 2).
app.u2(1) = app.u2(2);
app.u2(2) = ControlPID(app.u2, app.e2, q0, q1, q2);
H2 = app.u2(2) / 100; %Se mapea el PWM obtenico para enviarlo al arduino.
writePWMDutyCycle(app.a, 'D10', H2);
end
format bank;
app.matriz1(1, 1) = muestra(i);
app.matriz1(1, 2) = round(lectura1(i), 2);
app.matriz1(1, 3) = round(lectura2(i), 2);
app.matriz1(1, 4) = round(H1 * 100, 2);
app.matriz1(1, 5) = round(H2 * 100, 2);
writematrix(app.matriz1, app.file_path, 'WriteMode', 'append');
plot(app.grafica_pwm, muestra(i), H2 * 100, muestra(i), H1 * 100);
legend(app.grafica_pwm, 'H2', 'H1');
plot(app.grafica_temp, muestra, lectura2, muestra, lectura1);
legend(app.grafica_temp, 'Lectura2', 'Lectura1');
drawnow;
i = i + 1;
%set(app.inicioButton,'BackgroundColor',[0 0 0],'FontColor',[0.96 0.96 0.96],'Text','Sensando...');
pause(t);
end
function [act] = ControlPID(u, e, q0, q1, q2)
act = u(1) + q0*e(3) + q1*e(2) + q2*e(1);
if act >= 100
act = 100;
elseif act <= 0
act = 0;
end
end
I am grateful for any comments
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
