Ignore:
Timestamp:
08/29/12 16:52:52 (12 years ago)
Author:
wcaarls
Message:

Updated extremum_seeking to revision 1017

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/extremum_seeking/esc_test/include/esc_test/function.h

    r11 r13  
    99};
    1010
    11 class Gauss : public ESCFunction
     11class Gauss1D : public ESCFunction
    1212{
    1313  private:
    14     float a_, b_, c_;
     14    float a_, b_, c_, d_;
    1515
    1616  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) { }
    1818   
    1919    std::vector<float> init()
     
    2929        throw std::runtime_error("invalid state size");
    3030       
    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_));
    3232    }
    3333};
     34
     35class 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
    3481
    3582class ESCSystem
Note: See TracChangeset for help on using the changeset viewer.