|
Re: How to interface with absolute encoder using WPILib?
Quote:
Originally Posted by urg8rb8
I am using the following absolute encoder:
http://www.mouser.com/ds/2/54/EMS22A-50229.pdf
I has one digital out pin that spits out the position (0-1024) of the encoder. I have used two-channel encoders in the past with no issues but trying to figure out how to use the WPILib classes to read the position of this new absolute encoder. For some reason I'm having troubling finding sample code.
|
This encoder has a microcontroller in it and so the roboRio needs to generate a clock and chip select to get the serialized data back. There's no built in support for this device in WPILib, but you might try using the SPI class (and the dedicated pins for it), as SPI should be able to generate signaling similar to what this device needs. Hook up SCLK to the clock, CS0 to the chip select, and MISO to the data output. Based on the timing diagram you might need to artifically increase the length of the data and ignore some of the bits to meet the minimum CS timing before and after the data. You'll need to get the clock polarity settings correct for the device as well.
In the worst case you could probably bit-bang it (e.g. drive the clock and chip select pins as DigitalOutputs and use a DigitalInput to read the shifted serial data) but I'd see that as a last resort as it's significantly slower and processor intensive.
__________________
Author of cscore - WPILib CameraServer for 2017+
Author of ntcore - WPILib NetworkTables for 2016+
Creator of RobotPy - Python for FRC
2010 FRC World Champions ( 294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Last edited by Peter Johnson : 21-01-2017 at 12:35.
|