From: zainah on
Hi,
Can someone check my code, and error like below cameout when running the program. What should I do to correct it.

??? Input argument "Yd" is undefined.

Error in ==> sb_inputy at 8
e1 = Yd(1) - y(1);

Error in ==> y_position at 46
u=sb_inputy(t_current,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd);


------------------------------------------------------------------------------------------------------
clear;
ns =12;% number of states
ni =4;% number of inputs
%
mb = 21.43; % mass of the vehicle
rho = 1023.0; % fluid density
l = 0.1; % distance
r = 0.1; % radius
b = 0.068; % thrust factor
d = 3.617e-4; % drag factor
Jx = 0.0857; %roll inertia of the vehicle
Jy = 1.1143; % pitch inertia of the vehicle
Jz = 1.1143; % yaw inertia of the vehicle
Jt = 1.1941e-4; % thruster inertia
%
m1 = mb + 0.394*rho*pi*r^3; %total mass in the x-direction
m2 = mb + 5.96*rho*pi*r^3; %total mass in the y-direction
m3 = mb + 5.96*rho*pi*r^3; %total mass in the z-direction
%
Ix = Jx + 0; %total inertia in the x-direction
Iy = Jy + 24.2648*rho*pi*r^5; %total inertia in the y-direction
Iz = Jz + 24.2648*rho*pi*r^5; %total inertia in the z-direction
%
k1 = 0.15; k2 = 35; k3 = 35; k4 = 1.0; k5 = 2.0; % control gains (critical damping)
%k1 = 0.15; k2 = 35; k3 = 35; k4 = 1.0; k5 = 3.0; % control gains (overdamped)
%k1 = 0.15; k2 = 35; k3 = 35; k4 = 1.0; k5 = 1.0; % control gains (underdamped)
%
Xd = [2 0 0 0 0 0 0 0 0 0 0 0]'; % desired state vector
Yd = [0 0 2 0 0 0 0 0 0 0 0 0]'; % desired state vector
x0 = [0 0 0 0 0 0 pi/4 0 pi/4 0 pi/4 0]'; % initial state vector
%
omega(1) = 0.0; omega(2) = 0.0; omega(3) = 0.0; omega(4) = 0.0; %initial rotation
%
tf = 15; % final time for simulation
delta_t = 0.01; % ƒTƒ“ƒvƒŠƒ“ƒO•?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j1 = 0;% j2 = 0; j3 = 0;
for i=1:tf/delta_t+1
t_current = (i-1)*delta_t;
%
%%%%%%%%%% Nonholonomic control for all attitudes and x-position %%%%%%%%%%
% measurement of state
y = x0; %asal y = x0;
% control inputs
u=sb_inputy(t_current,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd);
%
% solving of capital Omega
% transformation matrix T
T = [ b b b b;
d -d d -d;
b 0 -b 0;
0 b 0 -b];
% u = T * Omega2, where Omega2 = [omega1^2 omega2^2 omega3^2 omega4^2]'
Omega2 = inv(T)*u;
%
for i1 = 1:ni
omega(i1) = sqrt(Omega2(i1));
end
% Capital omega = omega2 + omega4 - oemga1 - omega3
Omega = omega(2) + omega(4) - omega(1) - omega(3);
%
% saving of state x_1,...,x_n and inputs u_1,...,u_m
z(i,1) = t_current;
for j2=1:ns
z(i,j2+1) = x0(j2);
end
%
v(i,1) = t_current;
%
for j2=1:ni
v(i,j2+1) = u(j2); % force or torque inputs
v(i,j2+1+ni) = omega(j2); % for rotational inputs
end
% update of kinematic states
tspan=[t_current i*delta_t];
[t, x]=ode45(@sb_planty, tspan, x0, [],k1,k2,k3,k4,k5,m1,m2,m3,Ix,Iy,Iz,Jt,Omega,l,Xd,Yd);
%t,uvˆÈŠO‚̃pƒ‰ƒ??[ƒ^‚ðˆø?”‚É‚·‚é‚Æ‚«?@@ŠÖ?”–¼
%t,uv‚Ì‚Ý‚ðˆø?”‚É‚·‚é‚Æ‚«‚Í 'ŠÖ?”–¼'‚Å?‘‚¯‚é
% n=size(t,1); %t‚Ì?s?”‚𒲂ׂé; ‚Ü‚½‚Í
n=size(x,1); % x‚Ì?s?”‚𒲂ׂé % size(x,2)‚Ì‚Æ‚«‚Í—ñ?”
x0=[x(n,1);x(n,2);x(n,3);x(n,4);x(n,5);x(n,6);x(n,7);x(n,8);x(n,9);x(n,10);x(n,11);x(n,12)];
% tspan‚Ì?ÅŒã‚ÌŒvŽZ’l‚ðŽŸ‚Ì?‰Šú’l‚Æ‚µ‚ÄŽ?‚Á‚Ä‚ä‚­
%%%%%%%%%%% ˆê“x‚É‰ð‚­‚Æ‚« %%%%%%%%%%%%%%%%%%%%%%%%%%
% options=odeset('RelTol',1.0e-5,'AbsTol',1.0e-5);
% [t,x]=ode45('sb_plant',[0 tf],x0,options);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
%
%
figure(1)
plot(z(:,1),z(:,8),'-',z(:,1),z(:,10),'--',z(:,1),z(:,12),':','LineWidth',1.5)
%hold on
%plot(z(:,1),z(:,5),'-.',z(:,1),z(:,6),'--',z(:,1),z(:,7),':','LineWidth',1.0)
%hold off
%
axis([0 tf -0.2 1.0])
ax1=findobj(gca,'Type','Axes','Visible','on');
set(ax1,'FontSize',18,'FontName','times')
%
word_1 = legend('{\phi}','{\theta}','{\psi}');
set(word_1,'FontName','Times')
%grid
xlabel('Time {\it t} [s]','FontSize',18,'FontName','Times')
ylabel('Attitude [rad]','FontSize',18,'FontName','Times')
title('Attitude {\phi}, {\theta} and {\psi}','FontSize',18,'FontName','Times')
%
%
figure(2)
plot(z(:,1),z(:,9),'-',z(:,1),z(:,11),'--',z(:,1),z(:,13),':','LineWidth',1.5)
%hold on
%plot(z(:,1),z(:,5),'-.',z(:,1),z(:,6),'--',z(:,1),z(:,7),':','LineWidth',1.0)
%hold off
%
axis([0 tf -0.4 0.4])
ax1=findobj(gca,'Type','Axes','Visible','on');
set(ax1,'FontSize',18,'FontName','times')
%
word_1 = legend('Rate of {\phi}','Rate of {\theta}','Rate of {\psi}');
set(word_1,'FontName','Times')
%grid
xlabel('Time {\it t} [s]','FontSize',18,'FontName','Times')
ylabel('Attitude rate [rad/s]','FontSize',18,'FontName','Times')
title('Attitude rate of {\phi}, {\theta} and {\psi}','FontSize',18,'FontName','Times')
%title('Attitude rate \dot{\phi}, \dot{\theta} and \dot{\psi}','FontSize',18,'FontName','Times')
%
%
figure(3) % y position
plot(z(:,1),z(:,4),'-','LineWidth',1.5)
%hold on
%plot(z(:,1),z(:,5),'-.',z(:,1),z(:,6),'--','LineWidth',1.5)
%hold off
%
axis([0 tf -0.5 3])
ax1=findobj(gca,'Type','Axes','Visible','on');
set(ax1,'FontSize',18,'FontName','times')
%
word_1 = legend('{\it x}');
set(word_1,'FontName','Times')
%grid
xlabel('Time {\it t} [s]','FontSize',18,'FontName','Times')
ylabel('Position {\it y} [m]','FontSize',18,'FontName','Times')
title('Controlled result of position {\it y}','FontSize',18,'FontName','Times')
%
%

figure(4)% rate y position
plot(z(:,1),z(:,5),'-','LineWidth',1.5)
%hold on
%plot(z(:,1),z(:,5),'-.',z(:,1),z(:,6),'--','LineWidth',1.5)
%hold off
%
axis([0 tf -0.5 2])
ax1=findobj(gca,'Type','Axes','Visible','on');
set(ax1,'FontSize',18,'FontName','times')
%
word_1 = legend('Rate of {\it x}');
set(word_1,'FontName','Times')
%grid
xlabel('Time {\it t} [s]','FontSize',18,'FontName','Times')
ylabel('Position rate of {\it x} [m]','FontSize',18,'FontName','Times')
title('Controlled result of position rate of {\it x}','FontSize',18,'FontName','Times')
%
%
figure(5)
plot(v(:,1),v(:,2),'-',v(:,1),v(:,3),'--',v(:,1),v(:,4),':',v(:,1),v(:,5),'-.','LineWidth',1.8);
%hold on
%plot(v(:,1),v(:,4),':',v(:,1),v(:,5),'-.','LineWidth',1.0);
%hold off
%
%axis([0 tf -4 4])
tmpaxis=axis; axis([0 tf tmpaxis(3:4)]) % tmpaxis(1:2)‚ÍŒ»?Ý‚Ì?Ý’è‚©‚çŽæ‚Á‚½[xmin xmax]‚ð‚ ‚ç‚킵?Ctmpaxis(3:4)‚Í[ymin y max]‚ð‚ ‚ç‚í‚·
ax1=findobj(gca,'Type','Axes','Visible','on');
set(ax1,'FontSize',18,'FontName','times')
%
word_2 = legend('{\it u}_1','{\it u}_2','{\it u}_3','{\it u}_4');
set(word_2,'FontName','Times')
%
%grid
xlabel('Time {\it t} [s]','FontSize',18,'FontName','Times')
ylabel('Control input {\it u}_{\it i}','FontSize',18,'FontName','Times')
title('Control inputs {\it u}_1,..., {\it u}_4','FontSize',18,'FontName','Times')
%
%
figure(6)
plot(v(:,1),v(:,6),'-',v(:,1),v(:,7),'--',v(:,1),v(:,8),':',v(:,1),v(:,9),'-.','LineWidth',1.5);
%hold on
%plot(v(:,1),v(:,4),':',v(:,1),v(:,5),'-.','LineWidth',1.0);
%hold off
%
%axis([0 tf -4 4])
tmpaxis=axis; axis([0 tf tmpaxis(3:4)]) % tmpaxis(1:2)‚ÍŒ»?Ý‚Ì?Ý’è‚©‚çŽæ‚Á‚½[xmin xmax]‚ð‚ ‚ç‚킵?Ctmpaxis(3:4)‚Í[ymin y max]‚ð‚ ‚ç‚í‚·
ax1=findobj(gca,'Type','Axes','Visible','on');
set(ax1,'FontSize',18,'FontName','times')
%
word_2 = legend('{\omega}_1','{\omega}_2','{\omega}_3','{\omega}_4');
set(word_2,'FontName','Times')
%
%grid
xlabel('Time {\it t} [s]','FontSize',18,'FontName','Times')
ylabel('Control input {\omega}_{\it i} [rad/s]','FontSize',18,'FontName','Times')
title('Control inputs in rotation {\omega}_1,..., {\omega}_4','FontSize',18,'FontName','Times')




function actual_u=sb_inputy(t,x,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd)
% u1 = [m1*hat_u1]/[cos(x9)*cos(x11)],
% where hat_u1 = -k4*e1 - k5*e2
% in which ei = yi^d - yi
%
e1 = Yd(1) - y(1);
e2 = Yd(2) - y(2);
hat_u1 = k4*e1 + k5*e2;
%hat_u1 = -k4*e1 - k5*e2;
%
u(1) = (m2*hat_u1)/(cos(x(9))*sin(x(11)));
%
u(2) = -Ix*(x(7) - Xd(7)) - k1*x(8);
u(3) = -Iy*(x(9) - Xd(9))/l - k2*x(10);
u(4) = -Iz*(x(11) - Xd(11))/l - k3*x(12);
%
%
actual_u = [u(1); u(2); u(3); u(4)];

function[xdot]=sb_planty(t,x,y,k1,k2,k3,k4,k5,m1,m2,m3,Ix,Iy,Iz,Jt,Omega,l,Xd,Yd)
% x(1)= x, x(2) = dot x, x(3) = y, x(4) = dot y, x(5) = z, x(6) = dot z,
% x(7) = phi, x(8) = dot phi, x(9) = theta, x(10) = dot theta, x(11) = psi, x(12) = dot psi
theta = x(9);
psi = x(11);
%
u=sb_inputy(t,x,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd);
%
%
f_xu = [x(2); cos(theta)*cos(psi)*u(1)/m1; x(4); cos(theta)*sin(psi)*u(1)/m2; x(6); -sin(theta)*u(1)/m3; x(8);
x(10)*x(12)*((Iy-Iz)/Ix) + u(2)/Ix; x(10); x(8)*x(12)*((Iz-Ix)/Iy) - Jt*x(12)*Omega/Iy + l*u(3)/Iy; x(12);
x(8)*x(10)*((Ix-Iy)/Iz) + Jt*x(10)*Omega/Iz + l*u(4)/Iz];
% function
xdot=f_xu;
From: Walter Roberson on
zainah wrote:

> ??? Input argument "Yd" is undefined.

> u=sb_inputy(t_current,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd);

Count the arguments you are passing in to the function.


> function actual_u=sb_inputy(t,x,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd)

Count the arguments that are needed by the function.
From: Steven_Lord on


"Walter Roberson" <roberson(a)hushmail.com> wrote in message
news:JQo6o.57864$YX3.14234(a)newsfe18.iad...
> zainah wrote:
>
>> ??? Input argument "Yd" is undefined.
>
>> u=sb_inputy(t_current,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd);
>
> Count the arguments you are passing in to the function.
>
>
>> function actual_u=sb_inputy(t,x,y,k1,k2,k3,k4,k5,m2,Ix,Iy,Iz,l,Xd,Yd)
>
> Count the arguments that are needed by the function.

And as a stylistic suggestion (that would also have helped avoid this
problem) consider packing your additional input arguments in a struct array
and passing just that struct array as an additional input, retrieving the
appropriate fields from the struct inside sb_inputy as needed. That way,
instead of calling your function with fourteen inputs, you'd call it with 4.
I find 4-input function calls to be much easier to read than 14-input
function calls.

--
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