Merge "Changed AnalogPotentiometer to use angle specification and rail voltage."

This commit is contained in:
Fred Silberberg (WPI)
2014-12-05 16:58:04 -08:00
committed by Gerrit Code Review
5 changed files with 75 additions and 62 deletions

View File

@@ -5,38 +5,41 @@
/**
* Class for reading analog potentiometers. Analog potentiometers read
* in an analog voltage that corresponds to a position. Usually the
* position is either degrees or meters. However, if no conversion is
* given it remains volts.
* in an analog voltage that corresponds to a position. The position is
* in whichever units you choose, by way of the scaling and offset
* constants passed to the constructor.
*
* @author Alex Henning
* @author Colby Skeggs (rail voltage)
*/
class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
public:
/**
* AnalogPotentiometer constructor.
*
* Use the scaling and offset values so that the output produces
* Use the fullRange and offset values so that the output produces
* meaningful values. I.E: you have a 270 degree potentiometer and
* you want the output to be degrees with the halfway point as 0
* degrees. The scale value is 270.0(degrees)/5.0(volts) and the
* offset is -135.0 since the halfway point after scaling is 135
* degrees.
* degrees. The fullRange value is 270.0(degrees) and the offset is
* -135.0 since the halfway point after scaling is 135 degrees.
*
* This will calculate the result from the fullRange times the
* fraction of the supply voltage, plus the offset.
*
* @param channel The analog channel this potentiometer is plugged into.
* @param scale The scaling to multiply the voltage by to get a meaningful unit.
* @param fullRange The scaling to multiply the voltage by to get a meaningful unit.
* @param offset The offset to add to the scaled value for controlling the zero value
*/
explicit AnalogPotentiometer(int channel, double scale = 1.0, double offset = 0.0);
explicit AnalogPotentiometer(int channel, double fullRange = 1.0, double offset = 0.0);
explicit AnalogPotentiometer(AnalogInput *input, double scale = 1.0, double offset = 0.0);
explicit AnalogPotentiometer(AnalogInput *input, double fullRange = 1.0, double offset = 0.0);
explicit AnalogPotentiometer(AnalogInput &input, double scale = 1.0, double offset = 0.0);
explicit AnalogPotentiometer(AnalogInput &input, double fullRange = 1.0, double offset = 0.0);
virtual ~AnalogPotentiometer();
/**
* Get the current reading of the potentiomere.
* Get the current reading of the potentiomer.
*
* @return The current position of the potentiometer.
*/
@@ -70,7 +73,7 @@ public:
virtual void StopLiveWindowMode() {}
private:
double m_scale, m_offset;
double m_fullRange, m_offset;
AnalogInput* m_analog_input;
ITable* m_table;
bool m_init_analog_input;
@@ -78,5 +81,5 @@ private:
/**
* Common initialization code called by all constructors.
*/
void initPot(AnalogInput *input, double scale, double offset);
void initPot(AnalogInput *input, double fullRange, double offset);
};