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 CenterFile Exchange에서 Robotics System Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by