|
| 1 | +% Initialization for the helicopter assignment in TTK4135. |
| 2 | +% Run this file before you execute QuaRC -> Build. |
| 3 | + |
| 4 | +% Updated spring 2017, Andreas L. Flåten |
| 5 | + |
| 6 | +clear all; |
| 7 | +close all; |
| 8 | +clc; |
| 9 | + |
| 10 | +%% Physical constants |
| 11 | +m_h = 0.4; % Total mass of the motors. |
| 12 | +m_g = 0.03; % Effective mass of the helicopter. |
| 13 | +l_a = 0.65; % Distance from elevation axis to helicopter body |
| 14 | +l_h = 0.17; % Distance from pitch axis to motor |
| 15 | + |
| 16 | +% Moments of inertia |
| 17 | +J_e = 2 * m_h * l_a *l_a; % Moment of interia for elevation |
| 18 | +J_p = 2 * ( m_h/2 * l_h * l_h); % Moment of interia for pitch |
| 19 | +J_t = 2 * m_h * l_a *l_a; % Moment of interia for travel |
| 20 | + |
| 21 | +% Identified voltage sum and difference |
| 22 | +V_s_eq = 6.4; % Identified equilibrium voltage sum. |
| 23 | +V_d_eq = 0.35; % Identified equilibrium voltage difference. |
| 24 | + |
| 25 | +% Model parameters |
| 26 | +K_p = m_g*9.81; % Force to lift the helicopter from the ground. |
| 27 | +K_f = K_p/V_s_eq; % Force motor constant. |
| 28 | +K_1 = l_h*K_f/J_p; |
| 29 | +K_2 = K_p*l_a/J_t; |
| 30 | +K_3 = K_f*l_a/J_e; |
| 31 | +K_4 = K_p*l_a/J_e; |
| 32 | + |
| 33 | +%% Pitch closed loop syntesis |
| 34 | +% Controller parameters |
| 35 | +w_p = 1.8; % Pitch controller bandwidth. |
| 36 | +d_p = 1.0; % Pitch controller rel. damping. |
| 37 | +K_pp = w_p^2/K_1; |
| 38 | +K_pd = 2*d_p*sqrt(K_pp/K_1); |
| 39 | +Vd_ff = V_d_eq; |
| 40 | + |
| 41 | +% Closed loop transfer functions |
| 42 | +Vd_max = 10 - V_s_eq; % Maximum voltage difference |
| 43 | +deg2rad = @(x) x*pi/180; |
| 44 | +Rp_max = deg2rad(15); % Maximum reference step |
| 45 | +s = tf('s'); |
| 46 | +G_p = K_1/(s^2); |
| 47 | +C_p = K_pp + K_pd*s/(1+0.1*w_p*s); |
| 48 | +L_p = G_p*C_p; |
| 49 | +S_p = (1 + L_p)^(-1); |
| 50 | + |
| 51 | +plot_pitch_response = 0; |
| 52 | +if plot_pitch_response |
| 53 | + figure() |
| 54 | + step(S_p*Rp_max); hold on; |
| 55 | + step(C_p*S_p*Rp_max/Vd_max); |
| 56 | + legend('norm error', 'norm input') |
| 57 | + title('Pitch closed loop response') |
| 58 | +end |
| 59 | + |
| 60 | +%% Elevation closed loop analysis |
| 61 | +% Controller parameters |
| 62 | +w_e = 0.5; % Elevation controller bandwidth. |
| 63 | +d_e = 1.0; % Elevation controller rel. damping. |
| 64 | +K_ep = w_e^2/K_3; |
| 65 | +K_ed = 2*d_e*sqrt(K_ep/K_3); |
| 66 | +K_ei = K_ep*0.1; |
| 67 | +Vs_ff = V_s_eq; |
| 68 | + |
| 69 | +% Closed loop transfer functions |
| 70 | +Vs_max = 10 - V_s_eq; % Maximum voltage sum |
| 71 | +Re_max = deg2rad(10); % Maximum elevation step |
| 72 | +G_e = K_3/(s^2); |
| 73 | +C_e = K_ep + K_ed*s/(1+0.1*w_e*s) + K_ei/s; |
| 74 | +L_e = G_e*C_e; |
| 75 | +S_e = (1 + L_e)^(-1); |
| 76 | + |
| 77 | +plot_elev_response = 0; |
| 78 | +if plot_elev_response |
| 79 | + figure() |
| 80 | + step(S_e*Re_max); |
| 81 | + hold on; |
| 82 | + step(C_e*S_e*Re_max/Vs_max); |
| 83 | + legend('norm error', 'norm input') |
| 84 | + title('Elevation closed loop response') |
| 85 | +end |
0 commit comments