This example explains how to use an encoder to determine the direction and rate of a motor controlled by your roboRIO. Encoder functions can be found in the Encoder subpalette, within the Sensors subpalette of the WPI Robotics Library palette on the block diagram.
These functions work specifically for a quadrature encoder, which contains two rotating disks A and B. Digital pulse outputs from A and B translate into speed, depending on the frequency of pulses, and direction, depending on the which disk’s pulse is detected first.
Connect your quadrature encoder to the DIO pins on the roboRIO such that encoder outputs A and B represent two separate DIO lines. Refer to the diagram shown on the front panel of the MotorwithEncoder.vi example for further direction. (Help > Find Examples > FRC Robotics > roboRIO > Robot and Motor)
How to include in 2015 Robot Project:
The WPI_EncoderOpen.vi automatically creates an encoder reference from two DIO inputs. (LabVIEW will generate two WPI_DigitalInputOpen.vi’s and convert these to source inputs for this VI). This reference can be passed to WPI_EncoderConfigureTimer.vi, which allows for further configuration of the encoder with inputs that specify the number of pulses to average for rpm calculations, as well as the minimum pulse rate before the encoder is considered stopped.
Robot Main VI
The WPI_EncoderGet.vi is used to return information from the encoder about count, direction, and period of pulses, or if the encoder is stopped. Additionally, the WPI_EncoderReset.vi can be used to reset the encoder to 0 between code executions.
The WPI_EncoderClose.vi is used to close the reference to the encoder.
Automated Test Product Marketing Engineer National Instruments