SIM_Plane.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. simple plane simulator class
  15. */
  16. #pragma once
  17. #include "SIM_Aircraft.h"
  18. #include "SIM_ICEngine.h"
  19. #include <Filter/LowPassFilter.h>
  20. namespace SITL {
  21. /*
  22. a very simple plane simulator
  23. */
  24. class Plane : public Aircraft {
  25. public:
  26. Plane(const char *frame_str);
  27. /* update model by one time step */
  28. virtual void update(const struct sitl_input &input) override;
  29. /* static object creator */
  30. static Aircraft *create(const char *frame_str) {
  31. return new Plane(frame_str);
  32. }
  33. protected:
  34. const float hover_throttle = 0.7f;
  35. const float air_density = 1.225; // kg/m^3 at sea level, ISA conditions
  36. float angle_of_attack;
  37. float beta;
  38. struct {
  39. // from last_letter skywalker_2013/aerodynamics.yaml
  40. // thanks to Georacer!
  41. float s = 0.45;
  42. float b = 1.88;
  43. float c = 0.24;
  44. float c_lift_0 = 0.56;
  45. float c_lift_deltae = 0;
  46. float c_lift_a = 6.9;
  47. float c_lift_q = 0;
  48. float mcoeff = 50;
  49. float oswald = 0.9;
  50. float alpha_stall = 0.4712;
  51. float c_drag_q = 0;
  52. float c_drag_deltae = 0.0;
  53. float c_drag_p = 0.1;
  54. float c_y_0 = 0;
  55. float c_y_b = -0.98;
  56. float c_y_p = 0;
  57. float c_y_r = 0;
  58. float c_y_deltaa = 0;
  59. float c_y_deltar = -0.2;
  60. float c_l_0 = 0;
  61. float c_l_p = -1.0;
  62. float c_l_b = -0.12;
  63. float c_l_r = 0.14;
  64. float c_l_deltaa = 0.25;
  65. float c_l_deltar = -0.037;
  66. float c_m_0 = 0.045;
  67. float c_m_a = -0.7;
  68. float c_m_q = -20;
  69. float c_m_deltae = 1.0;
  70. float c_n_0 = 0;
  71. float c_n_b = 0.25;
  72. float c_n_p = 0.022;
  73. float c_n_r = -1;
  74. float c_n_deltaa = 0.00;
  75. float c_n_deltar = 0.1;
  76. float deltaa_max = 0.3491;
  77. float deltae_max = 0.3491;
  78. float deltar_max = 0.3491;
  79. // the X CoG offset should be -0.02, but that makes the plane too tail heavy
  80. // in manual flight. Adjusted to -0.15 gives reasonable flight
  81. Vector3f CGOffset{-0.15, 0, -0.05};
  82. } coefficient;
  83. float thrust_scale;
  84. bool reverse_thrust;
  85. bool elevons;
  86. bool vtail;
  87. bool dspoilers;
  88. bool reverse_elevator_rudder;
  89. bool ice_engine;
  90. bool tailsitter;
  91. bool have_launcher;
  92. float launch_accel;
  93. float launch_time;
  94. uint64_t launch_start_ms;
  95. const uint8_t throttle_servo = 2;
  96. const int8_t choke_servo = 14;
  97. const int8_t ignition_servo = 12;
  98. const int8_t starter_servo = 13;
  99. const float slewrate = 100;
  100. ICEngine icengine{
  101. throttle_servo,
  102. choke_servo,
  103. ignition_servo,
  104. starter_servo,
  105. slewrate
  106. };
  107. float liftCoeff(float alpha) const;
  108. float dragCoeff(float alpha) const;
  109. Vector3f getForce(float inputAileron, float inputElevator, float inputRudder) const;
  110. Vector3f getTorque(float inputAileron, float inputElevator, float inputRudder, float inputThrust, const Vector3f &force) const;
  111. void calculate_forces(const struct sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel);
  112. };
  113. } // namespace SITL