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.pidwrappers; 006 007import edu.wpi.first.wpilibj.DigitalInput; 008import edu.wpi.first.wpilibj.DigitalOutput; 009import edu.wpi.first.wpilibj.PIDSource; 010import edu.wpi.first.wpilibj.PIDSourceType; 011import edu.wpi.first.wpilibj.Ultrasonic; 012 013/** 014 * Wrapper so that PIDSource is implemented for Ultrasonic for old PIDController. 015 * 016 * @deprecated Use {@link edu.wpi.first.math.controller.PIDController} which doesn't require this 017 * wrapper. 018 */ 019@Deprecated(since = "2022", forRemoval = true) 020public class PIDUltrasonic extends Ultrasonic implements PIDSource { 021 protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement; 022 023 public PIDUltrasonic(int pingChannel, int echoChannel) { 024 super(pingChannel, echoChannel); 025 } 026 027 public PIDUltrasonic(DigitalOutput pingChannel, DigitalInput echoChannel) { 028 super(pingChannel, echoChannel); 029 } 030 031 @Override 032 public void setPIDSourceType(PIDSourceType pidSource) { 033 if (!pidSource.equals(PIDSourceType.kDisplacement)) { 034 throw new IllegalArgumentException("Only displacement PID is allowed for ultrasonics."); 035 } 036 m_pidSource = pidSource; 037 } 038 039 @Override 040 public PIDSourceType getPIDSourceType() { 041 return m_pidSource; 042 } 043 044 /** 045 * Get the range in the inches for the PIDSource base object. 046 * 047 * @return The range in inches 048 */ 049 @Override 050 public double pidGet() { 051 return getRangeInches(); 052 } 053}