clear all;
clc;
Desired_Pressure = 0.7;
[P, V, t] = SetPressure(Desired_Pressure);
disp(P);
disp(V);
disp(t);
RT030_SetCompressorVoltage(0);
figure(1)
plot(t,P)
figure(2)
plot(t,V)
function [P, V, t] = SetPressure(RefPressure)
% Machine characteristics
MIN_VOLT = 0; MAX_VOLT = 5;
TIME_ERROR = 0.016;
PRESSURE_ERROR = 0.01;
VOLTAGE_ERROR = 0.01;
MAX_TIME = 60;
P = []; V = []; t = [];
start_time = tic;
voltage = 0;
elapsed_time = 0;
while (elapsed_time < MAX_TIME)
elapsed_time = toc(start_time);
current_pressure = RT030_GetPressure();
P(end+1) = current_pressure;
V(end+1) = voltage;
t(end+1) = elapsed_time - TIME_ERROR;
if (abs(current_pressure - RefPressure) <= PRESSURE_ERROR)
if (abs(voltage - MAX_VOLT) <= VOLTAGE_ERROR)
disp("Pressure reached within error margin");
end
end
RT030_SetCompressorVoltage(voltage);
if (current_pressure < RefPressure - PRESSURE_ERROR)
if (voltage < 5)
voltage = min(MAX_VOLT, voltage + abs(RefPressure - current_pressure));
end
elseif (current_pressure > RefPressure + PRESSURE_ERROR)
if (voltage > 0)
voltage = max(MIN_VOLT, voltage - abs(RefPressure - current_pressure));
end
end
RT030_GetPressure()
pause(0.1);
end
RT030_SetCompressorVoltage(0);
end
Im trying develop the function [P,V,t]=SetPressure(RefPressure) that, in a fully automatic way, drives the chamber pressure to reach, in a steady-state condition, a value close to the one specified in the input argument RefPressure (expressed in bar). This function should properly adjust the voltage applied to the compressor so that the pressure, in a steady-state condition, reaches a value close to RefPressure. Throughout the execution of the function, the samples of the pressure measured in the chamber and the voltage applied to the compressor will be recorded, being stored in the vectors P and V, respectively, and the vector t (of the same size as P and V) will contain the instants of time at which these signal samples were taken.
Is there any way to optimize it, reaching the steady-state faster? Currently it goes up and down a couple times before stabilizing