How to stop the simulation in one cycle of Simple Pendulum

1 view (last 30 days)
I made the code of simple pendulum which is moved by trq.
However, depending on the amount of torque, it will continue to rotate.
When the pendulum makes one lap, I want to stop and repeat the control.
In other words, after one lap, it was reset to the initial state [0: 0] and the simulation started again.
Please someone help me.
close all;
% parameter of simple pendulum
Length = 1.0; % Length of pendulum
Mass = 1.0; % mass of pendulum
Ts = 0.01; % time step
Theta_Initial = 0; % Initial Value of pendulum's theta
AngularVelocity_Initial = 0; % Initila Value of pendulum's angularVelocity
% call class of pendulum
Pendulum = classPendulum(Length,Mass,Theta_Initial,AngularVelocity_Initial,Ts);
Trq = -10;
% move
% If this is the case, the pendulum will stop at a certain angle and the simulation will end.
% I want to repeat the movement of the pendulum up to a certain angle.
for i = 1:1000
if Pendulum.Theta > -4.8
Pendulum.pstep(Trq);
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!