fig = uifigure('Name','test_manuel',"Position",[100 100 800 800]);
graphical_window = uigridlayout(fig);
fig.CloseRequestFcn = @(src,event)my_closereq(src);
cmd_edf = uislider(graphical_window);
cmd_edf.Limits = [80 260];
cmd_edf.Layout.Column = [4];
cmd_moteur =uislider(graphical_window);
cmd_moteur.Limits = [0 6500];
cmd_moteur.Layout.Row = 5;
cmd_moteur.Layout.Column = [4];
cmd_moteur.UserData="fdsf";
cmd_registre=uislider(graphical_window);
cmd_registre.Limits = [0 10];
cmd_registre.Layout.Row = 3;
cmd_registre.Layout.Column = [4];
cmd_registre.UserData="fdsf";
grapheQ = uiaxes(graphical_window);
grapheQ.Layout.Row = [1 3];
grapheQ.Layout.Column = [1 3];
grapheQ.Title.String=("débit en fonction du temps");
grapheQ.YLabel.String = 'Débit en m3/h';
grapheQ.XLabel.String = 'nb échantillons';
grapheP = uiaxes(graphical_window);
grapheP.Layout.Row = [4 6];
grapheP.Layout.Column = [1 3];
grapheP.Title.String=("Pression en fonction du temps");
grapheP.YLabel.String = 'Pression en Pa';
grapheP.XLabel.String = 'nb échantillons';
graphe_EDF = uiaxes(graphical_window);
graphe_EDF.Layout.Row = 2;
graphe_EDF.Layout.Column = 4;
graphe_EDF.Title.String=("Tension EDF");
graphe_EDF.YLabel.String = 'Tension en Vac';
graphe_EDF.XLabel.String = 'nb échantillons';
graphe_cmd = uiaxes(graphical_window);
graphe_cmd.Layout.Row = 6;
graphe_cmd.Layout.Column = 4;
graphe_cmd.Title.String=("commande moteur mV");
graphe_cmd.YLabel.String = 'cmd mV';
graphe_cmd.XLabel.String = 'nb échantillons';
graphe_rpm = uiaxes(graphical_window);
graphe_rpm.Layout.Row = 7;
graphe_rpm.Layout.Column = 4;
graphe_rpm.Title.String=("RPM moteur");
graphe_rpm.YLabel.String = 'RPM';
graphe_rpm.XLabel.String = 'nb échantillons';
graphe_registre = uiaxes(graphical_window);
graphe_registre.Layout.Row = 4;
graphe_registre.Layout.Column = 4;
graphe_registre.Title.String=("position registre");
graphe_registre.YLabel.String = 'position';
graphe_registre.XLabel.String = 'nb échantillons';
graphe_registre2 = uiaxes(graphical_window);
graphe_registre2.Layout.Row = 7;
graphe_registre2.Layout.Column = [1 3];
graphe_registre2.Title.String=("position registre");
graphe_registre2.YLabel.String = 'position';
graphe_registre2.XLabel.String = 'nb échantillons';
disp("initialistion device_daq")
device_daq.Rate = 1/(1/rate-time_offset);
newPressureDevice = serialport("COM8", 9600);
read_pressure = addinput(device_daq,"Dev1","ai8","Voltage");
read_pressure.TerminalConfig = "SingleEnded";
read_flow_rate = addinput(device_daq,"Dev1","ai1","Voltage");
read_flow_rate.TerminalConfig = "SingleEnded";
read_valva_position = addinput(device_daq,"Dev1","ai3","Voltage");
read_valva_position.TerminalConfig = "SingleEnded";
write_motor_signal = addoutput(device_daq,"Dev1","ao1","Voltage");
write_motor_signal.Range = [-10 10];
disp("initialistion modbus")
moteur_modbus = modbus("serialrtu","COM5");
cmd_autotransfo=serialport("COM7",9600);
position_autotransfo = 260;
position_autotransfo_str=int2str(position_autotransfo);
write(cmd_autotransfo, position_autotransfo_str, "uint8");
configureTerminator(cmd_autotransfo,"CR/LF")
disp("autotransfo arduino connecté")
visausb = visadev("USB0::0x0957::0x0607::MY47011181::0::INSTR");
visausb.write("CONF:VOLT:AC")
visausb.write("CONF:VOLT:AC BAND 20")
tension_entree=visausb.writeread("READ?");
comserie_temp=serialport("COM3",9600);
configureTerminator(comserie_temp,"CR/LF");
var_temp=visausb.writeread("READ?");
var_temp=str2double (var_temp);
EDF_mes=[EDF_mes;var_temp];
EDF_cmd=[EDF_cmd ;cmd_edf.Value];
temperature_mat=[temperature_mat ; var_temp];
inScanData = read(device_daq);
pressure = table2array(inScanData(:,1));
pressure_convert=(pressure*20);
P_mes=[P_mes;pressure_convert];
flow_rate = table2array(inScanData(:,2));
flow_rate_convert=(flow_rate*63.375)-126.75;
Q_mes=[Q_mes;flow_rate_convert];
var_temp=table2array(inScanData(:,3));
reg_mes=[reg_mes;var_temp];
new_pressure = readline(newPressureDevice);
new_num = str2double(new_pressure);
P_mes_new=[P_mes_new;new_pressure];
webb = webread("https://www.allosurf.net/meteo/live/toulouse-blagnac-station-meteo-lfbo-5386.html");
k = strfind(webb, 'hPa');
releve = webb(k(1)-5: k(1)-2);
modbus_data = read(moteur_modbus,"holdingregs",17,7);
U_DC=[U_DC; modbus_data(4)* 0.1];
I_DC=[I_DC; modbus_data(5)* 0.1];
Pow_DC=[Pow_DC; modbus_data(6)* 0.1];
I_15V=[I_15V; modbus_data(7)* 0.1];
cmd=[cmd; modbus_data(2)];
RPM_mes=[RPM_mes; modbus_data(3)];
D_I=[D_I;I_DC(end)-I_DC(end-1)];
D_O=[D_O;RPM_mes(end)-RPM_mes(end-1)];
q_estime=flow_hyp_1deg8(RPM_mes(end),U_DC(end),I_DC(end))
p_estime=pressure_hyp_1deg8(RPM_mes(end),U_DC(end),I_DC(end))
q_estime=flow_hyp_2deg7(RPM_mes(end),U_DC(end),I_DC(end),D_I(end))
p_estime=pressure_hyp_2deg7(RPM_mes(end),U_DC(end),I_DC(end),D_I(end))
q_estime=flow_hyp_3deg6(RPM_mes(end),U_DC(end),I_DC(end),D_O(end))
p_estime=pressure_hyp_3deg6(RPM_mes(end),U_DC(end),I_DC(end),D_O(end))
q_estime=flow_hyp_4deg7(RPM_mes(end),U_DC(end),I_DC(end),D_I(end),D_O(end))
p_estime=pressure_hyp_4deg7(RPM_mes(end),U_DC(end),I_DC(end),D_I(end),D_O(end))
reg_cmd=[reg_cmd;cmd_registre.Value];
write(device_daq,cmd_registre.Value);
var_temp=double(round(cmd_moteur.Value));
write(moteur_modbus,'holdingregs',2,i);
plot(graphe_cmd,sample,cmd,'--b')
lgd_cmd=legend(graphe_cmd, 'cmd moteur (mV)', 'Location','northwest') ;
lgd_cmd.FontSize = Fontsize;
plot(graphe_EDF,sample,EDF_cmd,'--b',sample,EDF_mes,'.r');
lgd_EDF=legend(graphe_EDF, 'EDF_cmd','EDF_mes', 'Location','northwest') ;
lgd_EDF.FontSize= Fontsize;
plot(graphe_registre,sample,reg_cmd,'--b',sample,reg_mes,'.r');
lgd_registre=legend(graphe_registre, 'reg_cmd','reg_mes', 'Location','northwest');
lgd_registre.FontSize= Fontsize;
plot(graphe_registre2,sample,reg_cmd,'--b',sample,reg_mes,'.r');
lgd_registre2=legend(graphe_registre, 'reg_cmd','reg_mes', 'Location','northwest');
lgd_registre2.FontSize=Fontsize;
plot(graphe_rpm,sample,RPM_mes,'--b');
lgd_rpm=legend(graphe_rpm, 'RPM_mes', 'Location','northwest');
lgd_rpm.FontSize=Fontsize;
plot(grapheP,sample,P_est,'--b',sample,P_mes,'.r', sample, P_mes_new);
lgd_P=legend(grapheP, 'P_est','P_mes','P_mes_new', 'Location','northwest');
plot(grapheQ,sample,Q_est,'--b',sample,Q_mes,'.r');
lgd_Q=legend(grapheQ, 'Q_est','Q_mes', 'Location','northwest');
save_matrix=[EDF_mes,EDF_cmd,temperature_mat,P_atm,P_mes,P_est,Q_mes,Q_est,reg_mes,reg_cmd,U_DC,I_DC,Pow_DC,I_15V,cmd,RPM_mes,D_I,D_O,sample,temps];
consigne_edf=cmd_edf.Value;
erreur = sortie-consigne_edf;
consigne_position=consigne_position+Kp*erreur;
consigne_position=round(consigne_position);
position_autotransfo_str=int2str(consigne_position);
disp(position_autotransfo_str)
write(cmd_autotransfo, position_autotransfo_str, "uint8");
currentDateTime = datestr(now, 'mm-dd-yyyy_HH-MM');
fileName = strcat('Repetabilite_var_position_', currentDateTime, '.csv');
writematrix (save_matrix,fileName,"Delimiter",';')
write(moteur_modbus,'holdingregs',2,0);
function my_closereq(fig)
selection = uiconfirm(fig,'Close the figurewindow?',...