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