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 : sailboat simulator class
17 : */
18 :
19 : #pragma once
20 :
21 : #include "SIM_Aircraft.h"
22 :
23 : namespace SITL {
24 :
25 : /*
26 : a sailboat simulator
27 : */
28 : class Sailboat : public Aircraft {
29 : public:
30 : Sailboat(const char *frame_str);
31 :
32 : /* update model by one time step */
33 : void update(const struct sitl_input &input) override;
34 :
35 : /* static object creator */
36 4 : static Aircraft *create(const char *frame_str) {
37 4 : return NEW_NOTHROW Sailboat(frame_str);
38 : }
39 :
40 0 : bool on_ground() const override {return true;};
41 :
42 : protected:
43 : bool motor_connected; // true if this frame has a motor
44 : bool skid_steering; // true if this vehicle is a skid-steering vehicle
45 : float sail_area; // 1.0 for normal area
46 :
47 : private:
48 :
49 : // 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
50 : void calc_lift_and_drag(float wind_speed, float angle_of_attack_deg, float& lift, float& drag) const;
51 :
52 : // return turning circle (diameter) in meters for steering angle proportion in the range -1 to +1
53 : float get_turn_circle(float steering) const;
54 :
55 : // return yaw rate in deg/sec given a steering input (in the range -1 to +1) and speed in m/s
56 : float get_yaw_rate(float steering, float speed) const;
57 :
58 : // return lateral acceleration in m/s/s given a steering input (in the range -1 to +1) and speed in m/s
59 : float get_lat_accel(float steering, float speed) const;
60 :
61 : // simulate waves and swell
62 : void update_wave(float delta_time);
63 :
64 : float steering_angle_max; // vehicle steering mechanism's max angle in degrees
65 : float turning_circle; // vehicle minimum turning circle diameter in meters
66 :
67 : // lift and drag curves. index is angle/10deg
68 : // angle-of-attack 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170+
69 : 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};
70 : 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};
71 :
72 : const float mass = 2.0f;
73 :
74 : Vector3f velocity_ef_water; // m/s
75 : Vector3f wave_gyro; // rad/s
76 : float wave_heave; // m/s/s
77 : float wave_phase; // rads
78 : };
79 :
80 : } // namespace SITL
|