how to make input to the system time variable?
5 次查看(过去 30 天)
显示 更早的评论
I would like to make an input that is time varying.
I have attached a photo that describe the time varying input I want.
Im a beginner. I hope someone can help me with this. Thank you
Im open to all suggestions or references that can help me learn.
采纳的回答
Sam Chak
2023-10-31
编辑:Sam Chak
2023-10-31

Okay @Min Khant, the problem is incomplete. However, you can learn by yourself using this example for tracking the desired trajectory
. Change the tau number as you wish to observe the time response of
.
tspan = linspace(0, 20, 3001); % can set tspan from 0 to π
y0 = [0; 0]; % initial values
[t, y] = ode45(@odefcn, tspan, y0);
yd = pi/2 - pi/4*cos(t); % desired trajectory
% Plots
plot(t, yd), hold on
plot(t, y(:,1)), grid on
title('Time response of \theta(t) in tracking \theta_{d}', 'fontsize', 10)
xlabel('t', 'fontsize', 10), ylabel('\theta', 'fontsize', 10)
legend('\theta_{d}', '\theta(t)', 'location', 'best', 'fontsize', 10)
% Simplified Robt dynamics
function dydt = odefcn(t, y)
dydt = zeros(2, 1);
% parameters
M = 1;
b = 1;
m = 1;
g = 1;
r = 0.16; % true value
rmeas = 0.08; % measured
kp = 1;
kd = 2;
% desired trajectory
yd = pi/2 - pi/4*cos(t);
dyd = 1/4*pi*sin(t);
ddyd = 1/4*pi*cos(t);
% tau input (3 variants)
tau1 = M*ddyd + b*dyd + m*g*rmeas*cos(yd); % so-called feedforward control
tau2 = M*ddyd + M*kd*dyd + M*kp*yd - M*kd*y(2) - M*kp*y(1) + b*y(2) + m*g*r*cos(y(1)); % perfect r
tau3 = M*ddyd + M*kd*dyd + M*kp*yd - M*kd*y(2) - M*kp*y(1) + b*y(2) + m*g*rmeas*cos(y(1)); % imperfect r
dydt(1) = y(2);
dydt(2) = (- b*y(2) - m*g*r*cos(y(1)) + tau3)/M; % <-- change the tau number
end
4 个评论
Sam Chak
2023-10-31
Hi @Min Khant
Good to hear that you like Simulink. This following approach is generally more accurate than applying the differentiation block twice to get
. If you find the solution helpful, please consider clicking 'Accept' ✔ on the answer and voting 👍 for it.

更多回答(1 个)
Aquatris
2023-10-31
You can create your own numeric integration to solve the equation and provide the desired input in each time step.
Here is an example (the accepted answer) which you can modify for your need.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discontinuities 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
