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 : helicopter simulator class 17 : */ 18 : 19 : #pragma once 20 : 21 : #include "SIM_Aircraft.h" 22 : 23 : namespace SITL { 24 : 25 : /* 26 : a helicopter simulator 27 : */ 28 : class Helicopter : public Aircraft { 29 : public: 30 : Helicopter(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 80 : static Aircraft *create(const char *frame_str) { 37 80 : return NEW_NOTHROW Helicopter(frame_str); 38 : } 39 : 40 : protected: 41 : 42 : void update_rotor_dynamics(Vector3f gyros, Vector2f ctrl_pos, Vector2f &tpp_angle, float dt); 43 : float update_rpm(float curr_rpm, float throttle, float &engine_torque, float collective, float dt); 44 : 45 : // buffers to provide time delay 46 : struct servos_stored { 47 : uint16_t servo1; 48 : uint16_t servo2; 49 : uint16_t servo3; 50 : uint16_t servo4; 51 : uint16_t servo5; 52 : uint16_t servo6; 53 : }; 54 : uint16_t _servos_delayed[6]; 55 : ObjectBuffer<servos_stored> *servos_stored_buffer; 56 : void push_to_buffer(const uint16_t servos_input[16]); 57 : void pull_from_buffer(uint16_t servos_delayed[6]); 58 : 59 : 60 : private: 61 : float terminal_rotation_rate = 4*radians(360.0f); 62 : float hover_lean = 3.2f; 63 : float rotor_rot_accel = radians(20); 64 : float roll_rate_max = radians(1400); 65 : float pitch_rate_max = radians(1400); 66 : float yaw_rate_max = radians(1400); 67 : float izz = 0.2f; 68 : float iyy; 69 : float tr_dist = 0.85f; 70 : float cyclic_scalar = 7.2; // converts swashplate servo ouputs to cyclic blade pitch 71 : float thrust_scale; 72 : Vector2f _tpp_angle; 73 : Vector2f _tpp_angle_1; 74 : Vector2f _tpp_angle_2; 75 : float torque_scale; 76 : float torque_mpog; 77 : float torque_max; 78 : float hover_coll = 5.0f; 79 : bool motor_interlock; 80 : uint8_t _time_delay; 81 : enum frame_types { 82 : HELI_FRAME_CONVENTIONAL, 83 : HELI_FRAME_CONVENTIONAL_DDVPTAIL, 84 : HELI_FRAME_CONVENTIONAL_DDFPTAIL, 85 : HELI_FRAME_DUAL, 86 : HELI_FRAME_COMPOUND, 87 : HELI_FRAME_BLADE360, 88 : } frame_type = HELI_FRAME_CONVENTIONAL; 89 : bool gas_heli = false; 90 : float nominal_rpm; 91 : 92 : // sets power consumption of the helicopter in watts while rotors turning 93 : float power_consumption_watts; 94 : // battery resistance reference value in Ohms 95 : float default_battery_resistance_ohm = 0.01; 96 : void update_battery() override; 97 9075634 : bool battery_is_empty() { return battery_voltage < 0.5f; }; 98 : 99 : }; 100 : 101 : } // namespace SITL