SIM_Balloon.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. balloon simulator class
  15. */
  16. #include "SIM_Balloon.h"
  17. #include <stdio.h>
  18. namespace SITL {
  19. Balloon::Balloon(const char *frame_str) :
  20. Aircraft(frame_str)
  21. {
  22. mass = 5.0f;
  23. }
  24. /*
  25. update the balloon simulation by one time step
  26. */
  27. void Balloon::update(const struct sitl_input &input)
  28. {
  29. // get wind vector setup
  30. update_wind(input);
  31. if (!released && input.servos[6] > 1800) {
  32. ::printf("Balloon released\n");
  33. released = true;
  34. }
  35. if (!burst && input.servos[7] > 1800) {
  36. ::printf("Balloon burst\n");
  37. burst = true;
  38. }
  39. // rotational air resistance
  40. Vector3f rot_accel = -gyro * radians(400) / terminal_rotation_rate;
  41. // air resistance
  42. Vector3f air_resistance = -velocity_air_ef * (GRAVITY_MSS/terminal_velocity);
  43. float lift_accel = 0;
  44. if (!burst && released) {
  45. float air_resistance_at_climb_rate = climb_rate * (GRAVITY_MSS/terminal_velocity);
  46. lift_accel = air_resistance_at_climb_rate + GRAVITY_MSS * dcm.c.z;
  47. }
  48. accel_body = Vector3f(0, 0, -lift_accel);
  49. accel_body += dcm.transposed() * air_resistance;
  50. update_dynamics(rot_accel);
  51. if (position.z < -burst_altitude) {
  52. ::printf("Balloon burst at %.1f\n", -position.z);
  53. burst = true;
  54. }
  55. // update lat/lon/altitude
  56. update_position();
  57. time_advance();
  58. // update magnetic field
  59. update_mag_field_bf();
  60. }
  61. } // namespace SITL