Libbarrett  1.2.4
include/barrett/systems/rate_limiter.h
00001 /*
00002         Copyright 2012 Barrett Technology <support@barrett.com>
00003 
00004         This file is part of libbarrett.
00005 
00006         This version of libbarrett is free software: you can redistribute it
00007         and/or modify it under the terms of the GNU General Public License as
00008         published by the Free Software Foundation, either version 3 of the
00009         License, or (at your option) any later version.
00010 
00011         This version of libbarrett is distributed in the hope that it will be
00012         useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License along
00017         with this version of libbarrett.  If not, see
00018         <http://www.gnu.org/licenses/>.
00019 
00020         Further, non-binding information about licensing is available at:
00021         <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes>
00022 */
00023 
00024 /*
00025  * rate_limiter.h
00026  *
00027  *  Created on: Apr 12, 2012
00028  *      Author: dc
00029  */
00030 
00031 #ifndef BARRETT_SYSTEMS_RATE_LIMITER_H_
00032 #define BARRETT_SYSTEMS_RATE_LIMITER_H_
00033 
00034 
00035 #include <string>
00036 
00037 #include <Eigen/Core>
00038 
00039 #include <barrett/detail/ca_macro.h>
00040 #include <barrett/math/traits.h>
00041 #include <barrett/systems/abstract/single_io.h>
00042 
00043 
00044 namespace barrett {
00045 namespace systems {
00046 
00047 
00048 template<typename T, typename MathTraits = math::Traits<T> >
00049 class RateLimiter : public SingleIO<T,T> {
00050 protected:
00051         typedef MathTraits MT;
00052 
00053 public:
00054         RateLimiter(const T& limit = T(0.0), const std::string& sysName = "RateLimiter") :
00055                 SingleIO<T,T>(sysName), T_s(0.0), limit(), maxDelta(), data(), delta()
00056         {
00057                 setLimit(limit);
00058                 getSamplePeriodFromEM();
00059         }
00060         ~RateLimiter() {
00061                 this->mandatoryCleanUp();
00062         }
00063 
00064         void setLimit(const T& newLimit);
00065 
00066         void setCurVal(const T& newPos);
00067 
00068 protected:
00069         double T_s;
00070         T limit, maxDelta;
00071         T data;
00072 
00073         T delta;
00074         virtual void operate();
00075 
00076         virtual void onExecutionManagerChanged() {
00077                 SingleIO<T,T>::onExecutionManagerChanged();  // First, call super
00078                 getSamplePeriodFromEM();
00079         }
00080         void getSamplePeriodFromEM();
00081 
00082 private:
00083         DISALLOW_COPY_AND_ASSIGN(RateLimiter);
00084 
00085 public:
00086         EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(MT::RequiresAlignment)
00087 };
00088 
00089 
00090 }
00091 }
00092 
00093 
00094 // include template definitions
00095 #include <barrett/systems/detail/rate_limiter-inl.h>
00096 
00097 
00098 #endif /* BARRETT_SYSTEMS_RATE_LIMITER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines