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; 006 007/** 008 * Interface for counting the number of ticks on a digital input channel. Encoders, Gear tooth 009 * sensors, and counters should all subclass this in order to build more advanced classes for 010 * control and driving. 011 * 012 * <p>All counters will immediately start counting - reset() them if you need them to be zeroed 013 * before use. 014 */ 015public interface CounterBase { 016 /** The number of edges for the CounterBase to increment or decrement on. */ 017 enum EncodingType { 018 /** Count only the rising edge. */ 019 k1X(0), 020 /** Count both the rising and falling edge. */ 021 k2X(1), 022 /** Count rising and falling on both channels. */ 023 k4X(2); 024 025 public final int value; 026 027 EncodingType(int value) { 028 this.value = value; 029 } 030 } 031 032 /** 033 * Get the count. 034 * 035 * @return the count 036 */ 037 int get(); 038 039 /** Reset the count to zero. */ 040 void reset(); 041 042 /** 043 * Get the time between the last two edges counted. 044 * 045 * @return the time between the last two ticks in seconds 046 */ 047 double getPeriod(); 048 049 /** 050 * Set the maximum time between edges to be considered stalled. 051 * 052 * @param maxPeriod the maximum period in seconds 053 */ 054 void setMaxPeriod(double maxPeriod); 055 056 /** 057 * Determine if the counter is not moving. 058 * 059 * @return true if the counter has not changed for the max period 060 */ 061 boolean getStopped(); 062 063 /** 064 * Determine which direction the counter is going. 065 * 066 * @return true for one direction, false for the other 067 */ 068 boolean getDirection(); 069}