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 : ROV/AUV/Blimp simulator class 17 : */ 18 : 19 : #pragma once 20 : 21 : #include "SIM_Aircraft.h" 22 : // #include "SIM_Motor.h" 23 : // #include "SIM_Frame.h" 24 : 25 : namespace SITL { 26 : 27 : struct Fins 28 : { 29 : float angle; 30 : float last_angle; 31 : float servo_angle; 32 : bool dir; 33 : float vel; // ang velocity, in deg/s 34 : float T; //Tangential (thrust) force, in Neutons 35 : float N; //Normal force, in Newtons 36 : float Fx; //Fx,y,z = Force in bodyframe orientation at servo position, in Newtons 37 : float Fy; 38 : float Fz; 39 : }; 40 : 41 : struct Motors 42 : { 43 : float throttle; 44 : float thrust; 45 : float Fx; //Fx,y,z = Force in bodyframe orientation at servo position, in Newtons 46 : float Fy; 47 : float Fz; 48 : }; 49 : 50 : /* 51 : a blimp simulator 52 : */ 53 : 54 : class Blimp : public Aircraft { 55 : public: 56 : Blimp(const char *frame_str); 57 : 58 : /* update model by one time step */ 59 : void update(const struct sitl_input &input) override; 60 : 61 : /* static object creator */ 62 0 : static Aircraft *create(const char *frame_str) { 63 0 : return NEW_NOTHROW Blimp(frame_str); 64 : } 65 : 66 : protected: 67 : float mass; //kilograms 68 : float radius; //metres 69 : Vector3f moment_of_inertia; 70 : Vector3f cog; //centre of gravity location relative to center of blimp 71 : 72 : //Airfish-specific variables 73 : Fins fin[4]; 74 : Motors mot[4]; 75 : float gondolawidth; 76 : float k_tan; //Tangential and normal force multipliers 77 : float k_nor; 78 : float k_m; 79 : float drag_constant; 80 : float drag_gyr_constant; 81 : float drag_lin_constant; 82 : float drag_gyr_lin_constant; 83 : 84 : bool motorblimp = false; 85 : 86 : void calculate_forces(const struct sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel); 87 : void update_battery() override; 88 0 : bool battery_is_empty() { return battery_voltage < 0.5f; }; 89 0 : float sq(float a) {return powf(a,2);} 90 : }; 91 : 92 : }