Relay.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, LABUST, UNIZG-FER
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the LABUST nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
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 /* RELAY_HPP_ */
00162 #endif


ident_so
Author(s): Gyula Nagy
autogenerated on Mon Oct 6 2014 01:39:47