Quote:
Originally Posted by taichichuan
We are using a Grayhill 63R64 encoder with an Arduino mega for the RPMs of our shooter. We opted for that encoder instead of the KOP because the PPR on the KOP encoder is so high that we were concerned at overrunning the Arduino. Further testing shows that the Arduino is easily capable of 30,000 PPS. So, that concern turned out to be bogus. But, using the KOP encoder would require another gearbox up high on our bot that would adversely effect the COG while trying to balance or going over the bump.
The Arduino mega can source the 5V for the Grayhill or the KOP encoder with no problem. We bring the A channel back from the encoder to Digital Pin 2 on the Arduino. The magic you're looking for can be found in the "attachInterrupt" command. Use it to increment a counter on the rising edge of the encoder pulse and then periodically read the pulse count and do your math for the RPM.
We also added the "SimpleTimer" library from the Arduino playground site so we could get updates every 100 ms. This library attaches a timer interrupt to a function so it's called at the interval you desire rather than simply polling the counter.
Our code sends it's output via an Ethernet shield direct to the cRio using UDP. We found some really interesting gotchas with the cRio robot code in that you must read the packets or face the possibility of a robot lockup. So, you'll need a blocking thread to read the socket constantly. Our robot code is written in C++, so creating a thread was pretty easy.
In addition, our Arduino is also sampling an absolute encoder on our ball shooting angle device. No problem doing both functions and sending out the results.
I'd say that the entire Arduino program for both sensors and the Ethernet output is maybe 50 lines of code total.
|
You are blocking what here- or are you saying there is a sync here on this. Using java there is the observer observable classes that I found handled serial come quite nicely.