My team wants to use a photoelectric sensor or photoswitch to measure and manage the rpm of a flywheel shooter. So there’d be something such as retro-reflective tape on the wheel that would trigger the sensor every rotation. The issue we don’t see anyone else talking about is how to get 6,000+ readings per programming cycle. By this, I mean the ~20ms it takes for an FRC Robot to run through it’s commands.
For example, if the wheels are rotating ~6,000 rpm, that means 100 rotations a second that must be counted. If a robot can only retrieve data every ~20ms (it’s not consistently 20ms) , that means there’s ~2 rotations every second.
However, the wheels are not at a constant 6,000 rpm and the data isn’t processed at a constant 20ms, so how do you get around the issue of the wheels rotating too fast for the code to read?
One option is a hardware counter, something the photoelectric sensor connects to that keeps track of how many times it’s triggered and then sends that number when the code asks for it every ~20ms. If this is your solution, do you have the name of the part you used to do this?
Does anyone know of any teams that have done this who’s code is available to read?
What you’ll actually need to do is configure a counter or encoder to the digital input that the sensor is plugged into. This will take care of all of the counting through the FGPA and you just read it like it is a normal encoder.
If you’re using Talon SRXs, they can also read encoders at high speed - plus connecting encoders directly to the SRXs allows you to do cool things like onboard high rate PIDF control. You can read the encoder from the SRX using CANTalon.getPosition()