block does not fully set the dimensions of output 'ddtheta'
1 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
Sam Chak
2024-5-9
Hi @Peter
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 个评论
Sam Chak
2024-5-9
Hi @Peter
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!