Numeric answer for PID command

2 visualizaciones (últimos 30 días)
Mohsina Zafar
Mohsina Zafar el 3 de Jul. de 2019
Comentada: Jon el 8 de Jul. de 2019
I used a Simulink PD model and used values:
P=100; D=10; N=100
The input I am giving is
[0;0;0]-[0.05*(10-t);0.04*(10-t);0.03*(10-t)] where t=1:10
I get numeric values from the simulation.
I am trying to implement the same in script file but I get answer in transfer function format. I want the answer to be in numeric form like that from Simulink, Here is my MATLab code:
for t = 1:10
T_d = [0;0;0];
T_o = [0.05*(10-t);0.04*(10-t);0.03*(10-t)];
T_e = T_d-T_o;
C = pid(100,0,10,100)
T_u=T_e*C
end
Kindly help me in this regard.

Respuesta aceptada

Jon
Jon el 3 de Jul. de 2019
In order to simulate the time response of a system using the MATLAB control system toolbox you can use the lsim function. Note it is not valid to multiply a transfer function by a time domain signal as you have done in your code.
I made an example following what I think you were trying to accomplish below
% define time domain reference (setpoint), measured output, and error
% signals
% signals must have a row for each time value and a column for each channel
t = 0:10; % start at initial time equal to zero continue to 10
T_d = [0 0 0];
T_o = [0.05*(10-t);0.04*(10-t);0.03*(10-t)]'; % note transpose, columns of T_o are channels
T_e = T_d-T_o;
% define PID controller parameters
Kp = 100; % proportional gain
Ki = 0; % integral gain
Kd = 10; % derivative gain
Tf = 100; % filter time constant
c = pid(Kp,Ki,Kd,Tf); % individual pid controller
C = [c 0 0;0 c 0;0 0 c]; % identical pid controllers for each channel
% simulate response of pid controller to error signal
T_u = lsim(C,T_e,t);
  3 comentarios
Mohsina Zafar
Mohsina Zafar el 4 de Jul. de 2019
After this, I want to simulate a motor model but its output is not consistent with the input:
load('Motor_Param.mat')
a = sim('Motor_Control','SimulationMode','normal');
out = a.get('T_l')
Jon
Jon el 8 de Jul. de 2019
I'm glad that you are now able to use the pid function successfully. Regarding your question on the motor control simulation. I did try to replicate your problem, but I could not find the variable T_u in your .mat file, and it is needed for the simulation to run. In any case, I would suggest opening this as a new question, as it is a new topic.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by