SIM_Sailboat.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. sailboat simulator class
  15. */
  16. #pragma once
  17. #include "SIM_Aircraft.h"
  18. namespace SITL {
  19. /*
  20. a sailboat simulator
  21. */
  22. class Sailboat : public Aircraft {
  23. public:
  24. Sailboat(const char *frame_str);
  25. /* update model by one time step */
  26. void update(const struct sitl_input &input) override;
  27. /* static object creator */
  28. static Aircraft *create(const char *frame_str) {
  29. return new Sailboat(frame_str);
  30. }
  31. bool on_ground() const override {return true;};
  32. private:
  33. // calculate the lift and drag as values from 0 to 1 given an apparent wind speed in m/s and angle-of-attack in degrees
  34. void calc_lift_and_drag(float wind_speed, float angle_of_attack_deg, float& lift, float& drag) const;
  35. // return turning circle (diameter) in meters for steering angle proportion in the range -1 to +1
  36. float get_turn_circle(float steering) const;
  37. // return yaw rate in deg/sec given a steering input (in the range -1 to +1) and speed in m/s
  38. float get_yaw_rate(float steering, float speed) const;
  39. // return lateral acceleration in m/s/s given a steering input (in the range -1 to +1) and speed in m/s
  40. float get_lat_accel(float steering, float speed) const;
  41. // simulate waves and swell
  42. void update_wave(float delta_time);
  43. float steering_angle_max; // vehicle steering mechanism's max angle in degrees
  44. float turning_circle; // vehicle minimum turning circle diameter in meters
  45. // lift and drag curves. index is angle/10deg
  46. // angle-of-attack 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170+
  47. const float lift_curve[18] = {0.00f, 0.50f, 1.00f, 1.10f, 0.95f, 0.75f, 0.60f, 0.40f, 0.20f, 0.00f, -0.20f, -0.40f, -0.60f, -0.75f, -0.95f, -1.10f, -1.00f, -0.50f};
  48. const float drag_curve[18] = {0.10f, 0.10f, 0.20f, 0.40f, 0.80f, 1.20f, 1.50f, 1.70f, 1.90f, 1.95f, 1.90f, 1.70f, 1.50f, 1.20f, 0.80f, 0.40f, 0.20f, 0.10f};
  49. const float mass = 2.0f;
  50. Vector3f velocity_ef_water; // m/s
  51. Vector3f wave_gyro; // rad/s
  52. float wave_heave; // m/s/s
  53. float wave_phase; // rads
  54. bool motor_connected; // true if this frame has a motor
  55. };
  56. } // namespace SITL