Add more accurate distance calculation constants for Sharp GP2Y0A21YK IR Sensor#2
Open
macuser47 wants to merge 1 commit into
Open
Add more accurate distance calculation constants for Sharp GP2Y0A21YK IR Sensor#2macuser47 wants to merge 1 commit into
macuser47 wants to merge 1 commit into
Conversation
This commit changes the conversion constants for the Sharp GP2Y0A21YK example based on data points extracted from the datasheet. A graph detailing the accuracy of the new approximation can be found at https://www.desmos.com/calculator/fivql4vfdm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes make the distance calculation for the Sharp GP2Y0A21YK IR Sensor more accurate, particularly in the 30-80cm range.
I extracted the points shown in the chart for distance vs voltage in the GP2Y0A21YK datasheet with WebPlotDigitizer and plotted them in desmos. This showed that the current formula for computing distance isn't very good, so I adjusted the constants for a better fit and tried them out on my sensor. You can see the plots here: https://www.desmos.com/calculator/fivql4vfdm
Here are the results I collected, using a dollar bill for measuring out lengths and comparing measured results for a piece of white paper at the given distance:
So it seems like these improvements manifest in real-world results with the sensor.