how to make input to the system time variable?

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.

댓글 수: 1

Rik
Rik 2023년 10월 31일
I have some difficulty understanding what you actually want to achieve in terms of Matlab code. It seems like there are a few steps missing.
Have a read here and here. It will greatly improve your chances of getting an answer.

댓글을 달려면 로그인하십시오.

 채택된 답변

Sam Chak
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

Min Khant
Min Khant 2023년 10월 31일
편집: Min Khant 2023년 10월 31일
thank you for generously answering my question even though I was bad at making a question. sir
as I am a beginner, I found simulink easier than coding in Matlab and thus I tried to finish my midterm project building blocks in simulink. i have alrdy finished problem 2(in attached file) by building blocks for feedback control. Now in problem 3 I have to create blocks for feedforward control which including a time-varying desired theta value. I wanted to ask how I can create a simulink block that can defines the desired time varying input.
Min Khant
Min Khant 2023년 10월 31일
I was willing to create an input that defines time-varying desired theta and differentiate it twice and build other necessary blocks to complete the feedforward tau which will lated be fed into the plant.
if there are better ideas than mine , I am willing to hear it sir
Sam Chak
Sam Chak 2023년 10월 31일
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.
May I know how to use derivative block consecutively? sir
as i tried , it does not function properly

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Aquatris
Aquatris 2023년 10월 31일

0 개 추천

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.

카테고리

제품

릴리스

R2023b

질문:

2023년 10월 31일

댓글:

2023년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by