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