Error occurs when creating Pole-Zero Map using pzmap()

10 次查看(过去 30 天)
% Define system parameters
m = 0.5; % kg
l = 1.5; % meters
b = 2; % Nms/rad
g = 9.8; % m/s^2
% Define symbolic variables
syms s tau theta
% Linearized equation of motion
eqn = m * l^2 * s^2 * theta + b * s * theta - m * g * l * theta == tau;
% Solve for transfer function H(s) = Theta(s) / Tau(s)
H = solve(eqn, theta/tau);
% Convert the symbolic transfer function to a function handle
H_function = matlabFunction(H);
Incorrect number or types of inputs or outputs for function matlabFunction.
% Plot poles of the transfer function
figure;
pzmap(H_function(s, 0), '-'); % '-' for inverted, '+' for upright
title('Pole-Zero Map');
legend('Inverted Configuration', 'Upright Configuration');

采纳的回答

Sam Chak
Sam Chak 2023-10-4
The input argument of the pzmap() function from the Control System Toolbox must be specified as a dynamic system model, which is constructed numerically. However, you are working in the symbolic realm, so you must convert the symbolic model to a numerical one.
% Define system parameters
m = 0.5; % kg
l = 1.5; % meters
b = 2; % Nms/rad
g = 9.8; % m/s^2
% Define symbolic variables
syms tau theta(t)
% Linearized equation of motion
eqn = (m*l^2)*diff(theta, 2) + b*diff(theta, 1) - m*g*l*theta == tau
eqn(t) = 
% Reduce ODE to equivalent system of first-order differential equations
[eqs, vars] = reduceDifferentialOrder(eqn, theta(t))
eqs = 
vars = 
[M, F] = massMatrixForm(eqs, vars);
f = M\F % x' = f(x), where state vector, x = [θ, \dot{θ}]
f = 
% Obtain the matrices of the state-space system (in continuous-time)
Ja = jacobian(f, vars); % still in symbolic form
A = double(Ja) % state matrix (convert symbolic Ja to numerical form)
A = 2×2
0 1.0000 6.5333 -1.7778
Jb = jacobian(f, tau);
B = double(Jb) % input matrix
B = 2×1
0 0.8889
C = [1 0]; % output matrix
D = 0; % feedforwand matrix
% Directly convert a state-space into a transfer function
% sys = ss(A, B, C, D)
% Gp = tf(sys)
Gp = tf(ss(A, B, C, D)) % one line only, you don't want to see the state-space
Gp = 0.8889 --------------------- s^2 + 1.778 s - 6.533 Continuous-time transfer function.
% Plot poles of the transfer function
figure;
pzmap(Gp, 'r'), grid on
  3 个评论
Muhammad Aboawah
Muhammad Aboawah 2023-10-4
% Define the desired poles for the upright configuration
desired_poles_upright = [-2 -3 -4]; % You can adjust these poles
% Design a PID controller using the desired poles
[Kp, Ki, Kd] = pidTuner(TF_upright, 'poles', desired_poles_upright);
Unrecognized function or variable 'TF_upright'.
% Create a PID controller object
pid_controller_upright = pid(Kp, Ki, Kd);
% Calculate the closed-loop transfer function
TF_closed_loop_upright = feedback(pid_controller_upright * TF_upright, 1);
% Compute the closed-loop step response
step_response_closed_loop_upright = step(TF_closed_loop_upright, t);
% Plot the closed-loop step response
figure;
plot(t, step_response_closed_loop_upright);
title('Closed Loop Step Response (Upright)');
xlabel('Time (s)');
ylabel('Theta(t)');
Sam Chak
Sam Chak 2023-10-4
You are welcome, @Muhammad Aboawah. If you find the solution helpful, please consider clicking 'Accept' ✔ on the answer to close the issue when the original problem involving pzmap() is resolved.
Additionally, the person who assisted you in writing the code for controller tuning using pidTuner() may be intentionally playing a prank on you.
I suggest that you post a new question, providing the plant transfer function (TF_upright), and specify the practical performance requirements, such as the desired settling time and maximum overshoot, if any. Nobody typically knows the desired poles outright; they often exist in textbooks solely for homework purposes when using the pole placement method.

请先登录,再进行评论。

更多回答(1 个)

Sam Chak
Sam Chak 2023-10-6
I wanted to bring to your attention that, based on the documentation, it appears that the pidTuner() function is unable to accept "desired pole locations" as input and returns "PID gains" as output. In order to achieve the placement of the closed-loop poles at the desired locations, it is necessary to utilize the place() command.
It's worth noting that the place(A, B, p) syntax requires the plant to be defined in state-space representation. Therefore, if one intends to apply the pole placement method to a given plant transfer function, it must first be converted into state-space form. This conversion will allow for the extraction of both the state matrix and the input matrix .
To illustrate this process, I have provided an example below that demonstrates how to design a PID controller when the desired pole locations are provided.
% Plant transfer function
Gp = tf(1, [1 3 3 1])
Gp = 1 --------------------- s^3 + 3 s^2 + 3 s + 1 Continuous-time transfer function.
% Define the desired poles for the upright configuration
p = [-2 -3 -4];
% Convert Plant TF to Canonical-Controllable SS
sys = ss(Gp);
sys = compreal(sys, 'c');
A = sys.A'; % state matrix
B = sys.C'; % input matrix
C = sys.B'; % output matrix
% Calculating the optimum gain matrix based on desired poles
K = place(A, B, p);
K = round(K, 4)
K = 1×3
23 23 6
% Desired Control System
Csys = ss(A - B*K, -prod(p)*B, C, 0*C*B);
% Control Design using Reverse Engineering
[num1, den1] = tfdata(Csys, 'v');
Gcp = tf(num1(end), [den1(1:3) 0]);
Gc = minreal(Gcp/Gp)
Gc = 24 s^3 + 72 s^2 + 72 s + 24 --------------------------- s^3 + 9 s^2 + 26 s Continuous-time transfer function.
zero(Gc); % 24*(s + 1)*(s + 1)*(s + 1)
pole(Gc); % s*(s^2 + 9*s + 26)
% Filter design
Gf = 24*tf([1 1], [1 9 26]) % 24*(s + 1)/(s^2 + 9*s + 26)
Gf = 24 s + 24 -------------- s^2 + 9 s + 26 Continuous-time transfer function.
% PID Controller
Gpid = minreal(Gc/Gf, 1e-4) % transfer function form
Gpid = s^2 + 2 s + 1 ------------- s Continuous-time transfer function.
[num2, den2] = tfdata(Gpid, 'v');
Kp = round(num2(2), 4);
Ki = round(num2(3), 4);
Kd = round(num2(1), 4);
Gpid = pid(Kp, Ki, Kd) % same as (s^2 + 2*s + 1)/s
Gpid = 1 Kp + Ki * --- + Kd * s s with Kp = 2, Ki = 1, Kd = 1 Continuous-time PID controller in parallel form.
% Closed-loop transfer function, with Gc = Gpid*Gf
Gcl = minreal(feedback(Gpid*Gf*Gp, 1), 1e-4)
Gcl = 24 ----------------------- s^3 + 9 s^2 + 26 s + 24 Continuous-time transfer function.
% Check if Gcl poles are placed at desired locations
pole(Gcl)
ans = 3×1
-4.0000 -3.0000 -2.0000
% Plot the closed-loop step response
step(Gcl, 10), grid on

类别

Help CenterFile Exchange 中查找有关 Stability Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by