4 // * Pah autopilot function. takes in the state *
5 // * variables and reference angle as arguments *
6 // * (there are other variable too as arguments *
7 // * as listed below) *
8 // * and returns the elevator deflection angle at *
9 // * every time step. *
11 // * Written 2/11/02 by Vikrant Sharma *
13 // *****************************************************
15 //#include <iostream.h>
18 // define u2prev,x1prev,x2prev and x3prev in the main function
19 // that uses this autopilot function. give them initial values at origin.
20 // Pass these values to the A/P function as an argument and pass by
22 // Parameters passed as arguments to the function:
23 // pitch - Current pitch angle
24 // pitchrate - current rate of change of pitch angle
25 // pitch_ref - reference pitch angle to be tracked
26 // sample_t - sampling time
27 // V - aircraft's current velocity
28 // u2prev - u2 value at the previous time step.
29 // x1prev - x1 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
30 // x2prev - x2 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
31 // x3prev - x3 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
32 // the autpilot function (pah_ap) changes these values at every time step.
33 // so the simulator guys don't have to do it. Since these values are
34 // passed by reference to the function.
36 // (RD) Units for the variables
43 // (RD) changed from float to double
45 #include "uiuc_pah_ap.h"
47 double pah_ap(double pitch, double pitchrate, double pitch_ref, double V,
48 double sample_t, int init)
50 // changes by RD so function keeps previous values
70 Ktheta = -0.0004*V*V + 0.0479*V - 2.409;
71 Kq = -0.0005*V*V + 0.054*V - 1.5931;
74 u1 = Ktheta*(pitch_ref-pitch);
75 u2 = u2prev + Ki*Ktheta*(pitch_ref-pitch)*sample_t;
78 totalU = u1 + u2 - u3;
80 // the following is using the actuator dynamics given in Beaver.
81 // the actuator dynamics for Twin Otter are still unavailable.
82 x1 = x1prev +(-10.951*x1prev + 7.2721*x2prev + 20.7985*x3prev +
83 25.1568*totalU)*sample_t;
84 x2 = x2prev + x3prev*sample_t;
85 x3 = x3prev + (7.3446*x1prev - 668.6713*x2prev - 16.8697*x3prev +
86 5.8694*totalU)*sample_t;