001/*----------------------------------------------------------------------------*/ 002/* Copyright (c) FIRST 2008-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; 009 010import edu.wpi.first.wpilibj.interfaces.Gyro; 011import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; 012import edu.wpi.first.wpilibj.tables.ITable; 013 014/** 015 * GyroBase is the common base class for Gyro implementations such as AnalogGyro. 016 */ 017public abstract class GyroBase extends SensorBase implements Gyro, PIDSource, LiveWindowSendable { 018 private PIDSourceType m_pidSource = PIDSourceType.kDisplacement; 019 020 /** 021 * Set which parameter of the gyro you are using as a process control variable. The Gyro class 022 * supports the rate and displacement parameters 023 * 024 * @param pidSource An enum to select the parameter. 025 */ 026 @Override 027 public void setPIDSourceType(PIDSourceType pidSource) { 028 m_pidSource = pidSource; 029 } 030 031 @Override 032 public PIDSourceType getPIDSourceType() { 033 return m_pidSource; 034 } 035 036 /** 037 * Get the output of the gyro for use with PIDControllers. May be the angle or rate depending on 038 * the set PIDSourceType 039 * 040 * @return the output according to the gyro 041 */ 042 @Override 043 public double pidGet() { 044 switch (m_pidSource) { 045 case kRate: 046 return getRate(); 047 case kDisplacement: 048 return getAngle(); 049 default: 050 return 0.0; 051 } 052 } 053 054 /* 055 * Live Window code, only does anything if live window is activated. 056 */ 057 @Override 058 public String getSmartDashboardType() { 059 return "Gyro"; 060 } 061 062 private ITable m_table; 063 064 065 @Override 066 public void initTable(ITable subtable) { 067 m_table = subtable; 068 updateTable(); 069 } 070 071 @Override 072 public ITable getTable() { 073 return m_table; 074 } 075 076 @Override 077 public void updateTable() { 078 if (m_table != null) { 079 m_table.putNumber("Value", getAngle()); 080 } 081 } 082 083 @Override 084 public void startLiveWindowMode() { 085 } 086 087 @Override 088 public void stopLiveWindowMode() { 089 } 090}