MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/simulation/dynamic_model_quad_diag.hpp
00001 /*******************************************************************************
00002  * Copyright (c) 2009-2016, MAV'RIC Development Team
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  * this list of conditions and the following disclaimer in the documentation
00013  * and/or other materials provided with the distribution.
00014  *
00015  * 3. Neither the name of the copyright holder nor the names of its contributors
00016  * may be used to endorse or promote products derived from this software without
00017  * specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  ******************************************************************************/
00031 
00032 /*******************************************************************************
00033  * \file dynamic_model_quad_diag.hpp
00034  *
00035  * \author MAV'RIC Team
00036  * \author Julien Lecoeur
00037  *
00038  * \brief Simulated dynamics of a quadcopter in diag configuration
00039  *
00040  ******************************************************************************/
00041 
00042 
00043 #ifndef DYNAMIC_MODEL_QUAD_DIAG_HPP_
00044 #define DYNAMIC_MODEL_QUAD_DIAG_HPP_
00045 
00046 
00047 #include "simulation/dynamic_model.hpp"
00048 #include "drivers/servo.hpp"
00049 #include "util/constants.hpp"
00050 
00054 typedef struct
00055 {
00056     float rotor_lpf;                    
00057     float rotor_rpm_gain;               
00058     float rotor_rpm_offset;             
00059 
00060     float rotor_cd;                     
00061     float rotor_cl;                     
00062     float rotor_diameter;               
00063     float rotor_foil_area;              
00064 
00065     float rotor_pitch;                  
00066     float total_mass;                   
00067     float vehicle_drag;                 
00068     float roll_pitch_momentum;          
00069     float yaw_momentum;                 
00070 
00071     float rotor_momentum;               
00072     float rotor_arm_length;             
00073 
00074     float wind_x;                       
00075     float wind_y;                       
00076 
00077     float gravity;                      
00078     float air_density;                  
00079 
00080     std::array<float,4> motor_dir;
00081 } dynamic_model_quad_diag_conf_t;
00082 
00083 
00089 static inline dynamic_model_quad_diag_conf_t dynamic_model_quad_diag_default_config();
00090 
00091 
00095 class Dynamic_model_quad_diag: public Dynamic_model
00096 {
00097 public:
00107     Dynamic_model_quad_diag(Servo& servo_rear_left,
00108                             Servo& servo_front_left,
00109                             Servo& servo_front_right,
00110                             Servo& servo_rear_right,
00111                             dynamic_model_quad_diag_conf_t config = dynamic_model_quad_diag_default_config());
00112 
00113 
00120     bool update(void);
00121 
00122 
00128     const float& last_update_us(void) const;
00129 
00130 
00136     const std::array<float, 3>& acceleration_bf(void) const;
00137 
00138 
00144     const std::array<float, 3>& velocity_lf(void) const;
00145 
00146 
00152     const local_position_t& position_lf(void) const;
00153 
00154 
00160     const global_position_t& position_gf(void) const;
00161 
00162 
00168     const std::array<float, 3>& angular_velocity_bf(void) const;
00169 
00170 
00176     const quat_t& attitude(void) const;
00177 
00178 private:
00179     Servo& servo_front_right_;              
00180     Servo& servo_front_left_;               
00181     Servo& servo_rear_right_;               
00182     Servo& servo_rear_left_;                
00183 
00184     dynamic_model_quad_diag_conf_t config_; 
00185 
00186     std::array<float, 4> rotorspeeds_;      
00187     std::array<float, 3> torques_bf_;       
00188     std::array<float, 3> rates_bf_;         
00189     std::array<float, 3> lin_forces_bf_;        
00190     std::array<float, 3> acc_bf_;           
00191     std::array<float, 3> vel_bf_;           
00192     std::array<float, 3> vel_;              
00193     quat_t attitude_;                       
00194 
00195     local_position_t local_position_;       
00196     global_position_t global_position_;     
00197 
00198     float last_update_us_;                  
00199     float dt_s_;                            
00200 
00201 
00205     void forces_from_servos(void);
00206 
00207 
00218     float lift_drag_base(float rpm, float sqr_lat_airspeed, float axial_airspeed);
00219 };
00220 
00221 
00222 
00223 static inline dynamic_model_quad_diag_conf_t dynamic_model_quad_diag_default_config()
00224 {
00225     dynamic_model_quad_diag_conf_t conf = {};
00226 
00227     conf.rotor_lpf              = 0.1f;                 
00228     conf.rotor_rpm_gain         = 4000.0f;              
00229     conf.rotor_rpm_offset       = -1.0f;                
00230     conf.rotor_cd               = 0.03f;                
00231     conf.rotor_cl               = 1.0f;                 
00232     conf.rotor_diameter         = 0.14f;                
00233     conf.rotor_foil_area        = 0.18f * 0.015f;       
00234     conf.rotor_pitch            = 0.15f;                
00235     conf.total_mass             = 0.35f;                
00236     conf.vehicle_drag           = 0.01f;                
00237     conf.roll_pitch_momentum    = 0.1f * 0.17f / 1.4142f;   
00238     conf.yaw_momentum           = 0.1f * 0.17f;         
00239     conf.rotor_momentum         = 0.005f * 0.03f;       
00240     conf.rotor_arm_length       = 0.17f;                
00241     conf.wind_x                 = 0.0f;                 
00242     conf.wind_y                 = 0.0f;                 
00243     conf.gravity                = 9.8f;                 
00244     conf.air_density            = 1.2f;                 
00245     conf.motor_dir              = std::array<float,4>{{-1.0f, 1.0f , -1.0f, 1.0f}};
00246 
00247     return conf;
00248 }
00249 
00250 
00251 #endif /* DYNAMIC_MODEL_QUAD_DIAG_HPP_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines