block does not fully set the dimensions of output 'ddtheta'

3 ビュー (過去 30 日間)
Peter
Peter 2024 年 5 月 9 日
コメント済み: Sam Chak 2024 年 5 月 9 日
Hello
I am trying to control dimming for 2 dof system, here is my problem:
Error:Block ''untitled/Subsystem/MATLAB Function'' does not fully set the dimensions of output 'ddtheta'.
Does anyone know how to fix this?
Here is my sctructure:
Here is code inside MATLAB function:
function ddtheta = Robot_2_DOF(dtheta,theta,to)
m1=1;
m2=1;
l1=1;
l2=1;
g=9.81;
theta1=theta(1);
theta2=theta(2);
dtheta1=dtheta(1);
dtheta2=dtheta(2);
%% M
M=[((m1+m2)*l1^2+m2*l2^2+2*m2*l1*l2*cos(theta2)) m2*l2^2+m2*l1*l2*cos(theta2) ;...
m2*l2^2+m2*l1*l2*cos(theta2) m2*l2^2 ];
%% V
V=[-l1*l2*m2*sin(theta2)*(2*dtheta1*dtheta2^2) ;...
m2*l1*l2*dtheta1^2*sin(theta2)];
%% G
G=[(m1+m2)*g*l1*cos(theta1)+m2*g*l2*cos(theta2) ;...
m2*g*l2*cos(theta1+theta2)];
%% ddtheta
ddtheta=M/(to-V-G-dtheta);

回答 (1 件)

Sam Chak
Sam Chak 2024 年 5 月 9 日
I'm not familiar with the specifics of your Robot dynamics, but based on my understanding of MATLAB, it seems that you should use a backslash operator (\) instead of a forward slash operator (/).
tspan = [0 2];
theta0 = [1 0];
[t, x] = ode45(@(t, theta) Robot_2_DOF(t, theta, 1), tspan, theta0);
plot(t, x), grid on
function ddtheta = Robot_2_DOF(t, theta, to)
m1 = 1;
m2 = 1;
l1 = 1;
l2 = 1;
g = 9.81;
theta1 = theta(1);
theta2 = theta(2);
dtheta1 = theta1;
dtheta2 = theta2;
%% M
M = [((m1+m2)*l1^2+m2*l2^2+2*m2*l1*l2*cos(theta2)) m2*l2^2+m2*l1*l2*cos(theta2) ;...
m2*l2^2+m2*l1*l2*cos(theta2) m2*l2^2 ];
%% V
V = [-l1*l2*m2*sin(theta2)*(2*dtheta1*dtheta2^2) ;...
m2*l1*l2*dtheta1^2*sin(theta2)];
%% G
G = [(m1+m2)*g*l1*cos(theta1)+m2*g*l2*cos(theta2) ;...
m2*g*l2*cos(theta1+theta2)];
%% ddtheta
ddtheta = M\(to - V - G - [dtheta1; dtheta2]); % <--- use backslash \
end
  2 件のコメント
Peter
Peter 2024 年 5 月 9 日
編集済み: Peter 2024 年 5 月 9 日
I tried doing what you said, I tried changing a backslash operator (\) instead of a forward slash operator (/), but it still doesn't seem to solve the error. If you have any other solution, please let me know. I'm really grateful and waiting for your response.
Sam Chak
Sam Chak 2024 年 5 月 9 日
I don't have any issue running the corrected code (backslash) below. Are you sure that you are still getting the same Error: Block "MATLAB Function" does not fully set the dimensions of output 'ddtheta'? If that happens, most probably the initial values in your Integrator blocks are incorrectly set.
function ddtheta = Robot_2_DOF(theta, dtheta, to)
m1 = 1;
m2 = 1;
l1 = 1;
l2 = 1;
g = 9.81;
theta1 = theta(1);
theta2 = theta(2);
dtheta1 = dtheta(1);
dtheta2 = dtheta(2);
%% M
M = [((m1+m2)*l1^2+m2*l2^2+2*m2*l1*l2*cos(theta2)) m2*l2^2+m2*l1*l2*cos(theta2) ;...
m2*l2^2+m2*l1*l2*cos(theta2) m2*l2^2 ];
%% V
V = [-l1*l2*m2*sin(theta2)*(2*dtheta1*dtheta2^2) ;...
m2*l1*l2*dtheta1^2*sin(theta2)];
%% G
G = [(m1+m2)*g*l1*cos(theta1)+m2*g*l2*cos(theta2) ;...
m2*g*l2*cos(theta1+theta2)];
%% ddtheta
ddtheta = M\(to - V - G - dtheta);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRobotics System Toolbox についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by