Libbarrett  1.2.4
include/barrett/math/utils.h
Go to the documentation of this file.
00001 
00009 /* Copyright 2009 Barrett Technology <support@barrett.com> */
00010 
00011 /* This file is part of libbarrett.
00012  *
00013  * This version of libbarrett is free software: you can redistribute it
00014  * and/or modify it under the terms of the GNU General Public License as
00015  * published by the Free Software Foundation, either version 3 of the
00016  * License, or (at your option) any later version.
00017  *
00018  * This version of libbarrett is distributed in the hope that it will be
00019  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License along
00024  * with this version of libbarrett.  If not, see
00025  * <http://www.gnu.org/licenses/>.
00026  *
00027  * Further, non-binding information about licensing is available at:
00028  * <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes>
00029  */
00030 
00031 
00032 #ifndef BARRETT_MATH_UTILS_H_
00033 #define BARRETT_MATH_UTILS_H_
00034 
00035 
00036 #include <Eigen/Core>
00037 
00038 
00039 namespace barrett {
00040 namespace math {
00041 
00042 
00043 namespace detail {
00044 template<typename Scalar> struct CwiseSignOp;
00045 template<typename Scalar> struct CwiseUnarySaturateOp;
00046 template<typename Scalar> struct CwiseBinarySaturateOp;
00047 template<typename Scalar> struct CwiseUnaryDeadbandOp;
00048 template<typename Scalar> struct CwiseBinaryDeadbandOp;
00049 }
00050 
00062 template<typename Derived>
00063 const Eigen::CwiseUnaryOp<
00064         detail::CwiseSignOp<typename Eigen::ei_traits<Derived>::Scalar>,
00065         Derived
00066 > sign(const Eigen::MatrixBase<Derived>& x);
00067 
00068 double sign(double x);
00069 
00079 template<typename Derived>
00080 const Eigen::CwiseUnaryOp<
00081         Eigen::ei_scalar_abs_op<typename Eigen::ei_traits<Derived>::Scalar>,
00082         Derived
00083 > abs(const Eigen::MatrixBase<Derived>& x);
00084 
00095 template<typename Derived1, typename Derived2>
00096 const Eigen::CwiseBinaryOp<
00097         Eigen::ei_scalar_min_op<typename Eigen::ei_traits<Derived1>::Scalar>,
00098         Derived1,
00099         Derived2
00100 > min(const Eigen::MatrixBase<Derived1>& a, const Eigen::MatrixBase<Derived2>& b);
00101 
00102 double min(double a, double b);
00103 
00114 template<typename Derived1, typename Derived2>
00115 const Eigen::CwiseBinaryOp<
00116         Eigen::ei_scalar_max_op<typename Eigen::ei_traits<Derived1>::Scalar>,
00117         Derived1,
00118         Derived2
00119 > max(const Eigen::MatrixBase<Derived1>& a, const Eigen::MatrixBase<Derived2>& b);
00120 
00121 double max(double a, double b);
00122 
00123 //template<typename T> T max(const T& a, const T& b);  //NOLINT: this is not the max() from <algorithm>
00124 
00135 template<typename Derived>
00136 const Eigen::CwiseUnaryOp<
00137         detail::CwiseUnarySaturateOp<typename Eigen::ei_traits<Derived>::Scalar>,
00138         Derived
00139 > saturate(const Eigen::MatrixBase<Derived>& x, double limit);
00140 
00141 template<typename Derived1, typename Derived2>
00142 inline const Eigen::CwiseBinaryOp<
00143         detail::CwiseBinarySaturateOp<typename Eigen::ei_traits<Derived1>::Scalar>,
00144         Derived1,
00145         Derived2
00146 > saturate(const Eigen::MatrixBase<Derived1>& x, const Eigen::MatrixBase<Derived2>& limit);
00147 
00148 double saturate(double x, double limit);
00149 
00150 
00151 template<typename Derived>
00152 const Eigen::CwiseUnaryOp<
00153         detail::CwiseUnarySaturateOp<typename Eigen::ei_traits<Derived>::Scalar>,
00154         Derived
00155 > saturate(const Eigen::MatrixBase<Derived>& x, double lowerLimit, double upperLimit);
00156 
00157 double saturate(double x, double lowerLimit, double upperLimit);
00158 
00159 
00171 template<typename Derived>
00172 const Eigen::CwiseUnaryOp<
00173         detail::CwiseUnaryDeadbandOp<typename Eigen::ei_traits<Derived>::Scalar>,
00174         Derived
00175 > deadband(const Eigen::MatrixBase<Derived>& x, double cutoff);
00176 
00177 template<typename Derived1, typename Derived2>
00178 const Eigen::CwiseBinaryOp<
00179         detail::CwiseBinaryDeadbandOp<typename Eigen::ei_traits<Derived1>::Scalar>,
00180         Derived1,
00181         Derived2
00182 > deadband(const Eigen::MatrixBase<Derived1>& x, const Eigen::MatrixBase<Derived2>& cutoff);
00183 
00184 double deadband(double x, double cutoff);
00185 
00186 //template<typename T> T deadBand(const T& x,
00187 //              const T& lowerCutoff, const T& upperCutoff);
00188 
00189 
00190 }
00191 }
00192 
00193 
00194 // include template definitions
00195 #include <barrett/math/detail/utils-inl.h>
00196 
00197 
00198 #endif /* BARRETT_MATH_UTILS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines