source: trunk/extremum_seeking/esc_sm/src/sm_esc_1d.cpp @ 48

Last change on this file since 48 was 13, checked in by wcaarls, 12 years ago

Updated extremum_seeking to revision 1017

File size: 2.1 KB
Line 
1/*
2 * sm_esc_1d.cpp
3 *
4 *  Created on: Jul 30, 2012
5 *      Author: Berk Calli
6 *      Organization: Delft Biorobotics Lab., Delft University of Technology
7 *              Contact info: b.calli@tudelft.nl, web: www.dbl.tudelft.nl
8 *
9 *  Class for one dimensional sliding mode extremum seeking control with periodic driving signal
10 *
11 * * References:
12 * - H. Yu and U. Ozguner, “Extremum-seeking Control Strategy for ABS System with Time Delay,” ACC 2002.
13 * - B. Calli, W. Caarls, P. Jonker and M. Wisse, "Comparison of Extremum Seeking Control Algorithms for Robotic Applications", IROS 2012.
14 */
15
16#include "esc_sm/sm_esc_1d.h"
17
18SMESC1D::SMESC1D(){
19        rho_ = 0;
20        k_ = 0;
21        alpha_ = 0;
22        driving_input_ = 0;
23        driving_input_init_ = false;
24        initialized_ = false;
25}
26
27SMESC1D::SMESC1D(double rho, double k, double alpha){
28        init(rho,k,alpha);
29}
30
31void SMESC1D::init(double rho, double k, double alpha){
32        rho_ = rho;
33        k_ = k;
34        alpha_ = alpha;
35        driving_input_ = 0;
36        driving_input_init_ = false;
37        initialized_ = true;
38}
39
40ESC::inputType SMESC1D::getInputType(){
41        return ESC::inputValue;
42}
43
44ESC::outputType SMESC1D::getOutputType(){
45        return ESC::outputVelocity;
46}
47
48std::vector<double> SMESC1D::step(double obj_val){
49        if (!initialized_){
50                fprintf(stderr,"The sliding mode ESC (1D) is not initialized... step function will not be executed. \n");
51                return std::vector<double>();
52        }
53        if(!driving_input_init_){
54                driving_input_ = obj_val;
55                driving_input_init_ = true;
56        }
57
58        driving_input_ = driving_input_- rho_;
59        double s = obj_val - driving_input_;
60        vel_ref_ = k_*sign(sin(PI/alpha_*s));
61        std::vector<double> output;
62        output.push_back(vel_ref_);
63        return output;
64}
65
66int SMESC1D::sign(double value){
67        if (value>0){
68                return 1;
69        }
70        else if (value<0){
71                return -1;
72        }
73        else{
74                return 0;
75        }
76}
77
78std::vector<double> SMESC1D::monitor(){
79        std::vector<double> monitor_values;
80        monitor_values.push_back(driving_input_);
81        return monitor_values;
82}
83std::vector<std::string> SMESC1D::monitorNames(){
84        std::vector<std::string> monitor_names;
85        monitor_names.push_back("driving input");
86        return monitor_names;
87}
88
89void SMESC1D::reset(){
90        driving_input_ = 0;
91        driving_input_init_ = false;
92}
Note: See TracBrowser for help on using the repository browser.