Generación y Prueba de Masa y Controlador

7
 % GeneraciÛn de Datos para la Red Neuronal % Sistema Masa-Resorte. clear all close all clc % Constantes del Sistema. b = 1; % Constante de Amortiguamiento. K = 1; % Constante de Elasticidad. M = 1; % Masa. % Matrices de Sistema para las Ecuaciones de Estado. A = [ 0 1 -K/M -b/M ]; B = [ 0 1/M ]; C = [ 1 0 ]; D = [ 0 ]; % Entrada. u = 10; % EscalÛn Unitario. % DefiniciÛn de Tiempos de SimulaciÛn. ti = 0; % Tiempo Inicial. tf = 20; % Tiempo Final. dt = 0.01; % Diferencial de Tiempo. % Condiciones Iniciales. xo = [ 0 0 ]; x = xo; % SimulaciÛn. k = 1; for t = ti:dt:tf POS(k,1) = x(1,1); VEL(k,1) = x(2,1); TIEMPO(k,1) = t; % Ecuaciones de Estado. xp = A*x + B*u; y = C*x + D*u; Y1(k,1) = y(1,1); % Integrando mediante Euler. x = x + dt*xp; k = k + 1; end % Graficamos las Salidas. figure(1) subplot(211) 

Transcript of Generación y Prueba de Masa y Controlador

  • % Generacin de Datos para la Red Neuronal % Sistema Masa-Resorte. clear all close all clc % Constantes del Sistema. b = 1; % Constante de Amortiguamiento. K = 1; % Constante de Elasticidad. M = 1; % Masa. % Matrices de Sistema para las Ecuaciones de Estado. A = [ 0 1 -K/M -b/M ]; B = [ 0 1/M ]; C = [ 1 0 ]; D = [ 0 ]; % Entrada. u = 10; % Escaln Unitario. % Definicin de Tiempos de Simulacin. ti = 0; % Tiempo Inicial. tf = 20; % Tiempo Final. dt = 0.01; % Diferencial de Tiempo. % Condiciones Iniciales. xo = [ 0 0 ]; x = xo; % Simulacin. k = 1; for t = ti:dt:tf POS(k,1) = x(1,1); VEL(k,1) = x(2,1); TIEMPO(k,1) = t; % Ecuaciones de Estado. xp = A*x + B*u; y = C*x + D*u; Y1(k,1) = y(1,1); % Integrando mediante Euler. x = x + dt*xp; k = k + 1; end % Graficamos las Salidas. figure(1) subplot(211)

  • plot(TIEMPO,POS,'b') title('Posicin') xlabel('Tiempo (Segundos)') ylabel('Metros') subplot(212) plot(TIEMPO,VEL,'b') title('Velocidad') xlabel('Tiempo (Segundos)') ylabel('Metros/Segundo') x1nn = 12*randn(1,5000); x2nn = 8*randn(1,5000); unn = 10*randn(1,5000); xnn = [ x1nn; x2nn ]; xpnn = A*xnn + B*unn; xnns = xnn + xpnn*dt; masann_in = [xnn;unn]; masann_out = xnns; save masann_data masann_in masann_out La Configuracin de la Red Neuronal de de Capa Oculta Sigmoide de 10 Unidades y Capa de Salida Lineal. % Prueba de la Red Neuronal % Sistema Masa-Resorte. clear all close all clc % Constantes del Sistema. b = 1; % Constante de Amortiguamiento. K = 1; % Constante de Elasticidad. M = 1; % Masa. % Matrices de Sistema para las Ecuaciones de Estado. A = [ 0 1 -K/M -b/M ]; B = [ 0 1/M ]; C = [ 1 0 ]; D = [ 0 ]; % Entrada. u = 5; % Escaln Unitario. % Definicin de Tiempos de Simulacin. ti = 0; % Tiempo Inicial.

  • tf = 50; % Tiempo Final. dt = 0.01; % Diferencial de Tiempo. % Condiciones Iniciales. xo = [ 0 0 ]; x = xo; load PEsos_MasasNN % Simulacin. k = 1; for t = ti:dt:tf POS(k,1) = x(1,1); VEL(k,1) = x(2,1); TIEMPO(k,1) = t; % Ecuaciones de Estado. xp = A*x + B*u; y = C*x + D*u; YNN(:,k) = purelin(W2*logsig(W1*[x;u]+b1)+b2); Y1(k,1) = y(1,1); % Integrando mediante Euler. x = x + dt*xp; k = k + 1; end % Graficamos las Salidas. figure(1) subplot(211) plot(TIEMPO,POS,'b',TIEMPO,YNN(1,:),'r:') title('Posicin') xlabel('Tiempo (Segundos)') ylabel('Metros') subplot(212) plot(TIEMPO,VEL,'b',TIEMPO,YNN(2,:),'r:') title('Velocidad') xlabel('Tiempo (Segundos)') ylabel('Metros/Segundo') CONTROLADOR NEURONAL: % Generacin de Datos para la Red Neuronal % Controlador Sistema Masa-Resorte. clear all close all clc

  • % Constantes del Sistema. b = 1; % Constante de Amortiguamiento. K = 1; % Constante de Elasticidad. M = 1; % Masa. % Matrices de Sistema para las Ecuaciones de Estado. A = [ 0 1 -K/M -b/M ]; B = [ 0 1/M ]; C = [ 1 0 ]; D = [ 0 ]; % Diseo del Controlador de Estados Ai = [ A zeros(2,1); -C 0 ]; Bi = [ B; 0 ]; Wi = [ 0; 0; 1 ]; Ci = [ C 0 ]; Di = D; pdc = -10*ones(3,1); Ki = acker(Ai,Bi,pdc) K = Ki(1,1:2) kI = -Ki(1,3) % Entrada. u = 10; % Escaln Unitario. % Definicin de Tiempos de Simulacin. ti = 0; % Tiempo Inicial. tf = 20; % Tiempo Final. dt = 0.01; % Diferencial de Tiempo. % Condiciones Iniciales. xo = [ 0 0 0 ]; x = xo; r = 2; % Simulacin. k = 1; for t = ti:dt:tf POS(k,1) = x(1,1); VEL(k,1) = x(2,1); INT(k,1) = x(3,1); UU(k,1) = u; TIEMPO(k,1) = t; % Ecuaciones de Estado. xp = Ai*x + Bi*u + Wi*r; u = -Ki*x;

  • % Integrando mediante Euler. x = x + dt*xp; k = k + 1; end % Graficamos las Salidas. figure(1) subplot(211) plot(TIEMPO,POS,'b') title('Posicin') xlabel('Tiempo (Segundos)') ylabel('Metros') subplot(212) plot(TIEMPO,VEL,'b') title('Velocidad') xlabel('Tiempo (Segundos)') ylabel('Metros/Segundo') x1nn = 12*randn(1,5000); x2nn = 8*randn(1,5000); x3nn = 10*randn(1,5000); xnn = [ x1nn; x2nn; x3nn ]; unn = -Ki*xnn; contmasann_in = xnn; contmasann_out = unn; save contmasann_data contmasann_in contmasann_out La Red Neuronal del Controlador es

    % Prueba la Red Neuronal % Controlador Sistema Masa-Resorte. clear all close all clc % Constantes del Sistema. b = 1; % Constante de Amortiguamiento.

  • K = 1; % Constante de Elasticidad. M = 1; % Masa. % Matrices de Sistema para las Ecuaciones de Estado. A = [ 0 1 -K/M -b/M ]; B = [ 0 1/M ]; C = [ 1 0 ]; D = [ 0 ]; % Diseo del Controlador de Estados Ai = [ A zeros(2,1); -C 0 ]; Bi = [ B; 0 ]; Wi = [ 0; 0; 1 ]; Ci = [ C 0 ]; Di = D; pdc = -10*ones(3,1); Ki = acker(Ai,Bi,pdc) K = Ki(1,1:2) kI = -Ki(1,3) % Entrada. u = 10; % Escaln Unitario. % Definicin de Tiempos de Simulacin. ti = 0; % Tiempo Inicial. tf = 100; % Tiempo Final. dt = 0.01; % Diferencial de Tiempo. % Condiciones Iniciales. xo = [ 0 0 0 ]; x = xo; r = 4; % Simulacin. k = 1; load ContMasa for t = ti:dt:tf POS(k,1) = x(1,1); VEL(k,1) = x(2,1); INT(k,1) = x(3,1); UU(k,1) = u; TIEMPO(k,1) = t; % Ecuaciones de Estado. xp = Ai*x + Bi*u + Wi*r; %u = -Ki*x;

  • u = purelin(W2c*logsig(W1c*[x]+b1c)+b2c); % Integrando mediante Euler. x = x + dt*xp; k = k + 1; end % Graficamos las Salidas. figure(1) subplot(211) plot(TIEMPO,POS,'b') title('Posicin') xlabel('Tiempo (Segundos)') ylabel('Metros') subplot(212) plot(TIEMPO,VEL,'b') title('Velocidad') xlabel('Tiempo (Segundos)') ylabel('Metros/Segundo')