Double Pendulum Simulation using Simulink

7 ビュー (過去 30 日間)
ad
ad 2020 年 7 月 23 日
編集済み: Fangjun Jiang 2020 年 7 月 23 日
I am trying to simulate the motion of a double pendulum with simulink using the Lagrangian equations. I have specified 6 inputs in the configuration parameters window> data import/export text field, namely t, gravitation g, mass1, mass2, Length 1, Length 2. However, t is a column vector ( t = [0 : 1 : 10] ' ), while the other inputs are constant values (simple numbers). I used the input block instead of the constant block so that I can change the values in the matlab workspace later to see how the pendulum behaves under different conditions.
When I try to run the model, I get the error that the dimensions of the inputs do not match. I checked in the help center, and it seems that when using the input block in simulink, the data type that is inported cannot be just a number/constant value. Is that correct? If yes, is there a way that I can input a time vector together with the constant values for g,m1,m2,L1,L2 ?
In case there is no way, I wanted to see if it works when I turn g, m1, m2, L1, L2 into constants (with constant blocks instead of input blocks in the simulink model). However, when doing that, I get the error that the vectors tout and yout are not the same length. I do not know how to access or change the yout vector. Can anyone help me?
Any help is much appreciated! This is my matlab code so far:
% Double Pendulum
clear ;
close all ;
% --------Model Variables-------------------------------------------------
% define t, g, m1, m2, L1, L2
t = [0 : 1 : 10]'; % simulation time transposed to a column vector
m1 = 5; % mass of pendulum 1
m2 = 5; % mass of pendulum 2
L1 = 10; % line 1 connecting mass 1 (rod length 1)
L2 = 10; % line 2 connecting mass 2 (rod length 2)
g = 9.81 ; % gravity
%define initial angles -> don't know if needed
%theta1 = pi/8; %initial L1 angle
%theta2 = pi/4; %initial L2 angle
%---------------access the according simulation in simulink----------------
output = sim('Finalmodel');
% ------------plot---------------------------------------------------------
% define tout and yout as the outputs
tout = output.tout ;
yout = output.yout ;
%plot tout over yout --> not sure which code to use
%hold on
plot(tout, yout)
%hold off
%drawnow;

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 7 月 23 日
編集済み: Fangjun Jiang 2020 年 7 月 23 日
The best way for this is to use the Constant block. You can specify the value of the Constant block as "m1" where "m1" is the variable in base workspace. When you change the value of "m1", it will be reflected in the model when you run simulation.
If you insist using Inport block, you need to make it the same size as t
t=(0:1:10)';
m1=5*ones(size(t));
tout and yout are specified in the same dialog window. They should have the same length once a successful simulation is run. Pay attention to the saving format and the "single simulation output" check mark and variable name.

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by