"

2013 FRC Java API

"

edu.wpi.first.wpilibj
Class AnalogChannel

java.lang.Object
  extended by edu.wpi.first.wpilibj.SensorBase
      extended by edu.wpi.first.wpilibj.AnalogChannel
All Implemented Interfaces:
LiveWindowSendable, PIDSource, Sendable

public class AnalogChannel
extends SensorBase
implements PIDSource, LiveWindowSendable

Analog channel class. Each analog channel is read from hardware as a 12-bit number representing -10V to 10V. Connected to each analog channel is an averaging and oversampling engine. This engine accumulates the specified ( by setAverageBits() and setOversampleBits() ) number of samples before returning a new value. This is not a sliding window average. The only difference between the oversampled samples and the averaged samples is that the oversampled samples are simply accumulated effectively increasing the resolution, while the averaged samples are divided by the number of samples to retain the resolution, but get more stable values.


Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.wpi.first.wpilibj.PIDSource
PIDSource.PIDSourceParameter
 
Field Summary
 
Fields inherited from class edu.wpi.first.wpilibj.SensorBase
kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond
 
Constructor Summary
AnalogChannel(int channel)
          Construct an analog channel on the default module.
AnalogChannel(int moduleNumber, int channel)
          Construct an analog channel on a specified module.
 
Method Summary
 void free()
          Channel destructor.
 long getAccumulatorCount()
          Read the number of accumulated values.
 void getAccumulatorOutput(AccumulatorResult result)
          Read the accumulated value and the number of accumulated values atomically.
 long getAccumulatorValue()
          Read the accumulated value.
 int getAverageBits()
          Get the number of averaging bits.
 int getAverageValue()
          Get a sample from the output of the oversample and average engine for this channel.
 double getAverageVoltage()
          Get a scaled sample from the output of the oversample and average engine for this channel.
 int getChannel()
          Get the channel number.
 long getLSBWeight()
          Get the factory scaling least significant bit weight constant.
 AnalogModule getModule()
          Get the analog module that this channel is on.
 int getModuleNumber()
          Gets the number of the analog module this channel is on.
 int getOffset()
          Get the factory scaling offset constant.
 int getOversampleBits()
          Get the number of oversample bits.
 String getSmartDashboardType()
           
 ITable getTable()
          
 int getValue()
          Get a sample straight from this channel on the module.
 double getVoltage()
          Get a scaled sample straight from this channel on the module.
 void initAccumulator()
          Initialize the accumulator.
 void initTable(ITable subtable)
          Initializes a table for this sendable object.
 boolean isAccumulatorChannel()
          Is the channel attached to an accumulator.
 double pidGet()
          Get the average value for use with PIDController.
 void resetAccumulator()
          Resets the accumulator to the initial value.
 void setAccumulatorCenter(int center)
          Set the center value of the accumulator.
 void setAccumulatorDeadband(int deadband)
          Set the accumulator's deadband.
 void setAccumulatorInitialValue(long initialValue)
          Set an inital value for the accumulator.
 void setAverageBits(int bits)
          Set the number of averaging bits.
 void setOversampleBits(int bits)
          Set the number of oversample bits.
 void setVoltageForPID(boolean shouldUseVoltageForPID)
          Set whether to use voltage of value for PIDGet This method determines whether PIDGet uses average voltage or value for PID controllers for a particular channel.
 void startLiveWindowMode()
          Analog Channels don't have to do anything special when entering the LiveWindow.
 void stopLiveWindowMode()
          Analog Channels don't have to do anything special when exiting the LiveWindow.
 void updateTable()
          Update the table for this sendable object with the latest values.
 
Methods inherited from class edu.wpi.first.wpilibj.SensorBase
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnalogChannel

public AnalogChannel(int channel)
Construct an analog channel on the default module.

Parameters:
channel - The channel number to represent.

AnalogChannel

public AnalogChannel(int moduleNumber,
                     int channel)
Construct an analog channel on a specified module.

Parameters:
moduleNumber - The digital module to use (1 or 2).
channel - The channel number to represent.
Method Detail

free

public void free()
Channel destructor.

Overrides:
free in class SensorBase

getModule

public AnalogModule getModule()
Get the analog module that this channel is on.

Returns:
The AnalogModule that this channel is on.

getValue

public int getValue()
Get a sample straight from this channel on the module. The sample is a 12-bit value representing the -10V to 10V range of the A/D converter in the module. The units are in A/D converter codes. Use GetVoltage() to get the analog value in calibrated units.

Returns:
A sample straight from this channel on the module.

getAverageValue

public int getAverageValue()
Get a sample from the output of the oversample and average engine for this channel. The sample is 12-bit + the value configured in SetOversampleBits(). The value configured in setAverageBits() will cause this value to be averaged 2**bits number of samples. This is not a sliding window. The sample will not change until 2**(OversamplBits + AverageBits) samples have been acquired from the module on this channel. Use getAverageVoltage() to get the analog value in calibrated units.

Returns:
A sample from the oversample and average engine for this channel.

getVoltage

public double getVoltage()
Get a scaled sample straight from this channel on the module. The value is scaled to units of Volts using the calibrated scaling data from getLSBWeight() and getOffset().

Returns:
A scaled sample straight from this channel on the module.

getAverageVoltage

public double getAverageVoltage()
Get a scaled sample from the output of the oversample and average engine for this channel. The value is scaled to units of Volts using the calibrated scaling data from getLSBWeight() and getOffset(). Using oversampling will cause this value to be higher resolution, but it will update more slowly. Using averaging will cause this value to be more stable, but it will update more slowly.

Returns:
A scaled sample from the output of the oversample and average engine for this channel.

getLSBWeight

public long getLSBWeight()
Get the factory scaling least significant bit weight constant. The least significant bit weight constant for the channel that was calibrated in manufacturing and stored in an eeprom in the module. Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)

Returns:
Least significant bit weight.

getOffset

public int getOffset()
Get the factory scaling offset constant. The offset constant for the channel that was calibrated in manufacturing and stored in an eeprom in the module. Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)

Returns:
Offset constant.

getChannel

public int getChannel()
Get the channel number.

Returns:
The channel number.

getModuleNumber

public int getModuleNumber()
Gets the number of the analog module this channel is on.

Returns:
The module number of the analog module this channel is on.

setAverageBits

public void setAverageBits(int bits)
Set the number of averaging bits. This sets the number of averaging bits. The actual number of averaged samples is 2**bits. The averaging is done automatically in the FPGA.

Parameters:
bits - The number of averaging bits.

getAverageBits

public int getAverageBits()
Get the number of averaging bits. This gets the number of averaging bits from the FPGA. The actual number of averaged samples is 2**bits. The averaging is done automatically in the FPGA.

Returns:
The number of averaging bits.

setOversampleBits

public void setOversampleBits(int bits)
Set the number of oversample bits. This sets the number of oversample bits. The actual number of oversampled values is 2**bits. The oversampling is done automatically in the FPGA.

Parameters:
bits - The number of oversample bits.

getOversampleBits

public int getOversampleBits()
Get the number of oversample bits. This gets the number of oversample bits from the FPGA. The actual number of oversampled values is 2**bits. The oversampling is done automatically in the FPGA.

Returns:
The number of oversample bits.

initAccumulator

public void initAccumulator()
Initialize the accumulator.


setAccumulatorInitialValue

public void setAccumulatorInitialValue(long initialValue)
Set an inital value for the accumulator. This will be added to all values returned to the user.

Parameters:
initialValue - The value that the accumulator should start from when reset.

resetAccumulator

public void resetAccumulator()
Resets the accumulator to the initial value.


setAccumulatorCenter

public void setAccumulatorCenter(int center)
Set the center value of the accumulator. The center value is subtracted from each A/D value before it is added to the accumulator. This is used for the center value of devices like gyros and accelerometers to make integration work and to take the device offset into account when integrating. This center value is based on the output of the oversampled and averaged source from channel 1. Because of this, any non-zero oversample bits will affect the size of the value for this field.


setAccumulatorDeadband

public void setAccumulatorDeadband(int deadband)
Set the accumulator's deadband.


getAccumulatorValue

public long getAccumulatorValue()
Read the accumulated value. Read the value that has been accumulating on channel 1. The accumulator is attached after the oversample and average engine.

Returns:
The 64-bit value accumulated since the last Reset().

getAccumulatorCount

public long getAccumulatorCount()
Read the number of accumulated values. Read the count of the accumulated values since the accumulator was last Reset().

Returns:
The number of times samples from the channel were accumulated.

getAccumulatorOutput

public void getAccumulatorOutput(AccumulatorResult result)
Read the accumulated value and the number of accumulated values atomically. This function reads the value and count from the FPGA atomically. This can be used for averaging.

Parameters:
result - AccumulatorResult object to store the results in.

isAccumulatorChannel

public boolean isAccumulatorChannel()
Is the channel attached to an accumulator.

Returns:
The analog channel is attached to an accumulator.

setVoltageForPID

public void setVoltageForPID(boolean shouldUseVoltageForPID)
Set whether to use voltage of value for PIDGet This method determines whether PIDGet uses average voltage or value for PID controllers for a particular channel. This is to preserve compatibility with existing programs and is likely to change in favor of voltage for RoboRIO.

Parameters:
m_shouldUseVoltageForPID - True if voltage should be used for PIDGet. The default is to use the value as it has been since the creation of the library.

pidGet

public double pidGet()
Get the average value for use with PIDController. This can be changed to use average voltage by calling setVoltageForPID().

Specified by:
pidGet in interface PIDSource
Returns:
the average value

getSmartDashboardType

public String getSmartDashboardType()
Specified by:
getSmartDashboardType in interface Sendable
Returns:
the string representation of the named data type that will be used by the smart dashboard for this sendable

initTable

public void initTable(ITable subtable)
Initializes a table for this sendable object.

Specified by:
initTable in interface Sendable
Parameters:
subtable - The table to put the values in.

updateTable

public void updateTable()
Update the table for this sendable object with the latest values.

Specified by:
updateTable in interface LiveWindowSendable

getTable

public ITable getTable()

Specified by:
getTable in interface Sendable
Returns:
the table that is currently associated with the sendable

startLiveWindowMode

public void startLiveWindowMode()
Analog Channels don't have to do anything special when entering the LiveWindow. Start having this sendable object automatically respond to value changes reflect the value on the table.

Specified by:
startLiveWindowMode in interface LiveWindowSendable

stopLiveWindowMode

public void stopLiveWindowMode()
Analog Channels don't have to do anything special when exiting the LiveWindow. Stop having this sendable object automatically respond to value changes.

Specified by:
stopLiveWindowMode in interface LiveWindowSendable

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"