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 HOME_POSITION_DETECTOR_HPP
00029 #define HOME_POSITION_DETECTOR_HPP
00030
00031 #include "rtt/dev/DigitalInInterface.hpp"
00032 #include "rtt/dev/SensorInterface.hpp"
00033 #include "rtt/dev/EncoderInterface.hpp"
00034
00035 namespace OCL
00036 {
00037
00047 class HomePositionDetector
00048 : public DigitalInInterface
00049 {
00050 SensorInterface<double>* sens;
00051 EncoderInterface* enc;
00052 public :
00059 HomePositionDetector( SensorInterface<double>* _sensor,
00060 EncoderInterface* _encoder = 0)
00061 : sens(_sensor), enc(_encoder) {}
00062
00063 virtual bool isOn( unsigned int bit = 0) const
00064 {
00065 if ( bit == 0)
00066 return sens->readSensor() == 0.0;
00067 if ( bit == 1)
00068 return enc != 0 && enc->positionGet() == 0;
00069 if ( bit == 2)
00070 return enc != 0 && enc->turnGet() == 0;
00071 return false;
00072 }
00073 virtual bool isOff( unsigned int bit = 0) const
00074 {
00075 return !isOn(bit);
00076 }
00077 virtual bool readBit( unsigned int bit = 0) const
00078 {
00079 return isOn(bit);
00080 }
00081 virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const
00082 {
00083 if (start_bit > 2 || stop_bit > 2 )
00084 return 0;
00085
00086 return (( isOn(0) + isOn(1)*2 + isOn(2)*4 ) >> start_bit ) & (1 << (stop_bit+1)-1) ;
00087 }
00088 virtual unsigned int nbOfInputs() const
00089 { return enc != 0 ? 3 : 1; }
00090 };
00091
00092 }
00093
00094 #endif