From: zainah on
Hi,
Could anyone check the Matlab program below, I got the error
Warning: Divide by zero.
> In QRODEF2 at 26
In funfun\private\odearguments at 110
In ode45 at 173
In QRSOLVEF2 at 97
??? Error using ==> cos
Not enough input arguments.

Error in ==> QRODEF2 at 36
dx=[x(7:12);...

Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ==> QRSOLVEF2 at 97
[t,x]=ode45(@QRODEF2,time1,x0);


Hopefully someone can suggest me where to correct it. Thank you.
----------------------------------------------------------------------------------------------


%File: QRSOLVEF2.m
clc
close all
clear all

global m g az1 az2 apsi1 apsi2 atheta1 atheta2 aphi1 aphi2 psid thetad phid I Ixx Ixy Ixz Iyx Iyy Iyz Izx Izy Izz xd yd zd z0 M_3 M_1 M_2



%Moments of Inertia (kg*m?)
Ixx=0.0857;
Ixy=0;
Ixz=0;
Iyx=0;
Iyy=1.8954;
Iyz=0;
Izx=0;
Izy=0;
Izz=1.8954;


%Contants
m=24.3;
g=9.81;
M_1=22.6964;
M_2= 40.5900;
M_3= 40.5900;


%Initial Conditions
x0=0;
y0=0;
z0=1;
psi0=0;
theta0=0;
phi0=0;

xdot0=0;
ydot0=0;
zdot0=0;
psidot0=0;
thetadot0=0;
phidot0=0;


x0=[x0 y0 z0 psi0 theta0 phi0 xdot0 ydot0 zdot0 psidot0 thetadot0 phidot0];


%Desired Conditions

xd=0;
yd=0;
zd=2;
psid=pi/2;
thetad=pi/2;
phid=pi/2;
%Z Control
scale_z=3;% asal 3
zeta_z=1; % asal 1
ts_z=scale_z*abs(zd-z0)+1;
omega_z=4/(ts_z*zeta_z);

az1=2*zeta_z*omega_z*m;
az2=m*(omega_z)^2;

%Psi Control
scale_psi=10;
zeta_psi=1;
ts_psi=scale_psi*abs(psid-psi0)+1;
omega_psi=4/(ts_psi*zeta_psi);
apsi1=2*zeta_psi*omega_psi;
apsi2=(omega_psi)^2;

%theta Control
scale_theta=10;
zeta_theta=1;
ts_theta=scale_theta*abs(thetad-theta0)+1;
omega_theta=4/(ts_theta*zeta_theta);
atheta1=2*zeta_theta*omega_theta;
atheta2=(omega_theta)^2;

%phi Control
scale_phi=10;
zeta_phi=1;
ts_phi=scale_theta*abs(phid-phi0)+1;
omega_phi=4/(ts_phi*zeta_phi);
aphi1=2*zeta_phi*omega_phi;
aphi2=(omega_phi)^2;



%Translational Sim
%addtime1=1;
%time_end1=3*ts_z+addtime1;

time1=[0:.1:25];
[t,x]=ode45(@QRODEF2,time1,x0);
figure('Name','QR Sim Trans','NumberTitle','off')
plot(t,x(:,1:3))
hold on
plot(t,x(:,7:9))
xlabel('Time (s)','FontSize',11)
ylabel(' ','FontSize',11)
title('QR Sim Translational','FontSize',14)
h = legend('x','y','z','xdot', 'ydot', 'zdot',1);



%Rotational Sim

figure('Name','QR Sim Rot','NumberTitle','off')
plot(t,x(:,4:6))
hold on
plot(t,x(:,10:12))
xlabel('Time (s)','FontSize',11)
ylabel(' ','FontSize',11)
title('QR Sim Translational','FontSize',14)
h = legend('psi','theta','phi','psidot', 'thetadot', 'phidot',1);


function dx=QRODEF2(t,x)
global m g az1 az2 apsi1 apsi2 atheta1 atheta2 aphi1 aphi2 psid thetad phid I Ixx Ixy Ixz Iyx Iyy Iyz Izx Izy Izz xd yd zd z0 M_3 M_1 M_2


%%Convention
% x=1 x1
% y=2 x2
% z=3 x3
% psi=4 x4
% theta=5 x5
% phi=6 x6
% xdot=7 x7
% ydot=8 x8
% zdot=9 x9
% psidot=10 x10
% thetadot=11 x11
% phidot=12 x12
%1,2,3,4 CCW


%Controllers

r1=-az1*x(9)-az2*(x(3)-zd);
u=r1/-(sin(x(5))); % try tukar cos
tau_tilde_psi=-apsi1*x(10)-apsi2*(x(4)-psid);
tau_tilde_theta=-atheta1*x(11)-atheta2*(x(5)-thetad);
tau_tilde_phi=-aphi1*x(12)-aphi2*(x(6)-phid);
%tau_tilde_theta=-sat(x(11)+sat(x(5)+x(11)+sat(2*x(5)+x(11)+x(7)/g+sat(3*x(5)+x(11)+3*x(7)/g+x(1)-xd/g))))
%tau_tilde_phi=-sat(x(12)+sat(x(6)+x(12)+sat(2*x(6)+x(12)+x(8)/g+sat(3*x(6)+x(12)+3*x(8)/g+x(2)-yd/g))))
tau_tilde=[tau_tilde_phi ; tau_tilde_theta; tau_tilde_psi];


%QR Dynamics
dx=[x(7:12);...
u*cos (x(5))*cos (x(4))/M_1;...
u*cos(x(5))*sin(x(4))/M_2;...
-u*sin(x(5))/M_3;...
tau_tilde];
From: Steven_Lord on


"zainah " <zainahmz(a)gmail.com> wrote in message
news:i2itg8$snh$1(a)fred.mathworks.com...
> Hi,
> Could anyone check the Matlab program below, I got the error Warning:
> Divide by zero.
>> In QRODEF2 at 26
> In funfun\private\odearguments at 110
> In ode45 at 173
> In QRSOLVEF2 at 97
> ??? Error using ==> cos
> Not enough input arguments.

*snip*

Do not put spaces between the name of a function you're calling and the
parentheses containing that function's input arguments. You do this twice
in your QRODEF2 function.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: zainah on
Thank you very much.


"Steven_Lord" <slord(a)mathworks.com> wrote in message <i2k3rd$kd8$1(a)fred.mathworks.com>...
>
>
> "zainah " <zainahmz(a)gmail.com> wrote in message
> news:i2itg8$snh$1(a)fred.mathworks.com...
> > Hi,
> > Could anyone check the Matlab program below, I got the error Warning:
> > Divide by zero.
> >> In QRODEF2 at 26
> > In funfun\private\odearguments at 110
> > In ode45 at 173
> > In QRSOLVEF2 at 97
> > ??? Error using ==> cos
> > Not enough input arguments.
>
> *snip*
>
> Do not put spaces between the name of a function you're calling and the
> parentheses containing that function's input arguments. You do this twice
> in your QRODEF2 function.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com