Help me with ode45 please
Show older comments
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 Comments
darova
on 10 May 2020
Try this

And show your ode function
Antonio Belmaggio
on 11 May 2020
Walter Roberson
on 11 May 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
on 11 May 2020
Edited: darova
on 11 May 2020
Accepted Answer
More Answers (1)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!