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.AnalogGyro;
008import edu.wpi.first.wpilibj.AnalogInput;
009import edu.wpi.first.wpilibj.PIDSource;
010import edu.wpi.first.wpilibj.PIDSourceType;
011
012/**
013 * Wrapper so that PIDSource is implemented for AnalogGyro 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 PIDAnalogGyro extends AnalogGyro implements PIDSource {
020  private PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
021
022  public PIDAnalogGyro(int channel) {
023    super(channel);
024  }
025
026  public PIDAnalogGyro(AnalogInput channel) {
027    super(channel);
028  }
029
030  public PIDAnalogGyro(int channel, int center, double offset) {
031    super(channel, center, offset);
032  }
033
034  public PIDAnalogGyro(AnalogInput channel, int center, double offset) {
035    super(channel, center, offset);
036  }
037
038  /**
039   * Set which parameter of the gyro you are using as a process control variable. The Gyro class
040   * supports the rate and displacement parameters
041   *
042   * @param pidSource An enum to select the parameter.
043   */
044  @Override
045  public void setPIDSourceType(PIDSourceType pidSource) {
046    m_pidSource = pidSource;
047  }
048
049  @Override
050  public PIDSourceType getPIDSourceType() {
051    return m_pidSource;
052  }
053
054  /**
055   * Get the output of the gyro for use with PIDControllers. May be the angle or rate depending on
056   * the set PIDSourceType
057   *
058   * @return the output according to the gyro
059   */
060  @Override
061  public double pidGet() {
062    switch (m_pidSource) {
063      case kRate:
064        return getRate();
065      case kDisplacement:
066        return getAngle();
067      default:
068        return 0.0;
069    }
070  }
071}