Skip to content
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

Create a Sharp IR Distance Sensor class #15

Open
kevlam2706 opened this issue Nov 27, 2018 · 2 comments
Open

Create a Sharp IR Distance Sensor class #15

kevlam2706 opened this issue Nov 27, 2018 · 2 comments
Assignees
Labels

Comments

@kevlam2706
Copy link

We used Sharp IR sensors in the last several years' robots. They provide an analog voltage which varies according to the distance to the nearest object. A graph of voltage-versus-distance is provided in the datasheets for these sensors.

It would be useful to have a wrapper class that knows how to interpret the values to turn into a distance, e.g. 2.3 volts = 17 cm, or whatever. Instead of using if/else or case statements, we could come up with a mathematical formula that fits the curve

Hint: people have already written some of these for Arduino - Google them up, find and port them over!

@kevlam2706 kevlam2706 added the rookie friendly Good for newcomers label Nov 27, 2018
@kevlam2706
Copy link
Author

Sharp GP2Y0A21YK0F has a "medium range" of 10-80 cm.

Datasheet: https://www.parallax.com/sites/default/files/downloads/28995-Sharp-GP2Y0A21YK0F-IR-Datasheet.pdf

@kevlam2706
Copy link
Author

One possible approach:

  1. Wire one of these IR sensors to a RoboRio's AIO port.
  2. Write some simple code to read the sensor and output the value to the console or to a dashboard field.
  3. Using a measuring tape, place an object at different distances from the sensor and record the sensor readings. For example, 10cm, 15cm, 20cm, etc.
  4. Plot these values in an Excel graph. It should look similar to the graph in the datasheet.
  5. Use a curve-fitting function in Excel to come up with coefficients of a polynomial.
  6. Now write a sensor wrapper class that uses this formula to interpret the sensor value and return it in a method call.

@kevlam2706 kevlam2706 changed the title Create a generic IR Distance Sensor class Create a Sharp IR Distance Sensor class Nov 28, 2018
@KyleRAnderson KyleRAnderson added this to the Kickoff milestone Nov 30, 2018
@ryanlarkin ryanlarkin removed this from the Kickoff milestone Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants