MAV'RIC
|
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 attitude_controller.hpp 00034 * 00035 * \author MAV'RIC Team 00036 * \author Julien Lecoeur 00037 * \author Basil Huber 00038 * 00039 * \brief A controller for attitude control 00040 * 00041 * \details It takes a command in attitude (roll/pitch/yaw or quaternion) as 00042 * input, and computes a torque command on roll pitch and yaw. 00043 * The inner PID loop controls the angular speed around the 3 axis. This inner 00044 * loop is fed by the outer PID loop which controls the attitude. 00045 * The error of the outer loop is computed using quaternion arithmetic, and thus 00046 * avoids gimbal locks as long as the attitude error is smaller than 90 degrees 00047 * on the pitch axis. 00048 * 00049 ******************************************************************************/ 00050 00051 00052 #ifndef ATTITUDE_CONTROLLER_HPP_ 00053 #define ATTITUDE_CONTROLLER_HPP_ 00054 00055 #include "control/attitude_error_estimator.hpp" 00056 #include "control/pid_controller.hpp" 00057 #include "sensing/ahrs.hpp" 00058 #include "util/constants.hpp" 00059 #include "control/control_command.hpp" 00060 #include "control/controller.hpp" 00061 00062 00063 class Attitude_controller : public Controller<attitude_command_t, rate_command_t> 00064 { 00065 public: 00066 00070 struct conf_t 00071 { 00072 pid_controller_conf_t pid_config[3]; 00073 }; 00074 00075 00081 static inline conf_t default_config(); 00082 00083 00087 struct args_t 00088 { 00089 const AHRS& ahrs; 00090 attitude_command_t& attitude_command; 00091 rate_command_t& rate_command; 00092 }; 00093 00094 00101 Attitude_controller(const args_t& args, const conf_t& config = default_config()); 00102 00103 00109 bool update(); 00110 00111 00119 bool set_command(const attitude_command_t& command); 00120 00121 00129 bool get_command(attitude_command_t& command) const; 00130 00131 00139 bool get_output(rate_command_t& command) const; 00140 00141 00147 pid_controller_t& get_pid_X(void); 00148 pid_controller_t& get_pid_Y(void); 00149 pid_controller_t& get_pid_Z(void); 00150 00151 00152 protected: 00153 const AHRS& ahrs_; 00154 attitude_command_t& attitude_command_; 00155 rate_command_t& rate_command_; 00156 00157 attitude_error_estimator_t attitude_error_estimator_; 00158 pid_controller_t pid_[3]; 00159 float dt_s_; 00160 float last_update_s_; 00161 }; 00162 00163 00164 Attitude_controller::conf_t Attitude_controller::default_config() 00165 { 00166 conf_t conf = {}; 00167 00168 // ----------------------------------------------------------------- 00169 // ------ ROLL ANGLE PID ------------------------------------------- 00170 // ----------------------------------------------------------------- 00171 conf.pid_config[ROLL] = {}; 00172 conf.pid_config[ROLL].p_gain = 4.0f; 00173 conf.pid_config[ROLL].clip_min = -12.0f; 00174 conf.pid_config[ROLL].clip_max = 12.0f; 00175 conf.pid_config[ROLL].integrator = {}; 00176 conf.pid_config[ROLL].integrator.gain = 0.0f; 00177 conf.pid_config[ROLL].integrator.clip_pre = 0.0f; 00178 conf.pid_config[ROLL].integrator.clip = 0.0f; 00179 conf.pid_config[ROLL].differentiator = {}; 00180 conf.pid_config[ROLL].differentiator.gain = 0.0f; 00181 conf.pid_config[ROLL].differentiator.clip = 0.0f; 00182 conf.pid_config[ROLL].soft_zone_width = 0.0f; 00183 // ----------------------------------------------------------------- 00184 // ------ PITCH ANGLE PID ------------------------------------------ 00185 // ----------------------------------------------------------------- 00186 conf.pid_config[PITCH] = {}; 00187 conf.pid_config[PITCH].p_gain = 4.0f; 00188 conf.pid_config[PITCH].clip_min = -12.0f; 00189 conf.pid_config[PITCH].clip_max = 12.0f; 00190 conf.pid_config[PITCH].integrator = {}; 00191 conf.pid_config[PITCH].integrator.gain = 0.0f; 00192 conf.pid_config[PITCH].integrator.clip_pre = 0.0f; 00193 conf.pid_config[PITCH].integrator.clip = 0.0f; 00194 conf.pid_config[PITCH].differentiator = {}; 00195 conf.pid_config[PITCH].differentiator.gain = 0.0f; 00196 conf.pid_config[PITCH].differentiator.clip = 0.0f; 00197 conf.pid_config[PITCH].soft_zone_width = 0.0f; 00198 // ----------------------------------------------------------------- 00199 // ------ YAW ANGLE PID -------------------------------------------- 00200 // ----------------------------------------------------------------- 00201 conf.pid_config[YAW] = {}; 00202 conf.pid_config[YAW].p_gain = 3.0f; 00203 conf.pid_config[YAW].clip_min = -1.5f; 00204 conf.pid_config[YAW].clip_max = 1.5f; 00205 conf.pid_config[YAW].integrator = {}; 00206 conf.pid_config[YAW].integrator.gain = 0.0f; 00207 conf.pid_config[YAW].integrator.clip_pre = 0.0f; 00208 conf.pid_config[YAW].integrator.clip = 0.0f; 00209 conf.pid_config[YAW].differentiator = {}; 00210 conf.pid_config[YAW].differentiator.gain = 0.0f; 00211 conf.pid_config[YAW].differentiator.clip = 0.0f; 00212 conf.pid_config[YAW].soft_zone_width = 0.0f; 00213 00214 return conf; 00215 }; 00216 00217 #endif /* ATTITUDE_CONTROLLER_HPP_ */