PID controller in matlab code
Mostra commenti meno recenti
I'm having trouble using a PID controller in a MATLAB script. I don't have the transfer function typically used with PID in MATLAB, but I do have the output error signal. I would like to connect this error signal to the PID code to improve the error correction.
For example, if I have this data (from the black system). I want to reduce the (maximum overshoot , rise time , settling time , ...) by using a PID controller .
clear all
clc
load("Vo_vn.mat")
load("x.mat")
Volt = Vo_vn;
Time = x;
OUTS = stepinfo(Volt,Time);
Desire = 23.5;
Error = Vo_vn-Desire;
RiseT = OUTS.RiseTime
SettT = OUTS.SettlingTime
OVERSH = (OUTS.Peak)-Desire
plot(Time,Volt)
4 Commenti
Sam Chak
circa un'ora fa
If you don't have the system transfer function in the traditional sense, where does the output error signal come from in the MATLAB script? The output signal must be generated from some system, either a transparent mathematical model or a data-driven black box. The PID controller, pid() function, itself does not require a transfer function to operate, unless you are referring to tuning the PID controller, which I understand you implied is intended to “improve the error correction.”
mohammed hussein
circa 17 ore fa
Modificato: mohammed hussein
circa 2 ore fa
You first need to estimate a transfer function that fits the step response data. This is a topic in system identification, and you can use the tfest() function to address this type of problem. Otherwise, you can also intelligently guess the coefficients if you are familiar with the underlying system.
clear all
clc
load("Vo_vn.mat")
load("x.mat")
Volt = Vo_vn;
Time = x;
OUTS = stepinfo(Volt,Time);
Desire = 23.5;
Error = Vo_vn-Desire;
RiseT = OUTS.RiseTime
SettT = OUTS.SettlingTime
OVERSH = (OUTS.Peak)-Desire
% Estimated model
s = tf('s');
w = 8e3; % natural frequency (guess)
K = w^2; % stiffness coeff
zet = 0.16; % damping ratio (guess)
D = 2*zet*w; % damping coeff
Gp = K/(s^2 + D*s + K); % 2nd-order transfer function
figure
step(Gp, Time(end)) % step response of model
hold on
plot(Time, Volt/Desire, 'r-') % normalized data
legend('estimated model', 'black box data')
hold off
ylim([0 1.6])
mohammed hussein
circa 5 ore fa
Risposte (1)
I revisited the problem, and you can perhaps use this as a mini guide. The manually estimated model is not 100% accurate, but it is relatively close. This model is then used by pidtune() to automatically tune the PID gains using a user-defined phase margin, an approach based on a concept you should already be familiar with in electrical engineering.
load("Vo_vn.mat")
load("x.mat")
Volt = Vo_vn;
Time = x;
OUTS = stepinfo(Volt,Time);
Desire = 23.5;
Error = Vo_vn-Desire;
RiseT = OUTS.RiseTime
SettT = OUTS.SettlingTime
OVERSH = (OUTS.Peak)-Desire
% Estimated model
s = tf('s');
w = 8725; % natural frequency (guess)
K = w^2; % stiffness coeff
zet = 0.158; % damping ratio (guess)
D = 2*zet*w; % damping coeff
Gp = K/(s^2 + D*s + K); % 2nd-order transfer function
figure
step(Desire*Gp, Time(end)) % step response of model
hold on
plot(Time, Volt, 'r-') % black box data
title('System Identification stage: Step Response')
legend('estimated model', 'black box data')
hold off
ylim([0 40])
% Auto-tuned PID Controller
opt = pidtuneOptions('PhaseMargin', 75, 'DesignFocus', 'reference-tracking');
Gc = pidtune(Gp, 'PIDF', opt)
% Closed-loop system
Gcl = minreal(feedback(Gc*Gp, 1))
% Plot results
figure
step(Desire*Gcl, 5e-3), grid on % simulated compensated system (not actual black box system)
hold on
plot(Time, Volt, 'r-') % black box data
title('Controller Design stage: Step Response')
legend('simulated compensated system', 'uncompensated black box output')
hold off
ylim([0 40])
Categorie
Scopri di più su Linear Model Identification in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



