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 #ifndef END_LIMIT_DETECTOR_HPP
00029 #define END_LIMIT_DETECTOR_HPP
00030
00031 #include "rtt/dev/DigitalInInterface.hpp"
00032 #include "rtt/dev/SensorInterface.hpp"
00033
00034 #include <limits>
00035
00036 namespace OCL
00037 {
00038 using std::numeric_limits;
00039
00052 class EndLimitDetector
00053 : public DigitalInInterface
00054 {
00055 SensorInterface<double>* sens;
00056 double minpos;
00057 double maxpos;
00058 public :
00066 EndLimitDetector( SensorInterface<double>* _sensor,
00067 double _minpos = -numeric_limits<double>::max(),
00068 double _maxpos = numeric_limits<double>::max() )
00069 : sens(_sensor), minpos(_minpos), maxpos(_maxpos)
00070 {}
00071
00072 virtual bool isOn( unsigned int bit = 0) const
00073 {
00074 double pos = sens->readSensor();
00075 if ( bit == 0)
00076 return pos < minpos || pos < sens->minMeasurement();
00077 if ( bit == 1)
00078 return pos > maxpos || pos > sens->maxMeasurement();
00079 return false;
00080 }
00081
00082 virtual bool isOff( unsigned int bit = 0) const
00083 {
00084 return !isOn(bit);
00085 }
00086
00087 virtual bool readBit( unsigned int bit = 0) const
00088 {
00089 return isOn(bit);
00090 }
00091
00092 virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const
00093 {
00094 if (start_bit > 1 || stop_bit > 1 )
00095 return 0;
00096
00097 return (( isOn(0) + isOn(1)*2 ) >> start_bit ) & (1 << (stop_bit+1)-1);
00098 }
00099
00100 virtual unsigned int nbOfInputs() const
00101 { return 2; }
00102 };
00103
00104 }
00105
00106 #endif