Ignore:
Timestamp:
01/03/13 15:27:56 (12 years ago)
Author:
wcaarls
Message:

Updated extremum_seeking to revision 1177

Location:
trunk/extremum_seeking/esc_nn
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/extremum_seeking/esc_nn/include/esc_nn/nn_esc_2d.h

    r13 r18  
    2626protected:
    2727        double A_,M_,ddelta1_,ddelta2_,ddelta3_,delta_,B_, mpd_init_, w_switch_old_, a_switch1_old_, a_switch2_old_, a_switch3_old_,yr_,period_;
    28         double min_peak_,w_switch_;
    29         std::vector<double> vel_ref_;
     28        double min_peak_,w_switch_, stoping_min_val_, obj_val_cycle_init_;
     29        int stopping_cycle_number_, nn_cycle_count_;
     30        std::vector<double> vel_ref_,vel_ref_old_;
    3031        bool initialized_,min_peak_detect_init_;
     32
    3133
    3234public:
    3335        NNESC2D();
    34 
    35         NNESC2D(double A,double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period);
    36 
    37         void init(double A, double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period);
     36        NNESC2D(double A,double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period, int stopping_cycle_number, double stoping_min_val);
     37        void init(double A, double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period, int stopping_cycle_number, double stoping_min_val);
    3838
    3939        std::vector<double> step(double obj_val);
     
    4343        std::vector<std::string> monitorNames();
    4444        void reset();
     45        bool isStoppingConditionsMet();
    4546protected:
    4647        double wSwitch(double e);
  • trunk/extremum_seeking/esc_nn/launch/nn_esc_1d.launch

    r5 r18  
    99                <param name="period" type="double" value="0.01" />
    1010                <param name="monitor" type="bool" value="true" />
     11                <param name="stopping_condition/cycle_number" type="int" value="0" />
     12                <param name="stopping_condition/min_val_change_per_cycle" type="double" value="0" />
    1113        </node>
    1214</launch>
  • trunk/extremum_seeking/esc_nn/src/nn_esc_2d.cpp

    r13 r18  
    3131        min_peak_ = 0;
    3232        vel_ref_.resize(2);
     33        vel_ref_old_.resize(2);
    3334        vel_ref_[0] = 0;
    3435        vel_ref_[1] = 0;
     
    7374}
    7475
    75 NNESC2D::NNESC2D(double A,double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period){
    76         init(A, M, B, ddelta1, ddelta2, ddelta3, delta, period);
    77 }
    78 
    79 void NNESC2D::init(double A, double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period){
     76NNESC2D::NNESC2D(double A,double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period, int stopping_cycle_number, double stoping_min_val){
     77        init(A, M, B, ddelta1, ddelta2, ddelta3, delta, period, stopping_cycle_number, stoping_min_val);
     78}
     79
     80void NNESC2D::init(double A, double M, double B, double ddelta1, double ddelta2, double ddelta3, double delta, double period, int stopping_cycle_number, double stoping_min_val){
    8081        A_ = A;
    8182        M_ = M;
     
    8687        delta_ = delta;
    8788        period_ = period;
    88         w_switch_old_ = 0;
    89         a_switch1_old_ = A_;
    90         a_switch2_old_ = 0;
    91         a_switch3_old_ = 0;
    92         vel_ref_.resize(2);
    93         vel_ref_[0] = 0;
    94         vel_ref_[1] = 0;
    95         yr_ = 0;
    96         min_peak_ = 0;
    97         w_switch_ = 0;
    98         min_peak_detect_init_ = false;
     89        reset();
    9990        initialized_ = true;
     91        stopping_cycle_number_ = stopping_cycle_number;
     92        stoping_min_val_ = stoping_min_val;
    10093}
    10194
     
    110103                yr_ = min_peak_;
    111104                min_peak_detect_init_ = true;
     105                obj_val_cycle_init_ = obj_val;
     106                vel_ref_old_[0] = vel_ref_[0];
     107                vel_ref_old_[1] = vel_ref_[1];
    112108        }
    113109
     
    124120        w_switch_ = wSwitch(e);
    125121        yr_ = yr_ + (w_switch_+min_peak_)*period_;
     122
     123        if((vel_ref_old_[0] != vel_ref_[0] || vel_ref_old_[1] != vel_ref_[1]) && vel_ref_[1] == A_ && vel_ref_[0] == 0){
     124                if(obj_val_cycle_init_ - obj_val < stoping_min_val_){
     125                        nn_cycle_count_++;
     126                }
     127                else
     128                        nn_cycle_count_ = 0;
     129                obj_val_cycle_init_ = obj_val;
     130        }
     131        //printf("[nn_esc_2d]: nn_cycle_count = %d \n",nn_cycle_count_);
     132        vel_ref_old_[0] = vel_ref_[0];
     133        vel_ref_old_[1] = vel_ref_[1];
    126134
    127135        return vel_ref_;
     
    197205        vel_ref_[0] = 0;
    198206        vel_ref_[1] = 0;
     207        vel_ref_old_.resize(2);
     208        vel_ref_old_[0] = 0;
     209        vel_ref_old_[1] = 0;
    199210        yr_ = 0;
    200211        min_peak_ = 0;
    201212        w_switch_ = 0;
     213        nn_cycle_count_ = 0;
    202214        min_peak_detect_init_ = false;
    203         initialized_ = true;
    204 }
     215}
     216
     217bool NNESC2D::isStoppingConditionsMet(){
     218        if(stopping_cycle_number_ <= 0)
     219                return false;
     220        else if(nn_cycle_count_ > stopping_cycle_number_){
     221                return true;
     222        }
     223        else
     224                return false;
     225}
  • trunk/extremum_seeking/esc_nn/src/node_2d.cpp

    r5 r18  
    1818        ros::NodeHandle n("~");
    1919
    20         double A, B, M, ddelta1, ddelta2, ddelta3, delta, period;
     20        double A, B, M, ddelta1, ddelta2, ddelta3, delta, period,stoping_min_val;
     21        int stopping_cycle_number;
    2122        if (!n.getParam("A", A)){
    2223                ROS_WARN("[nn_esc_2d]: Failed to get the parameter A from the parameter server. Using the default value.");
     
    5253        }
    5354
     55        if (!n.getParam("stopping_condition/cycle_number", stopping_cycle_number)){
     56                ROS_WARN("[nn_esc_1D]: Failed to get the parameter stopping_condition/cycle_number from the parameter server. Using the default value.");
     57                stopping_cycle_number = 0;
     58        }
     59
     60        if (!n.getParam("stopping_condition/min_val_change_per_cycle", stoping_min_val)){
     61                ROS_WARN("[nn_esc_1D]: Failed to get the parameter stopping_condition/min_val_change_per_cycle from the parameter server. Using the default value.");
     62                stoping_min_val = 0;
     63        }
     64
    5465        ESCROS esc_ros(&n);
    55         NNESC2D* nn_esc_2d = new NNESC2D(A,M,B,ddelta1,ddelta2,ddelta3,delta,period);
     66        NNESC2D* nn_esc_2d = new NNESC2D(A,M,B,ddelta1,ddelta2,ddelta3,delta,period,stopping_cycle_number,stoping_min_val);
    5667        esc_ros.init(nn_esc_2d);
    5768        esc_ros.spin();
Note: See TracChangeset for help on using the changeset viewer.