MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/control/velocity_controller_copter.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 velocity_controller_copter.hpp
00034  *
00035  * \author MAV'RIC Team
00036  * \author Felix Schill
00037  * \author Nicolas Dousse
00038  * \author Julien Lecoeur
00039  * \author Basil Huber
00040  *
00041  * \brief A velocity controller for copters.
00042  *
00043  * \details It takes a velocity command as input and computes an attitude
00044  * command as output. It is best suited for a hovering UAV with the thrust along
00045  * its local -Z axis (like multicopters).
00046  *
00047  ******************************************************************************/
00048 
00049 
00050 #ifndef VELOCITY_CONTROLLER_COPTER_HPP_
00051 #define VELOCITY_CONTROLLER_COPTER_HPP_
00052 
00053 #include "control/velocity_controller.hpp"
00054 #include "control/pid_controller.hpp"
00055 #include "sensing/ahrs.hpp"
00056 #include "sensing/ins.hpp"
00057 
00061 class Velocity_controller_copter : public Velocity_controller
00062 {
00063 public:
00064 
00068     struct conf_t: public Velocity_controller::conf_t
00069     {
00070         float thrust_hover_point;
00071     };
00072 
00073 
00079     static inline conf_t default_config(void);
00080 
00081 
00085     struct args_t
00086     {
00087         Velocity_controller::args_t vel_args;
00088     };
00089 
00097     Velocity_controller_copter(const args_t& args, const conf_t& config = default_config());
00098 
00099 
00100 protected:
00101 
00111     virtual bool compute_attitude_and_thrust_from_desired_accel(const std::array<float,3>& accel_command,
00112                                                                 attitude_command_t& attitude_command,
00113                                                                 thrust_command_t& thrust_command);
00114 
00115     float thrust_hover_point_;        
00116 };
00117 
00118 
00119 Velocity_controller_copter::conf_t Velocity_controller_copter::default_config(void)
00120 {
00121     conf_t conf = {};
00122 
00123     conf.control_frame                         = LOCAL_FRAME;
00124     conf.thrust_hover_point                    = -0.52f;
00125 
00126     // -----------------------------------------------------------------
00127     // ------ X PID ----------------------------------------------------
00128     // -----------------------------------------------------------------
00129     conf.pid_config[X]                         = {};
00130     conf.pid_config[X].p_gain                  = 0.2f;
00131     conf.pid_config[X].clip_min                = -0.5f;
00132     conf.pid_config[X].clip_max                = 0.5f;
00133     conf.pid_config[X].integrator              = {};
00134     conf.pid_config[X].integrator.gain         = 0.0125f;
00135     conf.pid_config[X].integrator.clip_pre     = 0.1f;
00136     conf.pid_config[X].integrator.accumulator  = 0.0f;
00137     conf.pid_config[X].integrator.clip         = 0.5f;
00138     conf.pid_config[X].differentiator          = {};
00139     conf.pid_config[X].differentiator.gain     = 0.01f;
00140     conf.pid_config[X].differentiator.previous = 0.0f;
00141     conf.pid_config[X].differentiator.clip     = 1.0f;
00142     conf.pid_config[X].soft_zone_width         = 0.0f;
00143 
00144     // -----------------------------------------------------------------
00145     // ------ Y PID ----------------------------------------------------
00146     // -----------------------------------------------------------------
00147     conf.pid_config[Y]                         = {};
00148     conf.pid_config[Y].p_gain                  = 0.2f;
00149     conf.pid_config[Y].clip_min                = -0.5f;
00150     conf.pid_config[Y].clip_max                = 0.5f;
00151     conf.pid_config[Y].integrator              = {};
00152     conf.pid_config[Y].integrator.gain         = 0.0125f;
00153     conf.pid_config[Y].integrator.clip_pre     = 0.1f;
00154     conf.pid_config[Y].integrator.accumulator  = 0.0f;
00155     conf.pid_config[Y].integrator.clip         = 0.5f;
00156     conf.pid_config[Y].differentiator          = {};
00157     conf.pid_config[Y].differentiator.gain     = 0.01f;
00158     conf.pid_config[Y].differentiator.previous = 0.0f;
00159     conf.pid_config[Y].differentiator.clip     = 1.0f;
00160     conf.pid_config[Y].soft_zone_width         = 0.0f;
00161 
00162     // ---------------------------------------------------------------------
00163     // ------ Z PID --------------------------------------------------------
00164     // ---------------------------------------------------------------------
00165     conf.pid_config[Z]                         = {};
00166     conf.pid_config[Z].p_gain                  = 0.20f;
00167     conf.pid_config[Z].clip_min                = -1.0f;
00168     conf.pid_config[Z].clip_max                = 0.0f;
00169     conf.pid_config[Z].integrator              = {};
00170     conf.pid_config[Z].integrator.gain         = 0.01f;
00171     conf.pid_config[Z].integrator.clip_pre     = 2.0f;
00172     conf.pid_config[Z].integrator.accumulator  = 0.0f;
00173     conf.pid_config[Z].integrator.clip         = 0.3f;
00174     conf.pid_config[Z].differentiator          = {};
00175     conf.pid_config[Z].differentiator.gain     = 0.08f;
00176     conf.pid_config[Z].differentiator.previous = 0.0f;
00177     conf.pid_config[Z].differentiator.clip     = 0.04f;
00178     conf.pid_config[Z].soft_zone_width         = 0.2f;
00179 
00180     return conf;
00181 }
00182 
00183 #endif /* VELOCITY_CONTROLLER_COPTER_HPP_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines