APM:Libraries
SIM_QuadPlane.cpp
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 quadplane simulator class
17 */
18 
19 #include "SIM_QuadPlane.h"
20 
21 #include <stdio.h>
22 
23 using namespace SITL;
24 
25 QuadPlane::QuadPlane(const char *home_str, const char *frame_str) :
26  Plane(home_str, frame_str)
27 {
28  // default to X frame
29  const char *frame_type = "x";
30  uint8_t motor_offset = 4;
31 
32  if (strstr(frame_str, "-octa-quad")) {
33  frame_type = "octa-quad";
34  } else if (strstr(frame_str, "-octaquad")) {
35  frame_type = "octa-quad";
36  } else if (strstr(frame_str, "-octa")) {
37  frame_type = "octa";
38  } else if (strstr(frame_str, "-hexax")) {
39  frame_type = "hexax";
40  } else if (strstr(frame_str, "-hexa")) {
41  frame_type = "hexa";
42  } else if (strstr(frame_str, "-plus")) {
43  frame_type = "+";
44  } else if (strstr(frame_str, "-y6")) {
45  frame_type = "y6";
46  } else if (strstr(frame_str, "-tri")) {
47  frame_type = "tri";
48  } else if (strstr(frame_str, "-tilttrivec")) {
49  frame_type = "tilttrivec";
50  // fwd motor gives zero thrust
51  thrust_scale = 0;
52  } else if (strstr(frame_str, "-tilthvec")) {
53  frame_type = "tilthvec";
54  } else if (strstr(frame_str, "-tilttri")) {
55  frame_type = "tilttri";
56  // fwd motor gives zero thrust
57  thrust_scale = 0;
58  } else if (strstr(frame_str, "firefly")) {
59  frame_type = "firefly";
60  // elevon style surfaces
61  elevons = true;
62  // fwd motor gives zero thrust
63  thrust_scale = 0;
64  // vtol motors start at 2
65  motor_offset = 2;
66  } else if (strstr(frame_str, "cl84")) {
67  frame_type = "tilttri";
68  // fwd motor gives zero thrust
69  thrust_scale = 0;
70  }
71  frame = Frame::find_frame(frame_type);
72  if (frame == nullptr) {
73  printf("Failed to find frame '%s'\n", frame_type);
74  exit(1);
75  }
76 
77  if (strstr(frame_str, "cl84")) {
78  // setup retract servos at front
80  frame->motors[0].servo_rate = 7*60.0/90; // 7 seconds to change
82  frame->motors[1].servo_rate = 7*60.0/90; // 7 seconds to change
83  }
84 
85  // leave first 4 servos free for plane
86  frame->motor_offset = motor_offset;
87 
88  // we use zero terminal velocity to let the plane model handle the drag
89  frame->init(mass, 0.51, 0, 0);
90 
92 }
93 
94 /*
95  update the quadplane simulation by one time step
96  */
97 void QuadPlane::update(const struct sitl_input &input)
98 {
99  // get wind vector setup
100  update_wind(input);
101 
102  // first plane forces
103  Vector3f rot_accel;
104  calculate_forces(input, rot_accel, accel_body);
105 
106  // now quad forces
107  Vector3f quad_rot_accel;
108  Vector3f quad_accel_body;
109 
110  frame->calculate_forces(*this, input, quad_rot_accel, quad_accel_body);
111 
112  rot_accel += quad_rot_accel;
113  accel_body += quad_accel_body;
114 
115  update_dynamics(rot_accel);
116 
117  // update lat/lon/altitude
118  update_position();
119  time_advance();
120 
121  // update magnetic field
123 }
Vector3f accel_body
Definition: SIM_Aircraft.h:142
int printf(const char *fmt,...)
Definition: stdio.c:113
void update_wind(const struct sitl_input &input)
QuadPlane(const char *home_str, const char *frame_str)
void calculate_forces(const struct sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel)
Definition: SIM_Plane.cpp:250
float servo_rate
Definition: SIM_Motor.h:43
Motor * motors
Definition: SIM_Frame.h:33
void init(float mass, float hover_throttle, float terminal_velocity, float terminal_rotation_rate)
Definition: SIM_Frame.cpp:177
static Frame * find_frame(const char *name)
Definition: SIM_Frame.cpp:192
float thrust_scale
Definition: SIM_Plane.h:94
enum SITL::Motor::@208 servo_type
uint8_t motor_offset
Definition: SIM_Frame.h:57
void update(const struct sitl_input &input) override
void update_mag_field_bf(void)
void update_position(void)
void calculate_forces(const Aircraft &aircraft, const Aircraft::sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel)
Definition: SIM_Frame.cpp:204
void update_dynamics(const Vector3f &rot_accel)
bool elevons
Definition: SIM_Plane.h:96
enum SITL::Aircraft::@199 ground_behavior