WPILib averaging in AnalogEncoder

Hey, a quick question for the WPILib devs, I noticed that the AnalogEncoder class doesn’t make use of the FPGA averaging possible with AnalogInput. Is there a reason for that? As I understand it, the FPGA can do about 1000X oversampling relative to just doing a single measurement at 50Hz in user code.

?

No particular reason, other than adding configurability makes things difficult. Its possible to just make a local copy of the AnalogEncoder class and try the other modes if you want.

cool, thanks!

You shouldn’t need to make a local copy. Use the version of the AnalogEncoder constructor that takes an AnalogInput, and configure the AnalogInput however you like.

Note that the AnalogEncoder class uses AnalogTriggers to look for rollovers at the FPGA rate, not the code rate, so you wouldn’t want to configure too much averaging to avoid affecting performance.

2 Likes

hm, your point about rollovers made me re-read the code and I’m thinking that it should work fine?

Unless you tell it otherwise, the trigger looks at the non-averaged input, so it should behave the same no matter what averaging is used. There is certainly a weird case where the trigger finds an edge near the end of the averaging period, so that AnalogInput will report a value inconsistent with the trigger, but AnalogEncoder seems to trap that case due to the “try ten times to get the same number two times in a row” logic in get().

Also as i understand it, the reason to make a copy of AnalogEncoder is because it uses getVoltage() which is not averaged; i would change it to use getAverageVoltage().

wdyt?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.