As far as I can tell, the Driver Station has a 10-bit ADC, and measures from 0V to 5V. As FRCComm.h indicates, the analog inputs are sent to the cRIO as right-aligned UINT16 ADC values.
However, DriverStation::GetAnalogIn() returns type float, without actually performing any arithmetic on these values. The documentation seems to imply that the function will return the actual voltage measured on the channel, however this seems to be incorrect.Code:struct FRCControlData{ ... //Analog inputs are 10 bit right-justified UINT16 analog1; UINT16 analog2; UINT16 analog3; UINT16 analog4; ...
The m_controlData->analog1..4 values are all UINT16 values from the DriverStation's ADC. The function incorrectly returns these values directly.Code:/** * Get an analog voltage from the Driver Station. * The analog values are returned as UINT32 values for the Driver Station analog inputs. * These inputs are typically used for advanced operator interfaces consisting of potentiometers * or resistor networks representing values on a rotary switch. * * @param channel The analog input channel on the driver station to read from. Valid range is 1 - 4. * @return The analog voltage on the input. */ float DriverStation::GetAnalogIn(UINT32 channel) { wpi_assert ((channel >= 1) && (channel <= 4)); GetData(); switch (channel) { case 1: return m_controlData->analog1; case 2: return m_controlData->analog2; case 3: return m_controlData->analog3; case 4: return m_controlData->analog4; } return 0; }
If this function is to do what the documentation implies, shouldn't the ADC values be multiplied by a conversion factor of ~0.00488758 V/code before returning the measurement?
(5V-0V)/(1023-0) ~= 0.00488758 V/code.
Also, the documentation appears to incorrectly state that the analog input values are reported as UINT32; they are UINT16.
I am referencing the source code provided with the latest version of WPILib, 3.1.1764.
This is also being discussed on ChiefDelphi here: http://www.chiefdelphi.com/forums/sh...ad.php?t=75475


Reply With Quote