| 1 |
// * * |
| 2 |
// * alh_ap.C * |
| 3 |
// * * |
| 4 |
// * ALH autopilot function. takes in the state * |
| 5 |
// * variables and reference height 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. * |
| 10 |
// * * |
| 11 |
// * Written 7/8/02 by Vikrant Sharma * |
| 12 |
// * * |
| 13 |
// ***************************************************** |
| 14 |
|
| 15 |
//#include <iostream.h> |
| 16 |
//#include <stddef.h> |
| 17 |
|
| 18 |
// define u2prev,ubarprev,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 |
| 21 |
// reference |
| 22 |
// Parameters passed as arguments to the function: |
| 23 |
// H - Current Height of the a/c at the current simulation time. |
| 24 |
// pitch - Current pitch angle ,,,,,,,,,,,, |
| 25 |
// pitchrate - current rate of change of pitch angle |
| 26 |
// H_ref - reference Height differential wanted |
| 27 |
// sample_t - sampling time |
| 28 |
// V - aircraft's current velocity |
| 29 |
// u2prev - u2 value at the previous time step. |
| 30 |
// ubar prev - ubar ,,,,,,,,,,,,,,,,,,,,,,, |
| 31 |
// x1prev - x1 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| 32 |
// x2prev - x2 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| 33 |
// x3prev - x3 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| 34 |
// the autpilot function (alh_ap) changes these values at every time step. |
| 35 |
// so the simulator guys don't have to do it. Since these values are |
| 36 |
// passed by reference to the function. |
| 37 |
|
| 38 |
// RD changed float to double |
| 39 |
|
| 40 |
#include "uiuc_alh_ap.h" |
| 41 |
|
| 42 |
double alh_ap(double pitch, double pitchrate, double H_ref, double H, |
| 43 |
double V, double sample_time, int init) |
| 44 |
{ |
| 45 |
// changes by RD so function keeps previous values |
| 46 |
static double u2prev; |
| 47 |
static double x1prev; |
| 48 |
static double x2prev; |
| 49 |
static double x3prev; |
| 50 |
static double ubarprev; |
| 51 |
|
| 52 |
if (init == 0) |
| 53 |
{ |
| 54 |
u2prev = 0; |
| 55 |
x1prev = 0; |
| 56 |
x2prev = 0; |
| 57 |
x3prev = 0; |
| 58 |
ubarprev = 0; |
| 59 |
} |
| 60 |
|
| 61 |
double Ki; |
| 62 |
double Ktheta; |
| 63 |
double Kq; |
| 64 |
double deltae; |
| 65 |
double Kh,Kd; |
| 66 |
double x1, x2, x3; |
| 67 |
Ktheta = -0.0004*V*V + 0.0479*V - 2.409; |
| 68 |
Kq = -0.0005*V*V + 0.054*V - 1.5931; |
| 69 |
Ki = 0.5; |
| 70 |
Kh = -0.25*LS_PI/180 + (((-0.15 + 0.25)*LS_PI/180)/(20))*(V-60); |
| 71 |
Kd = -0.0025*V + 0.2875; |
| 72 |
double u1,u2,u3,ubar; |
| 73 |
ubar = (1-Kd*sample_time)*ubarprev + Ktheta*pitchrate*sample_time; |
| 74 |
u1 = Kh*(H_ref-H) - ubar; |
| 75 |
u2 = u2prev + Ki*(Kh*(H_ref-H)-ubar)*sample_time; |
| 76 |
u3 = Kq*pitchrate; |
| 77 |
double totalU; |
| 78 |
totalU = u1 + u2 - u3; |
| 79 |
u2prev = u2; |
| 80 |
ubarprev = ubar; |
| 81 |
// the following is using the actuator dynamics given in Beaver. |
| 82 |
// the actuator dynamics for Twin Otter are still unavailable. |
| 83 |
x1 = x1prev +(-10.951*x1prev + 7.2721*x2prev + 20.7985*x3prev + |
| 84 |
25.1568*totalU)*sample_time; |
| 85 |
x2 = x2prev + x3prev*sample_time; |
| 86 |
x3 = x3prev + (7.3446*x1prev - 668.6713*x2prev - 16.8697*x3prev + |
| 87 |
5.8694*totalU)*sample_time; |
| 88 |
deltae = 57.2958*x2; |
| 89 |
x1prev = x1; |
| 90 |
x2prev = x2; |
| 91 |
x3prev = x3; |
| 92 |
return deltae; |
| 93 |
} |