#include <DriverStationEnhancedIO.h>
Public Member Functions | |
double | GetAcceleration (tAccelChannel channel) |
double | GetAnalogIn (uint32_t channel) |
double | GetAnalogInRatio (uint32_t channel) |
double | GetAnalogOut (uint32_t channel) |
void | SetAnalogOut (uint32_t channel, double value) |
bool | GetButton (uint32_t channel) |
uint8_t | GetButtons () |
void | SetLED (uint32_t channel, bool value) |
void | SetLEDs (uint8_t value) |
bool | GetDigital (uint32_t channel) |
uint16_t | GetDigitals () |
void | SetDigitalOutput (uint32_t channel, bool value) |
tDigitalConfig | GetDigitalConfig (uint32_t channel) |
void | SetDigitalConfig (uint32_t channel, tDigitalConfig config) |
double | GetPWMPeriod (tPWMPeriodChannels channels) |
void | SetPWMPeriod (tPWMPeriodChannels channels, double period) |
bool | GetFixedDigitalOutput (uint32_t channel) |
void | SetFixedDigitalOutput (uint32_t channel, bool value) |
int16_t | GetEncoder (uint32_t encoderNumber) |
void | ResetEncoder (uint32_t encoderNumber) |
bool | GetEncoderIndexEnable (uint32_t encoderNumber) |
void | SetEncoderIndexEnable (uint32_t encoderNumber, bool enable) |
double | GetTouchSlider () |
double | GetPWMOutput (uint32_t channel) |
void | SetPWMOutput (uint32_t channel, double value) |
uint8_t | GetFirmwareVersion () |
Public Member Functions inherited from ErrorBase | |
virtual Error & | GetError () |
Retrieve the current error. Get the current error information associated with this sensor. | |
virtual const Error & | GetError () const |
virtual void | SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (ErrorBase *rhs) const |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Friends | |
class | DriverStation |
Additional Inherited Members | |
Static Public Member Functions inherited from ErrorBase | |
static void | SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static void | SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static Error & | GetGlobalError () |
Protected Member Functions inherited from ErrorBase | |
ErrorBase () | |
Initialize the instance status to 0 for now. | |
Protected Attributes inherited from ErrorBase | |
Error | m_error |
Static Protected Attributes inherited from ErrorBase | |
static SEM_ID | _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE) |
static Error | _globalError |
Interact with the more complete I/O available from the newest driver station. Get a reference to an object of this type by calling GetEnhancedIO() on the DriverStation object.
double DriverStationEnhancedIO::GetAcceleration | ( | tAccelChannel | channel | ) |
Query an accelerometer channel on the DS IO.
channel | The channel number to read. |
double DriverStationEnhancedIO::GetAnalogIn | ( | uint32_t | channel | ) |
Query an analog input channel on the DS IO.
channel | The channel number to read. [1,8] |
double DriverStationEnhancedIO::GetAnalogInRatio | ( | uint32_t | channel | ) |
Query an analog input channel on the DS IO in ratiometric form.
channel | The channel number to read. [1,8] |
double DriverStationEnhancedIO::GetAnalogOut | ( | uint32_t | channel | ) |
Query the voltage currently being output.
AO1 is pin 11 on the top connector (P2). AO2 is pin 12 on the top connector (P2).
channel | The analog output channel on the DS IO. [1,2] |
bool DriverStationEnhancedIO::GetButton | ( | uint32_t | channel | ) |
Get the state of a button on the IO board.
Button1 is the physical button "S1". Button2 is pin 4 on the top connector (P2). Button3 is pin 6 on the top connector (P2). Button4 is pin 8 on the top connector (P2). Button5 is pin 10 on the top connector (P2). Button6 is pin 7 on the top connector (P2).
Button2 through Button6 are Capacitive Sense buttons.
channel | The button channel to read. [1,6] |
uint8_t DriverStationEnhancedIO::GetButtons | ( | ) |
Get the state of all the button channels.
bool DriverStationEnhancedIO::GetDigital | ( | uint32_t | channel | ) |
Get the current state of a DIO channel regardless of mode.
channel | The DIO channel to read. [1,16] |
DriverStationEnhancedIO::tDigitalConfig DriverStationEnhancedIO::GetDigitalConfig | ( | uint32_t | channel | ) |
Get the current configuration for a DIO line.
This has the side effect of forcing the Driver Station to switch to Enhanced mode if it's not when called. If Enhanced mode is not enabled when this is called, it will return kUnknown.
channel | The DIO channel config to get. [1,16] |
uint16_t DriverStationEnhancedIO::GetDigitals | ( | ) |
Get the state of all 16 DIO lines regardless of mode.
int16_t DriverStationEnhancedIO::GetEncoder | ( | uint32_t | encoderNumber | ) |
Get the position of a quadrature encoder.
There are two signed 16-bit 4X quadrature decoders on the IO board. These decoders are always monitoring the state of the lines assigned to them, but these lines do not have to be used for encoders.
Encoder1 uses DIO4 for "A", DIO6 for "B", and DIO8 for "Index". Encoder2 uses DIO5 for "A", DIO7 for "B", and DIO9 for "Index".
The index functionality can be enabled or disabled using SetEncoderIndexEnable().
encoderNumber | The quadrature encoder to access. [1,2] |
bool DriverStationEnhancedIO::GetEncoderIndexEnable | ( | uint32_t | encoderNumber | ) |
Get the current configuration of a quadrature encoder index channel.
This has the side effect of forcing the Driver Station to switch to Enhanced mode if it's not when called. If Enhanced mode is not enabled when this is called, it will return false.
encoderNumber | The quadrature encoder. [1,2] |
uint8_t DriverStationEnhancedIO::GetFirmwareVersion | ( | ) |
Get the firmware version running on the IO board.
This also has the side effect of forcing the driver station to switch to Enhanced mode if it is not. If you plan to switch between Driver Stations with unknown IO configurations, you can call this until it returns a non-0 version to ensure that this API is accessible before proceeding.
bool DriverStationEnhancedIO::GetFixedDigitalOutput | ( | uint32_t | channel | ) |
Get the state being output on a fixed digital output.
channel | The FixedDO line to get. [1,2] |
double DriverStationEnhancedIO::GetPWMOutput | ( | uint32_t | channel | ) |
double DriverStationEnhancedIO::GetPWMPeriod | ( | tPWMPeriodChannels | channels | ) |
Get the period of a PWM generator.
This has the side effect of forcing the Driver Station to switch to Enhanced mode if it's not when called. If Enhanced mode is not enabled when this is called, it will return 0.
channels | Select the generator by specifying the two channels to which it is connected. |
double DriverStationEnhancedIO::GetTouchSlider | ( | ) |
Get the value of the Capacitive Sense touch slider.
void DriverStationEnhancedIO::ResetEncoder | ( | uint32_t | encoderNumber | ) |
Reset the position of an encoder to 0.
This simply stores an offset locally. It does not reset the hardware counter on the IO board. If you use this method with Index enabled, you may get unexpected results.
encoderNumber | The quadrature encoder to reset. [1,2] |
void DriverStationEnhancedIO::SetAnalogOut | ( | uint32_t | channel, |
double | value | ||
) |
Set the analog output voltage.
AO1 is pin 11 on the top connector (P2). AO2 is pin 12 on the top connector (P2). AO1 is the reference voltage for the 2 analog comparators on DIO15 and DIO16.
The output range is 0V to 4V, however due to the supply voltage don't expect more than about 3V. Current supply capability is only 100uA.
channel | The analog output channel on the DS IO. [1,2] |
value | The voltage to output on the channel. |
void DriverStationEnhancedIO::SetDigitalConfig | ( | uint32_t | channel, |
tDigitalConfig | config | ||
) |
Override the DS's configuration of a DIO line.
If configured to kInputFloating, the selected DIO line will be tri-stated with no internal pull resistor.
If configured to kInputPullUp, the selected DIO line will be tri-stated with a 5k-Ohm internal pull-up resistor enabled.
If configured to kInputPullDown, the selected DIO line will be tri-stated with a 5k-Ohm internal pull-down resistor enabled.
If configured to kOutput, the selected DIO line will actively drive to 0V or Vddio (specified by J1 and J4). DIO1 through DIO12, DIO15, and DIO16 can source 4mA and can sink 8mA. DIO12 and DIO13 can source 4mA and can sink 25mA.
In addition to the common configurations, DIO1 through DIO4 can be configured to kPWM to enable PWM output.
In addition to the common configurations, DIO15 and DIO16 can be configured to kAnalogComparator to enable analog comparators on those 2 DIO lines. When enabled, the lines are tri-stated and will accept analog voltages between 0V and 3.3V. If the input voltage is greater than the voltage output by AO1, the DIO will read as true, if less then false.
channel | The DIO line to configure. [1,16] |
config | The mode to put the DIO line in. |
void DriverStationEnhancedIO::SetDigitalOutput | ( | uint32_t | channel, |
bool | value | ||
) |
Set the state of a DIO line that is configured for digital output.
channel | The DIO channel to set. [1,16] |
value | The state to set the selected channel to. |
void DriverStationEnhancedIO::SetEncoderIndexEnable | ( | uint32_t | encoderNumber, |
bool | enable | ||
) |
Enable or disable the index channel of a quadrature encoder.
The quadrature decoders on the IO board support an active-low index input.
Encoder1 uses DIO8 for "Index". Encoder2 uses DIO9 for "Index".
When enabled, the decoder's counter will be reset to 0 when A, B, and Index are all low.
encoderNumber | The quadrature encoder. [1,2] |
enable | If true, reset the encoder in an index condition. |
void DriverStationEnhancedIO::SetFixedDigitalOutput | ( | uint32_t | channel, |
bool | value | ||
) |
Set the state to output on a Fixed High Current Digital Output line.
FixedDO1 is pin 5 on the top connector (P2). FixedDO2 is pin 3 on the top connector (P2).
The FixedDO lines always output 0V and 3.3V regardless of J1 and J4. They can source 4mA and can sink 25mA. Because of this, they are expected to be used in an active low configuration, such as connecting to the cathode of a bright LED. Because they are expected to be active low, they default to true.
channel | The FixedDO channel to set. |
value | The state to set the FixedDO. |
void DriverStationEnhancedIO::SetLED | ( | uint32_t | channel, |
bool | value | ||
) |
Set the state of an LED on the IO board.
channel | The LED channel to set. [1,8] |
value | True to turn the LED on. |
void DriverStationEnhancedIO::SetLEDs | ( | uint8_t | value | ) |
Set the state of all 8 LEDs on the IO board.
value | The state of each LED. LED1 is lsb and LED8 is msb. |
void DriverStationEnhancedIO::SetPWMOutput | ( | uint32_t | channel, |
double | value | ||
) |
Set the percent duty-cycle to output on a PWM enabled DIO line.
DIO1 through DIO4 have the ability to output a PWM signal. The period of the signal can be configured in pairs using SetPWMPeriod().
void DriverStationEnhancedIO::SetPWMPeriod | ( | tPWMPeriodChannels | channels, |
double | period | ||
) |
Set the period of a PWM generator.
There are 2 PWM generators on the IO board. One can generate PWM signals on DIO1 and DIO2, the other on DIO3 and DIO4. Each generator has one counter and two compare registers. As such, each pair of PWM outputs share the output period but have independent duty cycles.
channels | Select the generator by specifying the two channels to which it is connected. |
period | The period of the PWM generator in seconds. [0.0,0.002731] |