#ifndef ANALOGRANGEFINDER_H #define ANALOGRANGEFINDER_H #include "SensorBase.h" #include "PIDSource.h" class AnalogChannel; class AnalogModule; #define ANALOG_RANGE_FINDER_DEFAULT_INCHES_PER_MV 0.1024F //Designed for the MaxBotix LV-MaxSonarŽ-EZ1, but should work for any analog output sonar module class AnalogRangeFinder : public SensorBase, public PIDSource { private: float inchesPerMillivolt; AnalogChannel *m_analogChannel; bool m_allocatedChannel; void InitAnalogRangeFinder(void) { inchesPerMillivolt = ANALOG_RANGE_FINDER_DEFAULT_INCHES_PER_MV; } public: AnalogRangeFinder(UINT8 moduleNumber, UINT32 channel); explicit AnalogRangeFinder(UINT32 channel) { m_analogChannel = new AnalogChannel(channel); m_allocatedChannel = true; InitAnalogRangeFinder(); } explicit AnalogRangeFinder(AnalogChannel *channel) { if (channel != NULL) { m_analogChannel = channel; InitAnalogRangeFinder(); m_allocatedChannel = false; } } explicit AnalogRangeFinder(AnalogChannel &channel) { m_analogChannel = &channel; m_allocatedChannel = false; InitAnalogRangeFinder(); } virtual ~AnalogRangeFinder() { if (m_allocatedChannel) { delete m_analogChannel; } } virtual float GetRangeInches() { return m_analogChannel->GetVoltage() * inchesPerMillivolt; } void SetSensitivity(float inches_per_millivolt) { inchesPerMillivolt = inches_per_millivolt; } // PIDSource interface double PIDGet() { return GetRangeInches(); } }; #endif