2015-06-13 07:07:25 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*
|
|
|
|
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 {
|
|
|
|
|
2015-06-13 07:07:25 -03:00
|
|
|
Balloon::Balloon(const char *home_str, const char *frame_str) :
|
|
|
|
Aircraft(home_str, frame_str)
|
|
|
|
{
|
|
|
|
mass = 5.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
update the balloon simulation by one time step
|
|
|
|
*/
|
|
|
|
void Balloon::update(const struct sitl_input &input)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
Vector3f air_resistance = -velocity_ef * (GRAVITY_MSS/terminal_velocity);
|
|
|
|
|
|
|
|
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-01-01 00:11:55 -04:00
|
|
|
accel_body += dcm * air_resistance;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2015-10-22 10:04:42 -03:00
|
|
|
|
|
|
|
} // namespace SITL
|