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 #ifndef ABSOLUTE_ENCODER_SENSOR_HPP
00028 #define ABSOLUTE_ENCODER_SENSOR_HPP
00029
00030 #include <ocl/OCL.hpp>
00031 #include <rtt/dev/EncoderInterface.hpp>
00032 #include <rtt/dev/SensorInterface.hpp>
00033 #include <rtt/dev/CalibrationInterface.hpp>
00034
00035 #include <limits>
00036
00037 namespace OCL
00038 {
00043 class AbsoluteEncoderSensor
00044 : public SensorInterface<double>
00045 {
00046 EncoderInterface* enc;
00047 double unit_to_inc;
00048 double min;
00049 double max;
00050 double posOffset;
00051 bool calibrated;
00052
00053 public:
00064 AbsoluteEncoderSensor(EncoderInterface* _enc, double _unit_to_inc, int _posOffset, double _minpos, double _maxpos)
00065 : enc(_enc), unit_to_inc(_unit_to_inc), min(_minpos), max(_maxpos), posOffset(_posOffset / _unit_to_inc), calibrated(true)
00066 {}
00067
00068 virtual int readSensor( double& p ) const
00069 {
00070 p = readSensor();
00071 return 0;
00072 }
00073
00077 void limit(double _min, double _max)
00078 {
00079 min = _min;
00080 max = _max;
00081 }
00082
00083 virtual void calibrate()
00084 {
00085 this->calibrated = true;
00086 }
00087
00088 virtual void unCalibrate()
00089 {
00090 this->calibrated = false;
00091 }
00092
00093 virtual bool isCalibrated() const
00094 {
00095 return this->calibrated;
00096 }
00097
00098 virtual double readSensor() const
00099 {
00100 if ( enc->upcounting() )
00101 return ( enc->turnGet() * enc->resolution() + enc->positionGet() ) / unit_to_inc - posOffset;
00102 else
00103 return ( enc->turnGet() * enc->resolution() + ( enc->resolution() - enc->positionGet() ) ) / unit_to_inc - posOffset;
00104 }
00105
00106 virtual double maxMeasurement() const
00107 {
00108 return max;
00109 }
00110
00111 virtual double minMeasurement() const
00112 {
00113 return min;
00114 }
00115
00116 virtual double zeroMeasurement() const
00117 {
00118 return 0.0;
00119 }
00120 };
00121 };
00122
00123 #endif