- Given that the voltage is not a directly controlled input, I do no know how to get this value during a simulation.
How can I plot an internal value in a state space model?
2 次查看(过去 30 天)
显示 更早的评论
I have a DC Motor model with a voltage and a torque disturbance as inputs, similar to this example (represented in code differently). I want to make sure that under no circumstances do I pass a voltage greater than 12 volts. So, I would like to plot, or saturate, the voltage value within my model so I get a more realistic representation. Given that the voltage is not a directly controlled input, I do no know how to get this value during a simulation.
In other words, if the image below represent my system, I would like to plot u during a simulation.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167843/image.png)
Currently my code looks like this:
%%Define Constants
j_motor = 0.01; % kg.m^2
j_load = 10; % kg.m^2
b_motor = 0.1; % N.m.s
b_load = 0.001; % N.m.s
k = 0.01;
r = 1; % ohms
L = .005; % henrys
G1 = 12;
G2 = 36;
j_t = j_motor + j_load*(G1/G2)^2;
b_t = b_motor + b_load*(G1/G2)^2;
%%Create State Space Representation
A = [-b_t/j_t k/j_t; -k/L -r/L];
B = [0 1/j_t; 1/L 0];
C = [1 0];
dcm = ss(A, B, C, 0);
%%Design with feed forward gains
Kff = 1./dcgain(dcm);
Kff = diag([Kff(1,1) 1]);
dcmff = dcm*Kff;
dcmff.InputName = {'voltage' 'disturbance torque'};
dcmff.OutputName = 'speed';
time = 0:.01:15;
Td = 50 * transpose((time>5 & time<7));
w_ref = 10* transpose(ones(size(time)));
u = [w_ref, Td];
figure
lsim(dcmff, u, time)
grid
title('Feed Forward Gain');
legend('Speed');
%%Design via pole placement
p1 = -10 + 10i;
p2 = -10 - 10i;
K = place(A,B,[p1 p2]);
dcm_cl = ss(A-(B*K), B, C, 0);
K_gain_cl = 1./dcgain(dcm_cl);
K_gain_cl = diag([K_gain_cl(1,1) 1]);
dcm_cl = dcm_cl * K_gain_cl;
dcm_cl.InputName = {'omega_ref' 'disturbance torque'};
dcm_cl.OutputName = 'speed';
figure
lsim(dcm_cl, u, time)
title('Pole Placement Compensator');
legend('Speed');
0 个评论
回答(1 个)
M
2019-3-8
Is u the voltage ? In this case, yes it is a controlled input.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Electrical Block Libraries 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!