Using the PID Tuner to read excel data

15 次查看(过去 30 天)
Brandon
Brandon 2025-9-3,21:43
编辑: Sam Chak 2025-9-4,10:17
I am trying to use the PID tuner for this excel sheet to automatically tune this values for less than 20% overshoot I am struggling to find a code to be able to read the imported values from this time series data to tune my controller. Is there anyone that can help provide a code that was used to read the values from this excel sheet for the PID tuner to use?

回答(1 个)

Sam Chak
Sam Chak 2025-9-4,6:08
编辑:Sam Chak 2025-9-4,10:17
The PID tuner can only tune single-input, single-output (SISO) linear time-invariant (LTI) dynamical system objects. In the continuous-time domain, LTI systems are described using ordinary differential equations (ODEs) with constant coefficients, but they are often expressed in the form of state-space representation (using matrices). In the frequency domain, SISO LTI systems are described as transfer functions after performing a Laplace transform on the ODEs.
However, the data in the attached .csv file is merely a sequence of measured currents over successive intervals of time. Can we generally derive a complete mathematical model from the raw measured output signal alone? The answer is no! Modeling dynamical systems using a data-driven approach requires knowledge of both input and output signals, as well as the system's structure and parameters.
Measured current signal:
T = readtable('Controlled Current test.csv', VariableNamingRule="preserve");
x = T{:,1};
y = T{:,2};
plot(x, y), grid on
ylim([0, 200])
title('Controlled Current test')
xlabel('Time (s)');
ylabel('Current (amp)');
If you have both input and output signals, you can use the ssest() command from the System Identification Toolbox to estimate a state-space model using time-domain or frequency-domain data.
Example:
% load input/output data
load sdata1 tt1
% estimated number of states
nx = 4;
% estimate a 4th-order state-space model
sys = ssest(tt1, nx, 'DisturbanceModel', 'none')
sys = Continuous-time identified state-space model: dx/dt = A x(t) + B u(t) + K e(t) y(t) = C x(t) + D u(t) + e(t) A = x1 x2 x3 x4 x1 -0.7457 -3.646 -0.2348 -0.748 x2 5.826 -2.426 -2.445 -2.131 x3 -0.5061 1.008 0.3814 -23.58 x4 -0.4342 0.9482 17.45 -1.883 B = u x1 0.2455 x2 -0.4267 x3 0.05298 x4 0.08337 C = x1 x2 x3 x4 y 65.83 31.99 1.339 -0.3672 D = u y 0 K = y x1 0 x2 0 x3 0 x4 0 Parameterization: FREE form (all coefficients in A, B, C free). Feedthrough: none Disturbance component: none Number of free coefficients: 24 Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using SSEST on time domain data "tt1". Fit to estimation data: 70.76% FPE: 1.749, MSE: 1.658
% compare the simulated model response with the measured output
compare(tt1, sys)
% plot zero initial condition response of the estimated system
figure
step(sys, 5), grid on
% PID controller design
opt = pidtuneOptions('PhaseMargin', 60, 'DesignFocus', 'reference-tracking');
[C, info] = pidtune(sys, 'PIDF', opt)
C = 1 s Kp + Ki * --- + Kd * -------- s Tf*s+1 with Kp = 0.266, Ki = 0.709, Kd = 0.0235, Tf = 0.00107 Continuous-time PIDF controller in parallel form.
info = struct with fields:
Stable: 1 CrossoverFrequency: 8.2095 PhaseMargin: 60.0000
% closed-loop system
Gcl = minreal(tf(feedback(C*sys, 1)))
Gcl = From input "u" to output: 56.82 s^5 + 4270 s^4 + 7.677e04 s^3 + 2.1e06 s^2 + 1.906e07 s + 4.793e07 -------------------------------------------------------------------------------- s^6 + 999.7 s^5 + 9096 s^4 + 4.933e05 s^3 + 3.362e06 s^2 + 2.795e07 s + 4.793e07 Continuous-time transfer function.
% plot the simulated response of compensated system (not the actual measured signal)
figure
step(Gcl, 5), grid on
stepinfo(Gcl)
ans = struct with fields:
RiseTime: 0.2046 TransientTime: 1.6445 SettlingTime: 1.6445 SettlingMin: 0.8467 SettlingMax: 1.0141 Overshoot: 1.4106 Undershoot: 0 Peak: 1.0141 PeakTime: 0.3981

类别

Help CenterFile Exchange 中查找有关 PID Controller Tuning 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by