how to make input to the system time variable?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Min Khant
am 31 Okt. 2023
Kommentiert: Min Khant
am 3 Nov. 2023
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.
Akzeptierte Antwort
Sam Chak
am 31 Okt. 2023
Bearbeitet: Sam Chak
am 31 Okt. 2023

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 Kommentare
Sam Chak
am 31 Okt. 2023
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.

Weitere Antworten (1)
Aquatris
am 31 Okt. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Discontinuities finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
