Add more accurate distance calculation constants for Sharp GP2Y0A21YK IR Sensor #2
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.