-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Feature to Get Encoder Rate (Period) #40
Conversation
@beardedone55 could you rebase against main? I just upgraded the build tooling so this should get the CI build working again |
The servo is using one of the PIOs, so there isn't enough room to have 4 separate state machines running for both the Encoder tick counter and the encoder period counter. This change replaces the encoder PIO program with one that will output the time between encoder pulses to its RX FIFO. Instead of having the PIO program keep track of the encoder tick count, the robot code will count the number of items it pulls from the RX FIFO (there will be one for each encoder tick) and keep track of the count itself. Only the encoder period (time between pulses) will be calculated in the PIO.
Encoder Channel A and B are not 90 degrees out of phase; therefore, at minimum, 2 consecutive periods have to be averaged together to obtain the current encoder speed. After some experimentation, I got the best results if I averaged 8 consecutive periods together, so I've set that as the default and added a function to change the number of samples to average in case someone wants to make it configurable in the future.
Done. |
Sorry for the delay in reviewing/merging this in @beardedone55 , but this looks good to go now! |
Great! Thank you! |
@beardedone55 feel free to put in a PR to allwpilib with the necessary halsim_xrp changes. Thanks again for the help with the firmware :) |
I've submitted pull request wpilibsuite/allwpilib#6795 with the necessary halsim_xrp changes. |
This change addresses issue #39. It adds code to calculate the encoder period (time between encoder pulses) and sends the data from the XRP to the robot code on the PC running the simulation. This change will allow the robot code to determine the motor speeds on the XRP using the Encoder::getRate() function.
For this to work, a corresponding change is necessary in WPILIB. I've included the change below. I've made sure that both this change and the change I am proposing for WPILIB are backward compatible. If this change is accepted, I will submit my WPILIB change for inclusion in their repository.