APM:Libraries
SIM_Balloon.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  balloon simulator class
17 */
18 
19 #include "SIM_Balloon.h"
20 
21 #include <stdio.h>
22 
23 namespace SITL {
24 
25 Balloon::Balloon(const char *home_str, const char *frame_str) :
26  Aircraft(home_str, frame_str)
27 {
28  mass = 5.0f;
29 }
30 
31 /*
32  update the balloon simulation by one time step
33  */
34 void Balloon::update(const struct sitl_input &input)
35 {
36  // get wind vector setup
37  update_wind(input);
38 
39  if (!released && input.servos[6] > 1800) {
40  ::printf("Balloon released\n");
41  released = true;
42  }
43 
44  if (!burst && input.servos[7] > 1800) {
45  ::printf("Balloon burst\n");
46  burst = true;
47  }
48 
49  // rotational air resistance
50  Vector3f rot_accel = -gyro * radians(400) / terminal_rotation_rate;
51 
52  // air resistance
54 
55  float lift_accel = 0;
56  if (!burst && released) {
57  float air_resistance_at_climb_rate = climb_rate * (GRAVITY_MSS/terminal_velocity);
58  lift_accel = air_resistance_at_climb_rate + GRAVITY_MSS * dcm.c.z;
59  }
60 
61  accel_body = Vector3f(0, 0, -lift_accel);
62  accel_body += dcm.transposed() * air_resistance;
63 
64  update_dynamics(rot_accel);
65 
66  if (position.z < -burst_altitude) {
67  ::printf("Balloon burst at %.1f\n", -position.z);
68  burst = true;
69  }
70 
71  // update lat/lon/altitude
73  time_advance();
74 
75  // update magnetic field
77 }
78 
79 } // namespace SITL
Vector3f accel_body
Definition: SIM_Aircraft.h:142
int printf(const char *fmt,...)
Definition: stdio.c:113
Vector3f position
Definition: SIM_Aircraft.h:140
void update_wind(const struct sitl_input &input)
Vector3< float > Vector3f
Definition: vector3.h:246
float burst_altitude
Definition: SIM_Balloon.h:44
Vector3f velocity_air_ef
Definition: SIM_Aircraft.h:138
void update(const struct sitl_input &input)
Definition: SIM_Balloon.cpp:34
Matrix3< T > transposed(void) const
Definition: matrix3.cpp:189
#define GRAVITY_MSS
Definition: definitions.h:47
Vector3< T > c
Definition: matrix3.h:48
T z
Definition: vector3.h:67
float terminal_rotation_rate
Definition: SIM_Balloon.h:41
void update_mag_field_bf(void)
void update_position(void)
static constexpr float radians(float deg)
Definition: AP_Math.h:158
void update_dynamics(const Vector3f &rot_accel)
float terminal_velocity
Definition: SIM_Balloon.h:43
Balloon(const char *home_str, const char *frame_str)
Definition: SIM_Balloon.cpp:25
float climb_rate
Definition: SIM_Balloon.h:42