Nghiên cứu điều khiển thích nghi cho robot lặn tự hành - 20


PL5. File CurrGen.m


function [Vc,uc,vc] = CurrGen(Vc_k_1,psi,h)


% CURRGEN generates values of current to input into simulation programs

%

% Inputs:

% Vc_k_1 current velocity at previuos time step (m/s)

% psi ship's heading (rad)

Có thể bạn quan tâm!

Xem toàn bộ 169 trang tài liệu này.

% h sampling time (sec)

%

Nghiên cứu điều khiển thích nghi cho robot lặn tự hành - 20

% Outputs:

% Vc current velocity at present time step (m/s)

% uc longitudinal velocity caused by current (m/s)

% vc lateral velocity caused by current (m/s)

%

% Author: Phung-Hung Nguyen, Korea Maritime University

% Date: 2006/Jan/10th

%

%======================================================================

=


% Setup values

% alph = 0.25;

Vcmax = 1;%0.2572;%1; % Maximum current velocity (m/s) Vcmin = 0.25;%0.1028;%0.5; % Minimum current velocity (m/s) Hc = 110;%220; % Current direction (deg)

%------------------------------------------------


Vc_dot = (2*rand-1)*0.15;% - alph*Vc_k_1; Vc = Vc_k_1 + h*Vc_dot;

if Vc<Vcmin

Vc = Vcmin;%Vc_k_1 - h*Vc_dot; elseif Vc>Vcmax

Vc = Vcmax;%Vc_k_1 - h*Vc_dot; end

% Vc = 0; % This is to set zero current sslip = psi - Hc*pi/180;

if sslip<=-pi

sslip = sslip + 2*pi; elseif sslip<=pi

sslip = sslip; else % pi<sslip<=2*pi

sslip = sslip - 2*pi; end

uc = Vc*cos(sslip); vc = -Vc*sin(sslip);

%>>>>>>>>>>>END<<<<<<<<<<<


PL6. File mạng nơ-ron nhiều lớp truyền thẳng


function Oi = mlnnc(outputs,hiddens,inputs,net_in,W21,W32)


% MLNNC calculate outputs of multi-layer neural network controller. s

% This isingle hidden layer feedforward network

%

% Inputs:

% outputs = i number of neurons in output layer, integer

% hiddens = j number of neurons in hidden layer, integer

% inputs = p number of neurons in input layer, integer

% net_in input signal of neural network, (px1) column vector

% W21 hidden weights, (jxp) matrix

% W32 output weight, (ixj) matrix

%

% Outputs:

% Oi output signal of neural network, (ix1) column vector

%

% Author: Phung-Hung Nguyen (Vietnam Maritime University)

% Date: 2005/Dec/4th

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Check input dimension

if (length(net_in)~=inputs)

error('Length of input vector and number of inputs are not equal

!');

end


neti = 0;

for j=1:hiddens netj(j)=0;

for p=1:inputs

mod_inj(j,p) = net_in(p)*W21(j,p); % Calculated the modulated

input


input


netj(j) = mod_inj(j,p) + netj(j); % Calculated the accumulated

end % End of statement "for p=..." Oj(j) = 1/(1+exp(-netj(j)));

mod_ini(j) = Oj(j)*W32(j); % Calculated the modulated input

neti = neti + mod_ini(j); % Calculated the accumulated input

end % End of statement "if j=..."

Oi = tansig(neti); % This is the output of NN controller


%>>>>>>>>>>>END<<<<<<<<<<<


PL7. File huấn luyện mạng nơ-ron thích nghi


function [W21,W32] = annaiTrain(h,lr,N,outputs,hiddens,inputs,net_in,e,U,r,...

ro_w,lamda_w,beta_w)


% ANNAITRAIN calculate weights of multi-layer feedforward neural network

% using "ANNAI" algorithm

%

% Inputs:

% h sampling inteval

% lr learning rate

% N number of training iterations

% outputs number of neurons in output layer, integer

% hiddens number of neurons in hidden layer, integer

% inputs number of neurons in input layer, integer

% net_in input signal of neural network, column vector

% e controlled error

% U control input

% r additional controlled item

% ro_w constant

% lamda_w constant

% beta_w constant

%

% Outputs:

% W21 hidden weights, matrix

% W32 output weight, matrix

%

% Author: Phung-Hung Nguyen

% Date: 2005/Dec/4th

% Modified to apply to AUV by PHAM VIET ANH 2019/Jun/10th

%======================================================================


W21 = rand(hiddens,inputs)*0.0001; % Set random hidden layer weights W32 = rand(outputs,hiddens)*0.0001; % Set random output layer weights A = ro_w*e + lamda_w*U + beta_w*r;


itr = 0; % Iterations of training while itr<N

neti = 0;

for j=1:hiddens netj(j)=0;

for p=1:inputs

mod_inj(j,p) = net_in(p)*W21(j,p); % Calculated the modulated input

netj(j) = mod_inj(j,p) + netj(j); % Calculated the accumulated input

end % End of statement "for p=..." Oj(j) = 1/(1+exp(-netj(j)));

mod_ini(j) = Oj(j)*W32(j); % Calculated the modulated input neti = neti + mod_ini(j); % Calculated the accumulated input

end % End of statement "if j=..."

% calculate new weights: for j=1:hiddens

% W32_dot(j) = lr*Oj(j)*exp(-2*neti)/(1+exp(-2*neti))^2*A; W32_dot(j) = lr*Oj(j)*A;

W32(j) = W32(j) + h*W32_dot(j); for p=1:inputs

W21_dot(j,p) = net_in(p)*W32(j)*W32_dot(j)*(1/(1+exp(netj(j))));



end


end

W21(j,p) = W21(j,p) + h*W21_dot(j,p);

itr = itr+1;

end % End of "while itr<N"

%>>>>>>>>>>>END<<<<<<<<<<<

Xem tất cả 169 trang.

Ngày đăng: 21/02/2023
Trang chủ Tài liệu miễn phí