Changeset 18 for trunk/extremum_seeking/esc_nn
- Timestamp:
- 01/03/13 15:27:56 (12 years ago)
- 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 26 26 protected: 27 27 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_; 30 31 bool initialized_,min_peak_detect_init_; 32 31 33 32 34 public: 33 35 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); 38 38 39 39 std::vector<double> step(double obj_val); … … 43 43 std::vector<std::string> monitorNames(); 44 44 void reset(); 45 bool isStoppingConditionsMet(); 45 46 protected: 46 47 double wSwitch(double e); -
trunk/extremum_seeking/esc_nn/launch/nn_esc_1d.launch
r5 r18 9 9 <param name="period" type="double" value="0.01" /> 10 10 <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" /> 11 13 </node> 12 14 </launch> -
trunk/extremum_seeking/esc_nn/src/nn_esc_2d.cpp
r13 r18 31 31 min_peak_ = 0; 32 32 vel_ref_.resize(2); 33 vel_ref_old_.resize(2); 33 34 vel_ref_[0] = 0; 34 35 vel_ref_[1] = 0; … … 73 74 } 74 75 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 ){76 NNESC2D::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 80 void 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){ 80 81 A_ = A; 81 82 M_ = M; … … 86 87 delta_ = delta; 87 88 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(); 99 90 initialized_ = true; 91 stopping_cycle_number_ = stopping_cycle_number; 92 stoping_min_val_ = stoping_min_val; 100 93 } 101 94 … … 110 103 yr_ = min_peak_; 111 104 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]; 112 108 } 113 109 … … 124 120 w_switch_ = wSwitch(e); 125 121 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]; 126 134 127 135 return vel_ref_; … … 197 205 vel_ref_[0] = 0; 198 206 vel_ref_[1] = 0; 207 vel_ref_old_.resize(2); 208 vel_ref_old_[0] = 0; 209 vel_ref_old_[1] = 0; 199 210 yr_ = 0; 200 211 min_peak_ = 0; 201 212 w_switch_ = 0; 213 nn_cycle_count_ = 0; 202 214 min_peak_detect_init_ = false; 203 initialized_ = true; 204 } 215 } 216 217 bool 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 18 18 ros::NodeHandle n("~"); 19 19 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; 21 22 if (!n.getParam("A", A)){ 22 23 ROS_WARN("[nn_esc_2d]: Failed to get the parameter A from the parameter server. Using the default value."); … … 52 53 } 53 54 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 54 65 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); 56 67 esc_ros.init(nn_esc_2d); 57 68 esc_ros.spin();
Note: See TracChangeset
for help on using the changeset viewer.