View Single Post
  #2   Spotlight this post!  
Unread 04-03-2009, 00:55
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: DriverStation::GetAnalogIn - what range?

The Driver Station has a 10 bit ADC. This means that the possible range of values is from 0 to (2^10)-1, or 0 to 1023.

I just looked at the source code for the DriverStation, and I'm actually a little confused about it. FRCComm.h describes the analog inputs like this:

Code:
struct FRCControlData{
...
	//Analog inputs are 10 bit right-justified
	UINT16 analog1;
	UINT16 analog2;
	UINT16 analog3;
	UINT16 analog4;
...
That makes sense. However, DriverStation::GetAnalogIn() looks like this:

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;
}
Why does the documentation say the values are returned as a UINT32, yet the function returns a float? Also, as seen in FRCComm.h, the control data actually represents these inputs as 16-bit integers. Note that m_controlData is of type FRCControlData, meaning that analog1..4 are all UINT16 values. Perhaps this was an oversight.

The @return comment implies that it returns the actual voltage on the analog port -- but how does it do this? It doesn't look right to me, and could be an oversight by the WPI Library developers. If it's not, perhaps someone else could help explain this...
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award
Reply With Quote