Changeset 13 for trunk/extremum_seeking/esc_test/include
- Timestamp:
- 08/29/12 16:52:52 (12 years ago)
- Location:
- trunk/extremum_seeking/esc_test/include/esc_test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/extremum_seeking/esc_test/include/esc_test/esc_test.h
r11 r13 11 11 12 12 ESCSystem *system_; 13 std::vector<float> vel_, pos_; 13 14 14 15 protected: -
trunk/extremum_seeking/esc_test/include/esc_test/function.h
r11 r13 9 9 }; 10 10 11 class Gauss : public ESCFunction11 class Gauss1D : public ESCFunction 12 12 { 13 13 private: 14 float a_, b_, c_ ;14 float a_, b_, c_, d_; 15 15 16 16 public: 17 Gauss (float a=1, float b=0, float c=1) : a_(a), b_(b), c_(c) { }17 Gauss1D(float a=0, float b=1, float c=0, float d=1) : a_(a), b_(b), c_(c), d_(d) { } 18 18 19 19 std::vector<float> init() … … 29 29 throw std::runtime_error("invalid state size"); 30 30 31 return a_ *std::exp(-(state[0]-b_)*(state[0]-b_)/(2*c_*c_));31 return a_ + b_*std::exp(-(state[0]-c_)*(state[0]-c_)/(2*d_*d_)); 32 32 } 33 33 }; 34 35 class Gauss2D : public ESCFunction 36 { 37 private: 38 float a_, b_; 39 std::vector<float> c_, d_; 40 41 public: 42 Gauss2D(float a, float b, std::vector<float> c, std::vector<float> d) 43 { 44 if (c.empty()) 45 { 46 c_.push_back(0); 47 c_.push_back(0); 48 } 49 else 50 c_ = c; 51 52 if (d.empty()) 53 { 54 d_.push_back(1); 55 d_.push_back(1); 56 } 57 else 58 d_ = d; 59 } 60 61 std::vector<float> init() 62 { 63 std::vector<float> state; 64 state.push_back(0); 65 state.push_back(0); 66 return state; 67 } 68 69 float value(const std::vector<float> &state) const 70 { 71 if (state.size() != 1) 72 throw std::runtime_error("invalid state size"); 73 74 double exponent = (state[0]-c_[0])*(state[0]-c_[0])/(2*d_[0]*d_[0]) + 75 (state[1]-c_[1])*(state[1]-c_[1])/(2*d_[1]*d_[1]); 76 77 return a_ + b_*std::exp(-exponent); 78 } 79 }; 80 34 81 35 82 class ESCSystem
Note: See TracChangeset
for help on using the changeset viewer.