001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.wpilibj.xrp;
006
007import edu.wpi.first.wpilibj.AnalogInput;
008
009/** This class represents the ultrasonic rangefinder on an XRP robot. */
010public class XRPRangefinder {
011  private final AnalogInput m_rangefinder = new AnalogInput(2);
012
013  /**
014   * Constructs an XRPRangefinder.
015   *
016   * <p>Only one instance of a XRPRangefinder is supported.
017   */
018  public XRPRangefinder() {}
019
020  /**
021   * Get the measured distance in meters. Distance further than 4m will be reported as 4m.
022   *
023   * @return distance in meters
024   */
025  public double getDistance() {
026    return (m_rangefinder.getVoltage() / 5.0) * 4.0;
027  }
028}