Line data Source code
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 0 : Balloon::Balloon(const char *frame_str) : 26 0 : Aircraft(frame_str) 27 : { 28 0 : mass = 5.0f; 29 0 : } 30 : 31 : /* 32 : update the balloon simulation by one time step 33 : */ 34 0 : void Balloon::update(const struct sitl_input &input) 35 : { 36 : // get wind vector setup 37 0 : update_wind(input); 38 : 39 0 : if (!released && input.servos[6] > 1800) { 40 0 : ::printf("Balloon released\n"); 41 0 : released = true; 42 : } 43 : 44 0 : if (!burst && input.servos[7] > 1800) { 45 0 : ::printf("Balloon burst\n"); 46 0 : burst = true; 47 : } 48 : 49 : // rotational air resistance 50 0 : Vector3f rot_accel = -gyro * radians(400) / terminal_rotation_rate; 51 : 52 : // air resistance 53 0 : Vector3f air_resistance = -velocity_air_ef * (GRAVITY_MSS/terminal_velocity) / eas2tas; 54 : 55 0 : float lift_accel = 0; 56 0 : if (!burst && released) { 57 0 : float air_resistance_at_climb_rate = climb_rate * (GRAVITY_MSS/terminal_velocity); 58 0 : lift_accel = air_resistance_at_climb_rate + GRAVITY_MSS * dcm.c.z; 59 : } 60 : 61 0 : accel_body = Vector3f(0, 0, -lift_accel); 62 0 : accel_body += dcm.transposed() * air_resistance; 63 : 64 0 : update_dynamics(rot_accel); 65 : 66 0 : if (position.z < -burst_altitude) { 67 0 : ::printf("Balloon burst at %.1f\n", -position.z); 68 0 : burst = true; 69 : } 70 : 71 : // update lat/lon/altitude 72 0 : update_position(); 73 0 : time_advance(); 74 : 75 : // update magnetic field 76 0 : update_mag_field_bf(); 77 : 78 0 : update_battery(); 79 0 : } 80 : 81 : } // namespace SITL