Borrar filtros
Borrar filtros

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

19 visualizaciones (últimos 30 días)
Peter
Peter el 9 de Mayo de 2024
Comentada: Sam Chak el 9 de Mayo de 2024
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);

Respuestas (1)

Sam Chak
Sam Chak el 9 de Mayo de 2024
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 comentarios
Peter
Peter el 9 de Mayo de 2024
Editada: Peter el 9 de Mayo de 2024
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 el 9 de Mayo de 2024
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

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by