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.AnalogInput;
008import edu.wpi.first.wpilibj.AnalogPotentiometer;
009import edu.wpi.first.wpilibj.PIDSource;
010import edu.wpi.first.wpilibj.PIDSourceType;
011
012/**
013 * Wrapper so that PIDSource is implemented for AnalogPotentiometer for old PIDController.
014 *
015 * @deprecated Use {@link edu.wpi.first.math.controller.PIDController} which doesn't require this
016 *     wrapper.
017 */
018@Deprecated(since = "2022", forRemoval = true)
019public class PIDAnalogPotentiometer extends AnalogPotentiometer implements PIDSource {
020  protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
021
022  public PIDAnalogPotentiometer(int channel, double fullRange, double offset) {
023    super(channel, fullRange, offset);
024  }
025
026  public PIDAnalogPotentiometer(AnalogInput input, double fullRange, double offset) {
027    super(input, fullRange, offset);
028  }
029
030  public PIDAnalogPotentiometer(int channel, double scale) {
031    super(channel, scale);
032  }
033
034  public PIDAnalogPotentiometer(AnalogInput input, double scale) {
035    super(input, scale);
036  }
037
038  public PIDAnalogPotentiometer(int channel) {
039    super(channel);
040  }
041
042  public PIDAnalogPotentiometer(AnalogInput input) {
043    super(input);
044  }
045
046  @Override
047  public void setPIDSourceType(PIDSourceType pidSource) {
048    if (!pidSource.equals(PIDSourceType.kDisplacement)) {
049      throw new IllegalArgumentException("Only displacement PID is allowed for potentiometers.");
050    }
051    m_pidSource = pidSource;
052  }
053
054  @Override
055  public PIDSourceType getPIDSourceType() {
056    return m_pidSource;
057  }
058
059  /**
060   * Implement the PIDSource interface.
061   *
062   * @return The current reading.
063   */
064  @Override
065  public double pidGet() {
066    return get();
067  }
068}