Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
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
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
00129
00130
00131
00132 numericprecission Ts_;
00133
00134
00135 uint32_t cycle_count_;
00136
00137
00138 bool state_initialized_, initialized_, old_vals_initialized_;
00139
00140
00141 int controlNum;
00142
00143
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