Library for WPILibJ distance sensors
Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
.travis.yml
LICENCE
README.md
pom.xml

README.md

DistanceSensorLib Build Status

DistanceSensorLib is a library for using distance sensors in WPILib.

Using the Library

Make an instance of the class for your distance sensor:

GP2Y0A02YK0F sensor = new GP2Y0A02YK0F(new AnalogInput(2));

This code creates GP2Y0A02YK0F distance sensor on port 2. In general, the distance sensor constructor only needs an AnalogInput as an argument, however you should look at the Javadocs for the specific sensor you wish to use. Some have special requirements.

Now, you can read distances from the object. Try to read distances:

sensor.getDistanceCentimeters(); //Double representing distance in centimeters
sensor.getDistanceInches(); //Double representing distance in centimeters

If you need to work with the AnalogInput directly, you can get it with the getAnalogInput method:

sensor.getAnalogInput().getVoltage();

Supported Sensors

Maxbotix

  • LV-MaxSonar-EZ0
  • LV-MaxSonar-EZ1
  • LV-MaxSonar-EZ2
  • LV-MaxSonar-EZ3
  • LV-MaxSonar-EZ4

Sharp

  • GP2D120XJ00F
  • GP2Y0A02YK0F

Supporting More Sensors

Quick guide for adding more distance sensors to the library. If the instructions don't make sense then take a look at the source code for one of the existing sensor classes, or create a new issue with the "new distance sensor" label.

The Class

  • Should be called org.robockets.distancesensorlib.<MANUFACTURER>.<MODELNAME>
    • For example, the Sharp GP2D120XJ00F would be org.robockets.distancesensorlib.sharp.GP2D120XJ00F
  • Should extend org.robockets.distancesensorlib.DistanceSensor

The Constructor

  • Should include a call to super(AnalogInput)
  • Should at the very least take an edu.wpi.first.wpilibj.AnalogInput for an argument. More arguments can be used if the sensor needs more information

The getDistance...() Methods

  • The method that calculates the distance from a voltage value should be the method for the unit of measurement that the sensors datasheet uses
  • The other method should use org.robockets.distancesensorlib.DistanceMeasurementConverter to convert the value from the previous method and return that

The Documentation

  • At the very least, add a Javadoc for the class with the sensor's range, the formula being used to calculate distances, and a link to a datasheet.

The Tests

  • Please add a class with JUnit tests for your sensor. You should at least add one test that gives your class different voltage values and checks the returned value
    • Example of using Mockito to test AnalogInputs without an actual robot.
  • File for the test class should be in the same package as the main class, but in the test directory instead of main
  • The test class should have the same name as the main class it tests, but with the word Test on the beginning