MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/navigation/navigation_directto.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 navigation_directto.hpp
00034  *
00035  * \author MAV'RIC Team
00036  * \author Basil Huber
00037  *
00038  * \brief   Navigation module allowing to navigated to goal position on direct trajectory
00039  * \details Inherits from Position_controller, which inherits from a Velocity_controller_I
00040  *          i.e. can take navigation, position and velocity commands
00041  *
00042  ******************************************************************************/
00043 
00044 
00045 #ifndef NAVIGATION_DIRECTTO_HPP_
00046 #define NAVIGATION_DIRECTTO_HPP_
00047 
00048 #include "navigation/navigation.hpp"
00049 #include "control/position_controller.hpp"
00050 
00051 
00052 class Navigation_directto : public Navigation
00053 {
00054     typedef position_command_t nav_command_t;
00055 public:
00056 
00060     struct conf_t
00061     {
00062         float min_cruise_dist_sqr;
00063         pid_controller_conf_t cruise_pid_config;
00064         pid_controller_conf_t hover_pid_config;
00065     };
00066 
00067     enum class ctrl_mode_t
00068     {
00069         POS_XYZ,        
00070         POS_XY_VEL_Z    
00071     };
00072 
00073 
00074     struct args_t
00075     {
00076         INS& ins;
00077     };
00078 
00079     Navigation_directto(args_t args, const conf_t& config = default_config());
00080 
00081 
00085     virtual bool update();
00086 
00094      bool set_navigation_command(const nav_command_t& command);
00095     bool set_goal(const nav_command_t& command);
00096 
00105     // virtual bool set_position_command(const pos_command_t& pos_command);
00106 
00116     // virtual bool set_xyposition_zvel_command(const typename TPosition_controller::xypos_zvel_command_t& command);
00117 
00118 
00125     inline float distance_to_goal_sqr() const {return distance_to_goal_sqr_;};
00126 
00132     static inline conf_t default_config();
00133 
00134 protected:
00135 
00136     pid_controller_conf_t& cruise_pid_config(); // TODO: set return to const when onboard parameter use get/set
00137     pid_controller_conf_t& hover_pid_config(); // TODO: set return to const when onboard parameter use get/set
00138 
00139 
00140 private:
00141 
00147     void set_cruise_mode(bool cruise_mode);
00148 
00149 
00150     const INS&              ins_;                    
00151     nav_command_t    navigation_command_;            
00152 
00153     /* parameters */
00154     pid_controller_conf_t cruise_pid_config_;        
00155     pid_controller_conf_t hover_pid_config_;         
00156     pid_controller_conf_t std_pid_config_;           
00157     float min_cruise_dist_sqr_;                      
00158 
00159     /* auxiliary variables */
00160     float distance_to_goal_sqr_;                     
00161 };
00162 
00163 
00164 Navigation_directto::conf_t Navigation_directto::default_config()
00165 {
00166     conf_t conf;
00167     conf.min_cruise_dist_sqr                        = 4.0f;
00168 
00169     /* config of the cruise pid controller */
00170     conf.cruise_pid_config.p_gain                   = 0.7f;
00171     conf.cruise_pid_config.clip_min                 = 0.0f;
00172     conf.cruise_pid_config.clip_max                 = 3.0f;
00173     conf.cruise_pid_config.integrator.gain          = 0.0f;
00174     conf.cruise_pid_config.integrator.clip_pre      = 0.0f;
00175     conf.cruise_pid_config.integrator.clip          = 0.0f;
00176     conf.cruise_pid_config.differentiator.gain      = 0.14f;
00177     conf.cruise_pid_config.differentiator.clip      = 0.46f;
00178     conf.cruise_pid_config.soft_zone_width          = 0.0f;
00179 
00180     /* config of the hover pid controller */
00181     conf.hover_pid_config.p_gain                  = 0.4f;
00182     conf.hover_pid_config.clip_min                = 0.0f;
00183     conf.hover_pid_config.clip_max                = 3.0f;
00184     conf.hover_pid_config.integrator.gain         = 0.0f;
00185     conf.hover_pid_config.integrator.clip_pre     = 0.0f;
00186     conf.hover_pid_config.integrator.clip         = 0.0f;
00187     conf.hover_pid_config.differentiator.gain     = 0.28f;
00188     conf.hover_pid_config.differentiator.clip     = 0.46f;
00189     conf.hover_pid_config.soft_zone_width         = 0.0f;
00190 
00191     return conf;
00192 };
00193 
00194 
00195 #endif /* NAVIGATION_DIRECTTO_HPP_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines