From 6faa51ff48653aea162cbf4e6a6106b9a3e1755d Mon Sep 17 00:00:00 2001 From: Peter_Mitrano Date: Thu, 31 Dec 2015 01:50:02 -0500 Subject: [PATCH] Renamed Gyro to AnalogGyro to match athena API Removed references to HAL classes, enabling moving of these classes into shared. Change-Id: I8d9053e1046d6fc2a60e13fb29410fd2c95180d2 --- .../java/edu/wpi/first/wpilibj/GyroBase.java | 0 .../edu/wpi/first/wpilibj/SensorBase.java | 3 - .../wpilibj/{Gyro.java => AnalogGyro.java} | 28 ++- .../edu/wpi/first/wpilibj/SensorBase.java | 191 ------------------ 4 files changed, 19 insertions(+), 203 deletions(-) rename wpilibj/src/{athena => shared}/java/edu/wpi/first/wpilibj/GyroBase.java (100%) rename wpilibj/src/{athena => shared}/java/edu/wpi/first/wpilibj/SensorBase.java (98%) rename wpilibj/src/sim/java/edu/wpi/first/wpilibj/{Gyro.java => AnalogGyro.java} (86%) delete mode 100644 wpilibj/src/sim/java/edu/wpi/first/wpilibj/SensorBase.java diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/GyroBase.java b/wpilibj/src/shared/java/edu/wpi/first/wpilibj/GyroBase.java similarity index 100% rename from wpilibj/src/athena/java/edu/wpi/first/wpilibj/GyroBase.java rename to wpilibj/src/shared/java/edu/wpi/first/wpilibj/GyroBase.java diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/src/shared/java/edu/wpi/first/wpilibj/SensorBase.java similarity index 98% rename from wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java rename to wpilibj/src/shared/java/edu/wpi/first/wpilibj/SensorBase.java index 41222ed439..d07a161f5b 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java +++ b/wpilibj/src/shared/java/edu/wpi/first/wpilibj/SensorBase.java @@ -7,9 +7,6 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.wpilibj.hal.DIOJNI; -import edu.wpi.first.wpilibj.hal.AnalogJNI; - /** * Base class for all sensors. Stores most recent status information as well as * containing utility functions for checking channels and error processing. diff --git a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/Gyro.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/AnalogGyro.java similarity index 86% rename from wpilibj/src/sim/java/edu/wpi/first/wpilibj/Gyro.java rename to wpilibj/src/sim/java/edu/wpi/first/wpilibj/AnalogGyro.java index 023044497e..c2cb504cbc 100644 --- a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/Gyro.java +++ b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/AnalogGyro.java @@ -6,21 +6,23 @@ /*----------------------------------------------------------------------------*/ package edu.wpi.first.wpilibj; +import edu.wpi.first.wpilibj.interfaces.Gyro; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.simulation.SimGyro; +import edu.wpi.first.wpilibj.GyroBase; import edu.wpi.first.wpilibj.tables.ITable; /** * Use a rate gyro to return the robots heading relative to a starting position. - * The Gyro class tracks the robots heading based on the starting position. As + * The AnalogGyro class tracks the robots heading based on the starting position. As * the robot rotates the new heading is computed by integrating the rate of * rotation returned by the sensor. When the class is instantiated, it does a * short calibration routine where it samples the gyro while at rest to * determine the default offset. This is subtracted from each sample to * determine the heading. */ -public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable { +public class AnalogGyro extends GyroBase implements Gyro, PIDSource, LiveWindowSendable { private PIDSourceType m_pidSource; private SimGyro impl; @@ -39,28 +41,36 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable { reset(); setPIDSourceType(PIDSourceType.kDisplacement); - LiveWindow.addSensor("Gyro", channel, this); + LiveWindow.addSensor("AnalogGyro", channel, this); } /** - * Gyro constructor with only a channel. + * AnalogGyro constructor with only a channel. * * @param channel * The analog channel the gyro is connected to. */ - public Gyro(int channel) { + public AnalogGyro(int channel) { initGyro(channel); } /** - * Gyro constructor with a precreated analog channel object. Use this + * {@inherit_doc} + */ + public void calibrate(){ + reset(); + } + + + /** + * AnalogGyro constructor with a precreated analog channel object. Use this * constructor when the analog channel needs to be shared. There is no * reference counting when an AnalogChannel is passed to the gyro. * * @param channel * The AnalogChannel object that the gyro is connected to. */ - // Not Supported: public Gyro(AnalogChannel channel) { + // Not Supported: public AnalogGyro(AnalogChannel channel) { /** * Reset the gyro. Resets the gyro to a heading of zero. This can be used if @@ -107,7 +117,7 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable { /** * Set which parameter of the encoder you are using as a process control - * variable. The Gyro class supports the rate and angle parameters + * variable. The AnalogGyro class supports the rate and angle parameters * * @param pidSource * An enum to select the parameter. @@ -143,7 +153,7 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable { * Live Window code, only does anything if live window is activated. */ public String getSmartDashboardType() { - return "Gyro"; + return "AnalogGyro"; } private ITable m_table; diff --git a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/SensorBase.java deleted file mode 100644 index 5c1180ec01..0000000000 --- a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/SensorBase.java +++ /dev/null @@ -1,191 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * Base class for all sensors. - * Stores most recent status information as well as containing utility functions for checking - * channels and error processing. - * - * XXX: Wait, there's no exception thrown if we try to allocate a non-existent module? It that behavior correct? - */ -public abstract class SensorBase { // TODO: Refactor - - // TODO: Move this to the HAL - - /** - * Ticks per microsecond - */ - public static final int kSystemClockTicksPerMicrosecond = 40; - /** - * Number of digital channels per roboRIO - */ - public static final int kDigitalChannels = 26; - /** - * Number of analog input channels - */ - public static final int kAnalogInputChannels = 8; - /** - * Number of analog output channels - */ - public static final int kAnalogOutputChannels = 2; - /** - * Number of solenoid channels per module - */ - public static final int kSolenoidChannels = 8; - /** - * Number of solenoid modules - */ - public static final int kSolenoidModules = 2; - /** - * Number of PWM channels per roboRIO - */ - public static final int kPwmChannels = 20; - /** - * Number of relay channels per roboRIO - */ - public static final int kRelayChannels = 4; - /** - * Number of power distribution channels - */ - public static final int kPDPChannels = 16; - - private static int m_defaultSolenoidModule = 1; - - /** - * Creates an instance of the sensor base and gets an FPGA handle - */ - public SensorBase() { - } - - /** - * Set the default location for the Solenoid module. - * - * @param moduleNumber The number of the solenoid module to use. - */ - public static void setDefaultSolenoidModule(final int moduleNumber) { - checkSolenoidModule(moduleNumber); - SensorBase.m_defaultSolenoidModule = moduleNumber; - } - - /** - * Verify that the solenoid module is correct. - * - * @param moduleNumber The solenoid module module number to check. - */ - protected static void checkSolenoidModule(final int moduleNumber) { -// if(HALLibrary.checkSolenoidModule((byte) (moduleNumber - 1)) != 0) { -// System.err.println("Solenoid module " + moduleNumber + " is not present."); -// } - } - - /** - * Check that the digital channel number is valid. - * Verify that the channel number is one of the legal channel numbers. Channel numbers are - * 1-based. - * - * @param channel The channel number to check. - */ - protected static void checkDigitalChannel(final int channel) { - if (channel <= 0 || channel > kDigitalChannels) { - System.err.println("Requested digital channel number is out of range."); - } - } - - /** - * Check that the digital channel number is valid. - * Verify that the channel number is one of the legal channel numbers. Channel numbers are - * 1-based. - * - * @param channel The channel number to check. - */ - protected static void checkRelayChannel(final int channel) { - if (channel <= 0 || channel > kRelayChannels) { - System.err.println("Requested relay channel number is out of range."); - throw new IndexOutOfBoundsException("Requested relay channel number is out of range."); - } - } - - /** - * Check that the digital channel number is valid. - * Verify that the channel number is one of the legal channel numbers. Channel numbers are - * 1-based. - * - * @param channel The channel number to check. - */ - protected static void checkPWMChannel(final int channel) { - if (channel <= 0 || channel > kPwmChannels) { - System.err.println("Requested PWM channel number is out of range."); - throw new IndexOutOfBoundsException("Requested PWM channel number is out of range."); - } - } - - /** - * Check that the analog input number is value. - * Verify that the analog input number is one of the legal channel numbers. Channel numbers - * are 0-based. - * - * @param channel The channel number to check. - */ - protected static void checkAnalogInputChannel(final int channel) { - if (channel <= 0 || channel > kAnalogInputChannels) { - System.err.println("Requested analog channel number is out of range."); - } - } - - /** - * Check that the analog input number is value. - * Verify that the analog input number is one of the legal channel numbers. Channel numbers - * are 0-based. - * - * @param channel The channel number to check. - */ - protected static void checkAnalogOutputChannel(final int channel) { - if (channel <= 0 || channel > kAnalogOutputChannels) { - System.err.println("Requested analog channel number is out of range."); - } - } - - /** - * Verify that the solenoid channel number is within limits. Channel numbers - * are 1-based. - * - * @param channel The channel number to check. - */ - protected static void checkSolenoidChannel(final int channel) { - if (channel <= 0 || channel > kSolenoidChannels) { - System.err.println("Requested solenoid channel number is out of range."); - } - } - - /** - * Verify that the power distribution channel number is within limits. - * Channel numbers are 1-based. - * - * @param channel The channel number to check. - */ - protected static void checkPDPChannel(final int channel) { - if (channel <= 0 || channel > kPDPChannels) { - System.err.println("Requested solenoid channel number is out of range."); - } - } - - /** - * Get the number of the default solenoid module. - * - * @return The number of the default solenoid module. - */ - public static int getDefaultSolenoidModule() { - return SensorBase.m_defaultSolenoidModule; - } - - /** - * Free the resources used by this object - */ - public void free() {} -}