00001 /* 00002 * sm_esc_1d.cpp 00003 * 00004 * Created on: Jul 30, 2012 00005 * Author: Berk Calli 00006 * Organization: Delft Biorobotics Lab., Delft University of Technology 00007 * Contact info: b.calli@tudelft.nl, web: www.dbl.tudelft.nl 00008 * 00009 * Class for one dimensional sliding mode extremum seeking control with periodic driving signal 00010 * 00011 * * References: 00012 * - H. Yu and U. Ozguner, “Extremum-seeking Control Strategy for ABS System with Time Delay,” ACC 2002. 00013 * - B. Calli, W. Caarls, P. Jonker and M. Wisse, "Comparison of Extremum Seeking Control Algorithms for Robotic Applications", IROS 2012. 00014 */ 00015 00016 #include "esc_sm/sm_esc_1d.h" 00017 00018 SMESC1D::SMESC1D(){ 00019 rho_ = 0; 00020 k_ = 0; 00021 alpha_ = 0; 00022 driving_input_ = 0; 00023 driving_input_init_ = false; 00024 initialized_ = false; 00025 } 00026 00027 SMESC1D::SMESC1D(double rho, double k, double alpha){ 00028 init(rho,k,alpha); 00029 } 00030 00031 void SMESC1D::init(double rho, double k, double alpha){ 00032 rho_ = rho; 00033 k_ = k; 00034 alpha_ = alpha; 00035 driving_input_ = 0; 00036 driving_input_init_ = false; 00037 initialized_ = true; 00038 } 00039 00040 ESC::inputType SMESC1D::getInputType(){ 00041 return ESC::inputValue; 00042 } 00043 00044 ESC::outputType SMESC1D::getOutputType(){ 00045 return ESC::outputVelocity; 00046 } 00047 00048 std::vector<double> SMESC1D::step(double obj_val){ 00049 if (!initialized_){ 00050 fprintf(stderr,"The sliding mode ESC (1D) is not initialized... step function will not be executed. \n"); 00051 return std::vector<double>(); 00052 } 00053 if(!driving_input_init_){ 00054 driving_input_ = obj_val; 00055 driving_input_init_ = true; 00056 } 00057 00058 driving_input_ = driving_input_- rho_; 00059 double s = obj_val - driving_input_; 00060 vel_ref_ = k_*sign(sin(PI/alpha_*s)); 00061 std::vector<double> output; 00062 output.push_back(vel_ref_); 00063 return output; 00064 } 00065 00066 int SMESC1D::sign(double value){ 00067 if (value>0){ 00068 return 1; 00069 } 00070 else if (value<0){ 00071 return -1; 00072 } 00073 else{ 00074 return 0; 00075 } 00076 } 00077 00078 std::vector<double> SMESC1D::monitor(){ 00079 std::vector<double> monitor_values; 00080 monitor_values.push_back(driving_input_); 00081 return monitor_values; 00082 } 00083 std::vector<std::string> SMESC1D::monitorNames(){ 00084 std::vector<std::string> monitor_names; 00085 monitor_names.push_back("driving input"); 00086 return monitor_names; 00087 } 00088 00089 void SMESC1D::reset(){ 00090 driving_input_ = 0; 00091 driving_input_init_ = false; 00092 }