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 position_controller.hpp 00034 * 00035 * \author MAV'RIC Team 00036 * \author Basil Huber 00037 * 00038 * \brief Implementation of position controller 00039 * 00040 ******************************************************************************/ 00041 00042 00043 #ifndef POSITION_CONTROLLER_HPP_ 00044 #define POSITION_CONTROLLER_HPP_ 00045 00046 #include "control/controller.hpp" 00047 #include "control/control_command.hpp" 00048 #include "control/pid_controller.hpp" 00049 #include "sensing/ahrs.hpp" 00050 #include "sensing/ins.hpp" 00051 00052 00053 class Position_controller : public Controller<position_command_t, velocity_command_t> 00054 { 00055 public: 00056 00060 struct conf_t 00061 { 00062 float cruise_speed; 00063 float cruise_dist; 00064 float max_climb_rate; 00065 float kp_yaw; 00066 pid_controller_conf_t pid_config; 00067 }; 00068 00069 00075 static inline conf_t default_config(); 00076 00077 00081 struct args_t 00082 { 00083 const AHRS& ahrs; 00084 const INS& ins; 00085 }; 00086 00087 00094 Position_controller(args_t args, const conf_t& config = default_config()); 00095 00096 00100 virtual bool update(); 00101 00102 00110 bool set_command(const position_command_t& pos); 00111 00112 00120 bool get_command(position_command_t& pos) const; 00121 00122 00130 bool get_output(velocity_command_t& vel) const; 00131 00132 00138 pid_controller_t& get_pid(void); 00139 00140 private: 00141 const INS& ins_; 00142 const AHRS& ahrs_; 00143 00144 position_command_t position_command_; 00145 velocity_command_t velocity_command_; 00146 00147 pid_controller_t pid_controller_; //< position pid controller 00148 float cruise_speed_; 00149 float cruise_dist_; 00150 float max_climb_rate_; 00151 float kp_yaw_; 00152 }; 00153 00154 00155 Position_controller::conf_t Position_controller::default_config() 00156 { 00157 conf_t conf; 00158 conf.cruise_speed = 3.0f; 00159 conf.cruise_dist = 10.0f; 00160 conf.max_climb_rate = 1.0f; 00161 conf.kp_yaw = 0.5f; 00162 00163 conf.pid_config.p_gain = 1.0f; 00164 conf.pid_config.clip_min = 0.0f; 00165 conf.pid_config.clip_max = 3.0f; 00166 conf.pid_config.integrator.gain = 0.0f; 00167 conf.pid_config.integrator.clip_pre = 0.0f; 00168 conf.pid_config.integrator.clip = 0.0f; 00169 conf.pid_config.differentiator.gain = 0.0f; 00170 conf.pid_config.differentiator.clip = 0.0f; 00171 conf.pid_config.soft_zone_width = 0.0f; 00172 00173 return conf; 00174 }; 00175 00176 00177 #endif /* POSITION_CONTROLLER_HPP_ */