Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef RELAY_HPP_
00035 #define RELAY_HPP_
00036
00037 namespace labust
00038 {
00039 namespace control
00040 {
00046 class Relay
00047 {
00048 public:
00052 Relay():
00053 Cp(1),Cm(-1),Xap(0),Xam(0),switched(false),out(1){};
00060 Relay(double C, double X):
00061 Cp(C),Cm(-C),Xap(X),Xam(-X),switched(false),out(C){};
00070 Relay(double Cp, double Cm, double Xp, double Xm):
00071 Cp(Cp),Cm(Cm),Xap(Xp),Xam(Xm),switched(false),out(Cp){};
00075 ~Relay(){};
00076
00082 inline void setAmplitude(double C){this->out = this->Cp = C; this->Cm = -C;};
00090 inline void setAmplitude(double Cp, double Cm){this->out = this->Cp = Cp; this->Cm = Cm;};
00096 inline void setHysteresis(double X){this->Xam = -X; this->Xap = X;};
00104 inline void setHysteresis(double Xp, double Xm){this->Xam = Xm; this->Xap = Xp;};
00110 inline double getAmplitude(){return this->Cp;};
00111
00117 inline int hasSwitched()
00118 {
00119 if (this->switched)
00120 {
00121 if (this->out == this->Cp) return 1;
00122 else return -1;
00123 }
00124 return 0;
00125 }
00133 double step(double input)
00134 {
00135 if ((this->switched = ((input>=Xap) && (this->out != this->Cp)))) this->out = this->Cp;
00136 else if ((this->switched = ((input<=this->Xam) && (this->out != this->Cm)))) this->out = this->Cm;
00137
00138 return this->out;
00139 }
00140
00141 private:
00145 double Cp, Cm;
00149 double Xap,Xam;
00153 bool switched;
00157 double out;
00158 };
00159 };
00160 };
00161
00162 #endif