EscPerturbationBase.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * EscPerturbation.hpp
00003  *
00004  *  Created on: Dec 15, 2014
00005  *      Author: Filip Mandic
00006  *
00007  ********************************************************************/
00008 
00009 /*********************************************************************
00010 * Software License Agreement (BSD License)
00011 *
00012 *  Copyright (c) 2014, LABUST, UNIZG-FER
00013 *  All rights reserved.
00014 *
00015 *  Redistribution and use in source and binary forms, with or without
00016 *  modification, are permitted provided that the following conditions
00017 *  are met:
00018 *
00019 *   * Redistributions of source code must retain the above copyright
00020 *     notice, this list of conditions and the following disclaimer.
00021 *   * Redistributions in binary form must reproduce the above
00022 *     copyright notice, this list of conditions and the following
00023 *     disclaimer in the documentation and/or other materials provided
00024 *     with the distribution.
00025 *   * Neither the name of the LABUST nor the names of its
00026 *     contributors may be used to endorse or promote products derived
00027 *     from this software without specific prior written permission.
00028 *
00029 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00030 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00031 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00032 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00033 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00034 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00035 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00036 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00037 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00038 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00039 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00040 *  POSSIBILITY OF SUCH DAMAGE.
00041 *********************************************************************/
00042 
00043 #ifndef ESCPERTURBATIONBASE_HPP_
00044 #define ESCPERTURBATIONBASE_HPP_
00045 
00046 #include <Eigen/Dense>
00047 #include <stdint.h>
00048 
00049 #include <ros/ros.h>
00050 
00051 namespace labust{
00052         namespace control{
00053                 namespace esc{
00054 
00055                 /*************************************************************
00056                  *** Abstract class definition
00057                  ************************************************************/
00058                         template <typename precission = double>
00059                         class EscPerturbationBase {
00060 
00061                         public:
00062 
00063                                 typedef precission numericprecission;
00064 
00065                                 typedef Eigen::Matrix<precission, Eigen::Dynamic, Eigen::Dynamic> matrix;
00066                                 typedef Eigen::Matrix<precission, Eigen::Dynamic, 1> vector;
00067 
00068                                 EscPerturbationBase(int ctrlNum, numericprecission Ts):Ts_(Ts),cycle_count_(0),controlNum(ctrlNum){
00069 
00070                                         state_initialized_ = false;
00071                                         initialized_ = false;
00072                                         old_vals_initialized_ = false;
00073                                 }
00074 
00075                             virtual ~EscPerturbationBase(){}
00076 
00077                                 /*****************************************************
00078                                  *** Class functions
00079                                  ****************************************************/
00080 
00081                                  virtual numericprecission preFiltering(numericprecission cost_signal){
00082 
00083                                          return cost_signal;
00084                                  }
00085 
00086                                  virtual vector gradientEstimation(numericprecission cost_signal_filtered, vector additional_input) = 0;
00087 
00088                                  virtual vector postFiltering(vector estimated_gradient){
00089                                          return estimated_gradient;
00090                                  }
00091 
00092                                  virtual vector controllerGain(vector postFiltered){
00093                                          control_ = control_+gain_.cwiseProduct(postFiltered)*Ts_;
00094                                          return control_;
00095                                  }
00096 
00097                                  virtual vector superimposePerturbation(vector control) = 0;
00098 
00099                                  virtual vector step(numericprecission cost_signal, vector additional_input = vector::Zero(2) ){
00100 
00101                                          numericprecission filtered_cost =  preFiltering(cost_signal);
00102 
00103                                          vector estimated_gradient = gradientEstimation(filtered_cost, additional_input);
00104 
00105                                          vector control = controllerGain(postFiltering(estimated_gradient));
00106 
00107                                          vector controlInput =  superimposePerturbation(control);
00108 
00109                                          pre_filter_input_old_ = cost_signal;
00110                                          pre_filter_output_old_ = filtered_cost;
00111                                          estimated_gradient_old_ = estimated_gradient;
00112 
00113                                          old_vals_initialized_ = true;
00114                                          cycle_count_++;
00115 
00116                                          return controlInput;
00117                                  }
00118 
00119                                 virtual void reset(){
00120 
00121                                         state_initialized_ = false;
00122                                         initialized_ = false;
00123                                         old_vals_initialized_ = false;
00124                                         cycle_count_ = 0;
00125                                 }
00126 
00127                                 /*****************************************************
00128                                  *** General parameters
00129                                  ****************************************************/
00130 
00131                                 /*** Sampling time */
00132                                 numericprecission Ts_;
00133 
00134                                 /*** Cycle */
00135                                 uint32_t cycle_count_;
00136 
00137                                 /*** Status flags */
00138                                 bool state_initialized_, initialized_, old_vals_initialized_;
00139 
00140                                 /*** Number of control inputs (states) */
00141                                 int controlNum;
00142 
00143                                 /*** ES variables */
00144                                 numericprecission pre_filter_input_old_, pre_filter_output_old_;
00145                                 vector estimated_gradient_old_, control_, gain_;
00146 
00147                         };
00148                 }
00149         }
00150 }
00151 
00152 #endif /* ESCPERTURBATION_HPP_ */


labust_control
Author(s): Gyula Nagy
autogenerated on Fri Aug 28 2015 11:22:42