Results 1 to 3 of 3

Thread: DriverStation::GetAnalogIn() Bug?

  1. #1
    Join Date
    Oct 2008
    Posts
    4

    Question DriverStation::GetAnalogIn() Bug?

    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.

    Code:
    struct FRCControlData{
    ...
    	//Analog inputs are 10 bit right-justified
    	UINT16 analog1;
    	UINT16 analog2;
    	UINT16 analog3;
    	UINT16 analog4;
    ...
    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:
    /**
     * 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;
    }
    The m_controlData->analog1..4 values are all UINT16 values from the DriverStation's ADC. The function incorrectly returns these values directly.

    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

  2. #2
    Join Date
    Jan 2009
    Posts
    35

    Default Re: DriverStation::GetAnalogIn() Bug?

    Could be considered a bug in the documentation, or in the implementation. Clearly they don't agree as you point out!

    I can vouch that a zero voltage in on the DS Analog ports yields a '0' from DriverStation::GetAnalogIn(), and a +5 voltage yields 1023.

  3. #3
    Join Date
    Sep 2008
    Location
    National Instruments: Austin, TX
    Posts
    445

    Default Re: DriverStation::GetAnalogIn() Bug?

    This is certainly an oversight. In future releases, it will be 0 to 5V.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •