Changed AnalogPotentiometer to use angle specification and rail voltage.

Change-Id: I98f2c1c16726496a69c86174cdb870c74e05822c
This commit is contained in:
Colby Skeggs
2014-10-23 16:42:15 +00:00
parent 5893d28f39
commit 2ae8f40a58
5 changed files with 75 additions and 62 deletions

View File

@@ -1,28 +1,29 @@
#include "AnalogPotentiometer.h"
#include "ControllerPower.h"
/**
* Common initialization code called by all constructors.
*/
void AnalogPotentiometer::initPot(AnalogInput *input, double scale, double offset) {
m_scale = scale;
void AnalogPotentiometer::initPot(AnalogInput *input, double fullRange, double offset) {
m_fullRange = fullRange;
m_offset = offset;
m_analog_input = input;
}
AnalogPotentiometer::AnalogPotentiometer(int channel, double scale, double offset) {
AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange, double offset) {
m_init_analog_input = true;
initPot(new AnalogInput(channel), scale, offset);
initPot(new AnalogInput(channel), fullRange, offset);
}
AnalogPotentiometer::AnalogPotentiometer(AnalogInput *input, double scale, double offset) {
AnalogPotentiometer::AnalogPotentiometer(AnalogInput *input, double fullRange, double offset) {
m_init_analog_input = false;
initPot(input, scale, offset);
initPot(input, fullRange, offset);
}
AnalogPotentiometer::AnalogPotentiometer(AnalogInput &input, double scale, double offset) {
AnalogPotentiometer::AnalogPotentiometer(AnalogInput &input, double fullRange, double offset) {
m_init_analog_input = false;
initPot(&input, scale, offset);
initPot(&input, fullRange, offset);
}
AnalogPotentiometer::~AnalogPotentiometer() {
@@ -33,12 +34,12 @@ AnalogPotentiometer::~AnalogPotentiometer() {
}
/**
* Get the current reading of the potentiomere.
* Get the current reading of the potentiometer.
*
* @return The current position of the potentiometer.
*/
double AnalogPotentiometer::Get() {
return m_analog_input->GetVoltage() * m_scale + m_offset;
return (m_analog_input->GetVoltage() / ControllerPower::GetVoltage5V()) * m_fullRange + m_offset;
}
/**