2015-06-13 07:07:25 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
balloon simulator class
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SIM_Balloon.h"
|
2015-10-22 10:58:33 -03:00
|
|
|
|
2015-06-13 07:07:25 -03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-10-22 10:04:42 -03:00
|
|
|
namespace SITL {
|
|
|
|
|
2019-08-15 01:01:24 -03:00
|
|
|
Balloon::Balloon(const char *frame_str) :
|
|
|
|
Aircraft(frame_str)
|
2015-06-13 07:07:25 -03:00
|
|
|
{
|
|
|
|
mass = 5.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
update the balloon simulation by one time step
|
|
|
|
*/
|
|
|
|
void Balloon::update(const struct sitl_input &input)
|
|
|
|
{
|
2016-04-19 22:48:37 -03:00
|
|
|
// get wind vector setup
|
|
|
|
update_wind(input);
|
|
|
|
|
2015-06-13 07:07:25 -03:00
|
|
|
if (!released && input.servos[6] > 1800) {
|
|
|
|
::printf("Balloon released\n");
|
|
|
|
released = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!burst && input.servos[7] > 1800) {
|
|
|
|
::printf("Balloon burst\n");
|
|
|
|
burst = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rotational air resistance
|
|
|
|
Vector3f rot_accel = -gyro * radians(400) / terminal_rotation_rate;
|
|
|
|
|
|
|
|
// air resistance
|
2016-04-19 22:48:37 -03:00
|
|
|
Vector3f air_resistance = -velocity_air_ef * (GRAVITY_MSS/terminal_velocity);
|
2015-06-13 07:07:25 -03:00
|
|
|
|
|
|
|
float lift_accel = 0;
|
|
|
|
if (!burst && released) {
|
|
|
|
float air_resistance_at_climb_rate = climb_rate * (GRAVITY_MSS/terminal_velocity);
|
|
|
|
lift_accel = air_resistance_at_climb_rate + GRAVITY_MSS * dcm.c.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
accel_body = Vector3f(0, 0, -lift_accel);
|
2016-05-26 07:38:20 -03:00
|
|
|
accel_body += dcm.transposed() * air_resistance;
|
2016-01-01 00:11:55 -04:00
|
|
|
|
|
|
|
update_dynamics(rot_accel);
|
2015-06-13 07:07:25 -03:00
|
|
|
|
|
|
|
if (position.z < -burst_altitude) {
|
|
|
|
::printf("Balloon burst at %.1f\n", -position.z);
|
|
|
|
burst = true;
|
|
|
|
}
|
2016-01-01 00:11:55 -04:00
|
|
|
|
2015-06-13 07:07:25 -03:00
|
|
|
// update lat/lon/altitude
|
|
|
|
update_position();
|
2017-03-03 06:23:40 -04:00
|
|
|
time_advance();
|
2016-06-17 00:46:12 -03:00
|
|
|
|
|
|
|
// update magnetic field
|
|
|
|
update_mag_field_bf();
|
2015-06-13 07:07:25 -03:00
|
|
|
}
|
2015-10-22 10:04:42 -03:00
|
|
|
|
|
|
|
} // namespace SITL
|