how to make input to the system time variable?
조회 수: 16 (최근 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!
