clear all, close all, clc
comp=3;;
global a1 a2 lc1 lc2 lc3 m1 m2 m3 I1 I2 I3 gc d1 d2
global KP KD comp gfin
global qd1 qd2 qd3 ts ta
a1=1; a2=1; a3=1;
lc1=0.4; lc2=0.4; lc3=0.4; m1=30; m2=20; m3=10; I1=3; I2=2; I3=1; gc=9.8;
% d1=50; d2=50;
d1=0; d2=0;
qd1=[pi/4; pi/4];
qd2=[pi/3; pi/2];
qd3=[pi/2; 0];
q0=[-pi/4; pi/4];
qp0=[0; 0];
dt=0.01;
Tfin=15;
ts=5;
KP=400*eye(2); KD=50*eye(2);
switch comp
case 0
tipocontrollo='PD senza compensazione della gravità';
case 1
tipocontrollo='PD con compensazione esatta della gravità';
case 2
tipocontrollo='PD con compensazione nel punto finale';
case 3
tipocontrollo='Computed Torque';
end
Tsim=0:dt:Tfin;
Nsim=max(size(Tsim));
x0=[q0; qp0];
[T,Xout]=ode45('robot3R',Tsim,x0);
N=max(size(T));
q1sim=Xout(:,1); q2sim=Xout(:,2); q3sim=Xout(:,3)
qp1sim=Xout(:,4); qp2sim=Xout(:,5); qp3sim=Xout(:,6)
if ts>=Tfin
tt=Tfin;
else
tt=ts;
end
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in robot3R_control_main (line 86)
[T,Xout]=ode45('robot3R',Tsim,x0);
It keeps giving me this kind of errors but I can't understand where i have to work on, can anyone help me please?
P.S. The code can have several errors in its writing, i just started working on it.

4 Commenti

darova
darova il 10 Mag 2020
Try this
And show your ode function
I did what you told me to do and it gives me another error:
Error: File: robot3R_control_main.m Line: 86 Column: 33
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
That is the ode45 function:
function xp=robot3R(t,x)
global KP KD qd1 qd2 qd3 ts ta comp gfin
qd=qd1;
if t>=ts
qd=qd2;
end
if ta>=t
qd=qd3;
end
if comp==2
[Bdum,mdum,gfin]=calcBmg3R(qd,[0; 0]);
end
q=x(1:2:3);
qp=x(4:5:6);
[B,m,g]=calcBmg3R(q,qp);
xp=zeros(6,1);
gcomp=[0 0]';
switch comp
case 0, gcomp=[0 0]';
case 1, gcomp=g;
case 2, gcomp=gfin;
end
u=KP*(qd-q)-KD*qp+gcomp;
umax=500;
if abs(u(1))>umax
u(1)=umax*sign(u(1));
end
if abs(u(2))>umax
u(2)=umax*sign(u(2));
end
if comp==3,
v=KP*(qd-q)-KD*qp;
u=B*v+m+g;
end
xp(1:2:3)=x(4:5:6);
xp(4:5:6)=B\(-m-g+u);
Walter Roberson
Walter Roberson il 11 Mag 2020
Your code does not have 86 lines in either files.
You cannot combine the two files together because in the syntax you used, ode45('NAME', etc) only works if NAME matches the name of a .m file or simulink model or stateflow chart, and cannot be used to refer to functions defined within the same file.
You define comp before you declare it global; that is an error in all current versions of MATLAB.
You did not post the code for calcBmg3R so we cannot execute your code to test it.
Antonio Belmaggio
Antonio Belmaggio il 11 Mag 2020
Modificato: darova il 11 Mag 2020
I didnt post everything because most of the lines i did not posted are just comments, line 86 is the ode45 line, sorry but i'm not so used to MATLAB.
Thank you for your help anyway
here is calcBmg3R script:
function [B,m,g]=calcBmg3R(q,qp)
global a1 a2 lc1 lc2 lc3 m1 m2 m3 I1 I2 I3 gc d1 d2
q1=q(1); q2=q(2); q3=q(3); qp1=qp(1); qp2=qp(2); qp3=qp(3);
B=zeros(3,3);
B(1,1) = I1 + I2 + I3 + a1^2*m2 + a1^2*m3 + a2^2*m3 + lc1^2*m1 + lc2^2*m2 + lc3^2*m3 + 2*a1*lc3*m3*cos(q2 + q3) + 2*a1*a2*m3*cos(q2) + 2*a1*lc2*m2*cos(q2) + 2*a2*lc3*m3*cos(q3);
B(1,2) = m3*a2^2 + 2*m3*cos(q3)*a2*lc3 + a1*m3*cos(q2)*a2 + m2*lc2^2 + a1*m2*cos(q2)*lc2 + m3*lc3^2 + a1*m3*cos(q2 + q3)*lc3 + I2 + I3;
B(1,3) = I3 + lc3^2*m3 + a1*lc3*m3*cos(q2 + q3) + a2*lc3*m3*cos(q3);
B(2,1) = B(1,2);
B(2,2) = m3*a2^2 + 2*m3*cos(q3)*a2*lc3 + m2*lc2^2 + m3*lc3^2 + I2 + I3;
B(2,3) = m3*lc3^2 + a2*m3*cos(q3)*lc3 + I3;
B(3,1) = B(1,3);
B(3,2) = B(2,3);
B(3,3) = m3*lc3^2 + I3;
m=zeros(3,1);
m(1,1) = - a1*qp2*(2*lc3*m3*qp1*sin(q2 + q3) + lc3*m3*qp2*sin(q2 + q3) + lc3*m3*qp3*sin(q2 + q3) + 2*a2*m3*qp1*sin(q2) + a2*m3*qp2*sin(q2) + 2*lc2*m2*qp1*sin(q2) + lc2*m2*qp2*sin(q2)) - lc3*m3*qp3*(2*a2*qp1*sin(q3) + 2*a2*qp2*sin(q3) + a2*qp3*sin(q3) + 2*a1*qp1*sin(q2 + q3) + a1*qp2*sin(q2 + q3) + a1*qp3*sin(q2 + q3));
m(2,1) = a1*lc3*m3*qp1^2*sin(q2 + q3) + a1*a2*m3*qp1^2*sin(q2) + a1*lc2*m2*qp1^2*sin(q2) - a2*lc3*m3*qp3^2*sin(q3) - 2*a2*lc3*m3*qp1*qp3*sin(q3) - 2*a2*lc3*m3*qp2*qp3*sin(q3);
m(3,1) = lc3*m3*(a1*qp1^2*sin(q2 + q3) + a2*qp1^2*sin(q3) + a2*qp2^2*sin(q3) + 2*a2*qp1*qp2*sin(q3));
g=zeros(3,1);
g(1,1) = gc*m3*(a2*cos(q1 + q2) + a1*cos(q1) + lc3*cos(q1 + q2 + q3)) + gc*m2*(lc2*cos(q1 + q2) + a1*cos(q1)) + gc*lc1*m1*cos(q1);
g(2,1) = gc*m3*(a2*cos(q1 + q2) + lc3*cos(q1 + q2 + q3)) + gc*lc2*m2*cos(q1 + q2);
g(3,1) = lc3*m3*(a1*qp1^2*sin(q2 + q3) + a2*qp1^2*sin(q3) + a2*qp2^2*sin(q3) + 2*a2*qp1*qp2*sin(q3));

Accedi per commentare.

 Risposta accettata

Walter Roberson
Walter Roberson il 11 Mag 2020

0 voti

Your q0 and qp0 are each vectors of length 2, for a total of 4, but inside robot3D you extract from x as if they were each of length 3.
You have a bunch of variables that you assume are length 2, but your ode needs to be length 3.
This is made worse by your use of global variables, making it less obvious what connection there is between initialization and sizes for calculations.
I made some changes to calculate something in a consistent manner. I have no idea whether it is calculating the right thing -- probably not. But it will perhaps make it easier for you to advance.
No message was observed about syntax problems.... just about inconsistent matrix sizes, and subscript out of range, and so on.

1 Commento

Thank you this helped a lot, i fixed my code and now it works.
Thank you so much again!

Accedi per commentare.

Più risposte (1)

darova
darova il 11 Mag 2020

0 voti

Try this modification

1 Commento

it keeps giving me the same error as before..
Error: File: robot3R_control_main.m Line: 86 Column: 33
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
(Line 86 is the ode45 line)

Accedi per commentare.

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by