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