001/*----------------------------------------------------------------------------*/ 002/* Copyright (c) FIRST 2015-2017. All Rights Reserved. */ 003/* Open Source Software - may be modified and shared by FRC teams. The code */ 004/* must be accompanied by the FIRST BSD license file in the root directory of */ 005/* the project. */ 006/*----------------------------------------------------------------------------*/ 007 008package edu.wpi.first.wpilibj.filters; 009 010import edu.wpi.first.wpilibj.PIDSource; 011import edu.wpi.first.wpilibj.PIDSourceType; 012 013/** 014 * Superclass for filters. 015 */ 016public abstract class Filter implements PIDSource { 017 private PIDSource m_source; 018 019 public Filter(PIDSource source) { 020 m_source = source; 021 } 022 023 @Override 024 public void setPIDSourceType(PIDSourceType pidSource) { 025 m_source.setPIDSourceType(pidSource); 026 } 027 028 @Override 029 public PIDSourceType getPIDSourceType() { 030 return m_source.getPIDSourceType(); 031 } 032 033 @Override 034 public abstract double pidGet(); 035 036 /** 037 * Returns the current filter estimate without also inserting new data as pidGet() would do. 038 * 039 * @return The current filter estimate 040 */ 041 public abstract double get(); 042 043 /** 044 * Reset the filter state. 045 */ 046 public abstract void reset(); 047 048 /** 049 * Calls PIDGet() of source. 050 * 051 * @return Current value of source 052 */ 053 protected double pidGetSource() { 054 return m_source.pidGet(); 055 } 056}