Goal 1. Use Simulink to model and control velocity and altitude control of an ornithopter MAV
Goal 2. Use Matlab to calculate the forces and moments of a MAV and add the inputs to a mav
Matlab Linearization and Eigenvalues
0001 %function BATCAM_lin()
0002 % Capt Travis Higgs
0003 % Thesis: Batcam Control Law Development
0004 % This code linearizes the BATCAM nonlinear EOM simulink model using
0005 % the linmod command. It then checks the A matrix eigenvalues for stability
0006 % BATCAM_lin.m
0007
0008 % Dimensions Units
0009 % mass slugs
0010 % length ft
0011 % area ft^2
0012 % velocity ft/s
0013 % acceleration ft/s^2
0014 % density slugs/ft^3
0015 % force lbf
0016 % moments lbf-ft
0017 % angles deg Few people THINK in rads!
0018 % angular velocity deg/s
0019 % angular accel deg/s^2
0020
0021 clear; clc; %clf;
0022 format short g
0023
0024 global CLc CDc Cyc Cmc Cnc Clc xw rho g W m Ixx Iyy Izz Ixz S b cbar u0 x0
0025
0026 utest=u0
0027 xtest=x0
0028 [A,B,C,D] = linmod('BATCAM_nonlin_g');%,xtest,utest)
0029 %[A2,B2,C2,D2] = linmod('BATCAM_nonlin_f_test');%,x0,u0) Verification that
0030 %they are equivalent
0031 %[A,B,C,D] = linmod('sys', x, u) obtains the linearized model of sys
0032 %around an operating point with the specified state variables
0033 %x and the input u. If you omit x and u, the default values are zero.
0034
0035 %A(5,7)=-1.2946; Replace the large coupling value of -74
0036 %discovered it is the result of linmod perturbing in RADIANS about the
0037 %trim condition. The force and moment coefficients are determined using
0038 %DEGREES, but the resulting coefficients are non-dimensional
0039
0040 %Pull the sub-matrices from the big A matrix...
0041 Aph = A(1:2,1:2) %phugoid
0042 Asp = A(3:4,3:4) %short period
0043 Aroll = A(5:6,5:6) %roll
0044 Adr = A(7:8,7:8) %dutch roll
0045 Alat_dir= A(5:8,5:8) %coupling
0046
0047 %Calculate the eigenvalues of those sub matrices
0048 eig_ph = eig(Aph)
0049 eig_sp = eig(Asp)
0050 eig_roll = eig(Aroll)
0051 eig_dr = eig(Adr)
0052 eig_lat_dir = eig(Alat_dir)
0053 eig_A = eig(A)
0054 worst_eig_A = max(real(eig(A)))
0055
0056 save BATCAM_linmod A B C D Aph Asp Aroll Adr -ascii -tabs; %save for manipulation in Excel
0057
0058 %%%%%%%%%%%%%%%%%%%%%%%%%% Determine a Linear Controller %%%%%%%%%%%%%%%%%%%%%%%%%
0059 % No success with these--quick attempts out of curiosity
0060 %rank(B)
0061 % p=[-.75,-.75,-.75,-1,-1,-1,-2,-2,-2,-3,-3,-3];
0062 % K=place(A,B,p)
0063 % % Aplace=A-B*K
0064 % % eig(Aplace)
0065 % %
0066 % %%%%%%%% LQR Method %%%%%%%%%
0067 % Q=100*eye(12);
0068 % %R=[.01 0 0;0 100 0;0 0 100];
0069 % R=eye(3);
0070 %
0071 % Klqr=lqr(A,B,Q,R)
0072 % Alqr=A-B*Klqr
0073 % eig(Alqr)
0074 %
0075 % x_disturbance = .1*rand(12,1)
0076 %
0077 % %plat_dir=[p1,p2,p3,p4]
0078 % %Kph=1
0079
0080 return