You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
6.6 KiB

  1. #ifndef ASSEMBLAGE_INCLUDES_H
  2. #define ASSEMBLAGE_INCLUDES_H
  3. #include "types.h"
  4. #include "io.h"
  5. /* ***************************************************************************
  6. * Shared constants
  7. * ************************************************************************* */
  8. #define delta_th_eq (1.5868660794926)
  9. #define delta_e_eq (0.012009615652468)
  10. extern const REAL_TYPE h_eq;
  11. extern const REAL_TYPE Va_eq;
  12. #ifndef NBMAX_SAMPLE
  13. #define NBMAX_SAMPLE (6000000/4)
  14. #endif
  15. extern REAL_TYPE sample[SPL_SIZE][NBMAX_SAMPLE];
  16. void print_inmemory_sample();
  17. /* ***************************************************************************
  18. * The prelude imported node prototypes
  19. * ************************************************************************* */
  20. /**
  21. * Va filter (100/50/33/25 Hz --> 10/20/30/40 ms period)
  22. * @param[in] Va, airspeed (m/s)
  23. * @return Va_f, filtered airspeed (m/s)
  24. * 2nd order Butterworth filter with fc = 0.5 Hz (Matlab function butter)
  25. * Discretized with Zero-order Hold method with Ts = 0.01/0.02/0.03/0.04 (Matlab function c2d)
  26. */
  27. REAL_TYPE
  28. Va_filter_100(REAL_TYPE Va);
  29. REAL_TYPE
  30. Va_filter_50(REAL_TYPE Va);
  31. REAL_TYPE
  32. Va_filter_33(REAL_TYPE Va);
  33. REAL_TYPE
  34. Va_filter_25(REAL_TYPE Va);
  35. /**
  36. * Vz filter (100/50/33/25 Hz --> 10/20/30/40 ms period)
  37. * @param[in] Vz, vertical speed (m/s)
  38. * @return Vz_f, filtered vertical airspeed (m/s)
  39. * 2nd order Butterworth filter with fc = 0.5 Hz (Matlab function butter)
  40. * Discretized with Zero-order Hold method with Ts = 0.01/0.02/0.03/0.04 (Matlab function c2d)
  41. */
  42. REAL_TYPE
  43. Vz_filter_100(REAL_TYPE Vz);
  44. REAL_TYPE
  45. Vz_filter_50 (REAL_TYPE Vz);
  46. REAL_TYPE
  47. Vz_filter_33 (REAL_TYPE Vz);
  48. REAL_TYPE
  49. Vz_filter_25 (REAL_TYPE Vz);
  50. /**
  51. * q filter (100/50/33/25 Hz --> 10/20/30/40 ms period)
  52. * @param[in] q, pitch rate (rad/s)
  53. * @return q_f, filtered pitch rate (rad/s)
  54. * 2nd order Butterworth filter with fc = 3.0 Hz (Matlab function butter)
  55. * Discretized with Zero-order Hold method with Ts = 0.01/0.02/0.03/0.04 (Matlab function c2d)
  56. */
  57. REAL_TYPE
  58. q_filter_100(REAL_TYPE q);
  59. REAL_TYPE
  60. q_filter_50 (REAL_TYPE q);
  61. REAL_TYPE
  62. q_filter_33 (REAL_TYPE q);
  63. REAL_TYPE
  64. q_filter_25 (REAL_TYPE q);
  65. /**
  66. * az filter (100/50/33/25 Hz --> 10/20/30/40 ms period)
  67. * @param[in] az, normal acceleration (m/s^2)
  68. * @return az_f, filtered normal acceleration (m/s^2)
  69. * 2nd order Butterworth filter with fc = 10.0 Hz (Matlab function butter)
  70. * Discretized with Zero-order Hold method with Ts = 0.01/0.02/0.03/0.04 (Matlab function c2d)
  71. */
  72. REAL_TYPE
  73. az_filter_100(REAL_TYPE az);
  74. REAL_TYPE
  75. az_filter_50 (REAL_TYPE az);
  76. REAL_TYPE
  77. az_filter_33 (REAL_TYPE az);
  78. REAL_TYPE
  79. az_filter_25 (REAL_TYPE az);
  80. /**
  81. * h filter (100/50/33/25 Hz --> 10/20/30/40 ms period)
  82. * @param[in] h, altitude (m)
  83. * @return h_f, filtered altitude (m)
  84. * 2nd order Butterworth filter with fc = 3.0 Hz (Matlab function butter)
  85. * Discretized with Zero-order Hold method with Ts = 0.01/0.02/0.03/0.04 (Matlab function c2d)
  86. */
  87. REAL_TYPE
  88. h_filter_100(REAL_TYPE h);
  89. REAL_TYPE
  90. h_filter_50 (REAL_TYPE h);
  91. REAL_TYPE
  92. h_filter_33 (REAL_TYPE h);
  93. REAL_TYPE
  94. h_filter_25 (REAL_TYPE h);
  95. /**
  96. * Altitude hold controller (rate 50/33/25/10 Hz sampling period 0.02/0.03/0.04/0.1)
  97. * @param[in] h_f, filtered altitude (m)
  98. * @param[in] h_c, commanded altitude (m)
  99. * @return Vz_c, commanded vertical speed (m/s)
  100. * Generates the vertical speed command Vz_c to track altitude change h_c
  101. */
  102. REAL_TYPE
  103. altitude_hold_50 (REAL_TYPE h_f, REAL_TYPE h_c);
  104. REAL_TYPE
  105. altitude_hold_33 (REAL_TYPE h_f, REAL_TYPE h_c);
  106. REAL_TYPE
  107. altitude_hold_25 (REAL_TYPE h_f, REAL_TYPE h_c);
  108. REAL_TYPE
  109. altitude_hold_10 (REAL_TYPE h_f, REAL_TYPE h_c);
  110. /**
  111. * Vz Speed controller (rate 50/33/25/10 Hz sampling period 0.02/0.03/0.04/0.1)
  112. * @param[in] Vz_f, filtered vertical speed (m/s)
  113. * @param[in] Vz_c, commanded vertical speed (m/s)
  114. * @param[in] q_f, filtered pitch rate (rad/s)
  115. * @param[in] az_f, filtered normal acceleration (m/s^2)
  116. * @return delta_e_c, commanded elevator deflection (rad)
  117. * Generates the elevator deflection command to track vertical speed command Vz_c
  118. */
  119. REAL_TYPE
  120. Vz_control_50 (REAL_TYPE Vz_f, REAL_TYPE Vz_c, REAL_TYPE q_f, REAL_TYPE az_f);
  121. REAL_TYPE
  122. Vz_control_33 (REAL_TYPE Vz_f, REAL_TYPE Vz_c, REAL_TYPE q_f, REAL_TYPE az_f);
  123. REAL_TYPE
  124. Vz_control_25 (REAL_TYPE Vz_f, REAL_TYPE Vz_c, REAL_TYPE q_f, REAL_TYPE az_f);
  125. REAL_TYPE
  126. Vz_control_10 (REAL_TYPE Vz_f, REAL_TYPE Vz_c, REAL_TYPE q_f, REAL_TYPE az_f);
  127. /**
  128. * Va Speed controller (rate 50/33/25/10 Hz sampling period 0.02/0.03/0.04/0.1)
  129. * @param[in] Va_f, filtered airspeed (m/s)
  130. * @param[in] Vz_f, filtered vertical speed (m/s)
  131. * @param[in] q_f, filtered pitch rate (rad/s)
  132. * @return delta_th_c, commanded throttle (-)
  133. * Generates the throttle command to track airspeed change Va_c
  134. */
  135. REAL_TYPE
  136. Va_control_50 (REAL_TYPE Va_f, REAL_TYPE Vz_f, REAL_TYPE q_f, REAL_TYPE Va_c);
  137. REAL_TYPE
  138. Va_control_33 (REAL_TYPE Va_f, REAL_TYPE Vz_f, REAL_TYPE q_f, REAL_TYPE Va_c);
  139. REAL_TYPE
  140. Va_control_25 (REAL_TYPE Va_f, REAL_TYPE Vz_f, REAL_TYPE q_f, REAL_TYPE Va_c);
  141. REAL_TYPE
  142. Va_control_10 (REAL_TYPE Va_f, REAL_TYPE Vz_f, REAL_TYPE q_f, REAL_TYPE Va_c);
  143. /**
  144. * Engine (200 Hz --> 5ms period)
  145. * @param[in] delta_th_c, commanded throttle (-)
  146. * @return T, Thrust (N)
  147. * 1st order system with time constant 0.5 s
  148. * ODE Solver: Euler method with fixed-step = 0.005 (200 Hz)
  149. */
  150. REAL_TYPE
  151. engine(REAL_TYPE delta_th_c);
  152. /**
  153. * Elevator (200 Hz --> 5ms period)
  154. * @param[in] delta_e_c, commanded elevator deflection (rad)
  155. * @return delta_e, elevator deflection (rad)
  156. * 2nd order system (natural frequency omega = 25.0 rad/s and damping xi = 0.85)
  157. * ODE Solver: Euler method with fixed-step = 0.005 s (200 Hz)
  158. */
  159. REAL_TYPE
  160. elevator(REAL_TYPE delta_e_c);
  161. /**
  162. * Flight dynamics (200 Hz --> 5ms period)
  163. * @param[in] i, the simulation step
  164. * @param[in] delta_e, elevator deflection (rad)
  165. * @param[in] T, Thrust (N)
  166. * @param[out] outputs, the outputs Va, Vz, q, az, h
  167. * Aircraft flight dynamics
  168. * ODE Solver: Euler method with fixed-step = 0.005 s (200 Hz)
  169. */
  170. void
  171. aircraft_dynamics (REAL_TYPE delta_e, REAL_TYPE T, struct aircraft_dynamics_outs_t *outputs);
  172. /* ***************************************************************************
  173. * The prelude sensor node prototypes
  174. * ************************************************************************* */
  175. /**
  176. * (200 Hz --> 5ms period)
  177. */
  178. REAL_TYPE
  179. input_h_c();
  180. REAL_TYPE
  181. input_Va_c();
  182. /* ***************************************************************************
  183. * The prelude actuator node prototypes
  184. * ************************************************************************* */
  185. /**
  186. * (200 Hz --> 5ms period)
  187. */
  188. void
  189. output_delta_th_c(REAL_TYPE delta_th_c);
  190. /**
  191. * (200 Hz --> 5ms period)
  192. */
  193. void
  194. output_delta_e_c(REAL_TYPE delta_e_c);
  195. #endif