diff --git a/hal/include/HAL/Constants.h b/hal/include/HAL/Constants.h new file mode 100644 index 0000000000..8b85d6d99e --- /dev/null +++ b/hal/include/HAL/Constants.h @@ -0,0 +1,14 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +extern "C" { +int32_t HAL_getSystemClockTicksPerMicrosecond(void); +} diff --git a/hal/include/HAL/HAL.h b/hal/include/HAL/HAL.h index c60b3f917d..92598ec19b 100644 --- a/hal/include/HAL/HAL.h +++ b/hal/include/HAL/HAL.h @@ -16,6 +16,7 @@ #include "AnalogOutput.h" #include "AnalogTrigger.h" #include "Compressor.h" +#include "Constants.h" #include "Counter.h" #include "DIO.h" #include "Errors.h" @@ -104,8 +105,6 @@ struct HALJoystickDescriptor { }; extern "C" { -extern const uint32_t kSystemClockTicksPerMicrosecond; - HalPortHandle getPort(uint8_t pin); HalPortHandle getPortWithModule(uint8_t module, uint8_t pin); const char* getHALErrorMessage(int32_t code); diff --git a/hal/include/HAL/Ports.h b/hal/include/HAL/Ports.h index 2966f6098c..88ef083c33 100644 --- a/hal/include/HAL/Ports.h +++ b/hal/include/HAL/Ports.h @@ -27,5 +27,6 @@ int32_t HAL_getNumRelayHeaders(void); int32_t HAL_getNumPCMModules(void); int32_t HAL_getNumSolenoidPins(void); int32_t HAL_getNumPDPModules(void); +int32_t HAL_getNumPDPChannels(void); int32_t HAL_getNumCanTalons(void); } diff --git a/hal/lib/athena/Constants.cpp b/hal/lib/athena/Constants.cpp new file mode 100644 index 0000000000..9c23ae6652 --- /dev/null +++ b/hal/lib/athena/Constants.cpp @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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. */ +/*----------------------------------------------------------------------------*/ + +#include "HAL/Constants.h" + +#include "ConstantsInternal.h" + +using namespace hal; + +extern "C" { +int32_t HAL_getSystemClockTicksPerMicrosecond(void) { + return kSystemClockTicksPerMicrosecond; +} +} diff --git a/hal/lib/athena/ConstantsInternal.h b/hal/lib/athena/ConstantsInternal.h new file mode 100644 index 0000000000..42b32ae84f --- /dev/null +++ b/hal/lib/athena/ConstantsInternal.h @@ -0,0 +1,14 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +namespace hal { +constexpr int32_t kSystemClockTicksPerMicrosecond = 40; +} diff --git a/hal/lib/athena/Counter.cpp b/hal/lib/athena/Counter.cpp index dccc7f60d8..56b9e8cb22 100644 --- a/hal/lib/athena/Counter.cpp +++ b/hal/lib/athena/Counter.cpp @@ -7,6 +7,7 @@ #include "HAL/Counter.h" +#include "ConstantsInternal.h" #include "DigitalInternal.h" #include "HAL/HAL.h" #include "PortsInternal.h" diff --git a/hal/lib/athena/DigitalInternal.cpp b/hal/lib/athena/DigitalInternal.cpp index 3f4888f529..89dd8ce84d 100644 --- a/hal/lib/athena/DigitalInternal.cpp +++ b/hal/lib/athena/DigitalInternal.cpp @@ -11,6 +11,7 @@ #include #include "ChipObject.h" +#include "ConstantsInternal.h" #include "FRC_NetworkCommunication/LoadOut.h" #include "HAL/AnalogTrigger.h" #include "HAL/HAL.h" diff --git a/hal/lib/athena/Ports.cpp b/hal/lib/athena/Ports.cpp index 0b1dc4fe30..d985ad2812 100644 --- a/hal/lib/athena/Ports.cpp +++ b/hal/lib/athena/Ports.cpp @@ -29,5 +29,6 @@ int32_t HAL_getNumRelayHeaders(void) { return kNumRelayHeaders; } int32_t HAL_getNumPCMModules(void) { return kNumPCMModules; } int32_t HAL_getNumSolenoidPins(void) { return kNumSolenoidPins; } int32_t HAL_getNumPDPModules(void) { return kNumPDPModules; } +int32_t HAL_getNumPDPChannels(void) { return kNumPDPChannels; } int32_t HAL_getNumCanTalons(void) { return kNumCanTalons; } } diff --git a/hal/lib/athena/PortsInternal.h b/hal/lib/athena/PortsInternal.h index 35143306e0..ed505f8943 100644 --- a/hal/lib/athena/PortsInternal.h +++ b/hal/lib/athena/PortsInternal.h @@ -30,5 +30,6 @@ constexpr int32_t kNumRelayHeaders = kNumRelayPins / 2; constexpr int32_t kNumPCMModules = 63; constexpr int32_t kNumSolenoidPins = 8; constexpr int32_t kNumPDPModules = 63; +constexpr int32_t kNumPDPChannels = 16; constexpr int32_t kNumCanTalons = 63; } diff --git a/wpilibc/athena/src/DigitalGlitchFilter.cpp b/wpilibc/athena/src/DigitalGlitchFilter.cpp index d798522b41..004ca972f7 100644 --- a/wpilibc/athena/src/DigitalGlitchFilter.cpp +++ b/wpilibc/athena/src/DigitalGlitchFilter.cpp @@ -159,7 +159,7 @@ void DigitalGlitchFilter::SetPeriodCycles(uint32_t fpga_cycles) { void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) { int32_t status = 0; uint32_t fpga_cycles = - nanoseconds * kSystemClockTicksPerMicrosecond / 4 / 1000; + nanoseconds * HAL_getSystemClockTicksPerMicrosecond() / 4 / 1000; setFilterPeriod(m_channelIndex, fpga_cycles, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); @@ -191,5 +191,5 @@ uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() { wpi_setErrorWithContext(status, getHALErrorMessage(status)); return static_cast(fpga_cycles) * 1000L / - static_cast(kSystemClockTicksPerMicrosecond / 4); + static_cast(HAL_getSystemClockTicksPerMicrosecond() / 4); } diff --git a/wpilibc/athena/src/PWM.cpp b/wpilibc/athena/src/PWM.cpp index 7288524a3e..4628401e71 100644 --- a/wpilibc/athena/src/PWM.cpp +++ b/wpilibc/athena/src/PWM.cpp @@ -126,7 +126,7 @@ void PWM::SetBounds(double max, double deadbandMax, double center, // calculate the loop time in milliseconds int32_t status = 0; double loopTime = - getLoopTiming(&status) / (kSystemClockTicksPerMicrosecond * 1e3); + getLoopTiming(&status) / (HAL_getSystemClockTicksPerMicrosecond() * 1e3); wpi_setErrorWithContext(status, getHALErrorMessage(status)); if (StatusIsFatal()) return; diff --git a/wpilibj/athena.gradle b/wpilibj/athena.gradle index 659587dd0b..17283d290b 100644 --- a/wpilibj/athena.gradle +++ b/wpilibj/athena.gradle @@ -160,6 +160,7 @@ task jniHeaders { args 'edu.wpi.first.wpilibj.hal.AnalogJNI' args 'edu.wpi.first.wpilibj.hal.AnalogGyroJNI' args 'edu.wpi.first.wpilibj.hal.CanTalonJNI' + args 'edu.wpi.first.wpilibj.hal.ConstantsJNI' args 'edu.wpi.first.wpilibj.hal.CounterJNI' args 'edu.wpi.first.wpilibj.hal.DigitalGlitchFilterJNI' args 'edu.wpi.first.wpilibj.hal.DIOJNI' @@ -167,6 +168,7 @@ task jniHeaders { args 'edu.wpi.first.wpilibj.hal.I2CJNI' args 'edu.wpi.first.wpilibj.hal.InterruptJNI' args 'edu.wpi.first.wpilibj.hal.NotifierJNI' + args 'edu.wpi.first.wpilibj.hal.PortsJNI' args 'edu.wpi.first.wpilibj.hal.PWMJNI' args 'edu.wpi.first.wpilibj.hal.RelayJNI' args 'edu.wpi.first.wpilibj.hal.SPIJNI' diff --git a/wpilibj/src/athena/cpp/lib/ConstantsJNI.cpp b/wpilibj/src/athena/cpp/lib/ConstantsJNI.cpp new file mode 100644 index 0000000000..76ae3d591a --- /dev/null +++ b/wpilibj/src/athena/cpp/lib/ConstantsJNI.cpp @@ -0,0 +1,40 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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. */ +/*----------------------------------------------------------------------------*/ + +#include +#include +#include "Log.h" + +#include "edu_wpi_first_wpilibj_hal_ConstantsJNI.h" + +#include "HAL/Constants.h" +#include "HALUtil.h" + +// set the logging level +TLogLevel constantsJNILogLevel = logWARNING; + +#define CONSTANTSJNI_LOG(level) \ + if (level > constantsJNILogLevel) \ + ; \ + else \ + Log().Get(level) + +extern "C" { +/* + * Class: edu_wpi_first_wpilibj_hal_ConstantsJNI + * Method: getSystemClockTicksPerMicrosecond + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_ConstantsJNI_getSystemClockTicksPerMicrosecond( + JNIEnv *env, jclass) { + CONSTANTSJNI_LOG(logDEBUG) << "Calling ConstantsJNI getSystemClockTicksPerMicrosecond"; + jint value = HAL_getSystemClockTicksPerMicrosecond(); + CONSTANTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} +} diff --git a/wpilibj/src/athena/cpp/lib/PortsJNI.cpp b/wpilibj/src/athena/cpp/lib/PortsJNI.cpp new file mode 100644 index 0000000000..5915566b2e --- /dev/null +++ b/wpilibj/src/athena/cpp/lib/PortsJNI.cpp @@ -0,0 +1,310 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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. */ +/*----------------------------------------------------------------------------*/ + +#include +#include +#include "Log.h" + +#include "edu_wpi_first_wpilibj_hal_PortsJNI.h" + +#include "HAL/Ports.h" +#include "HALUtil.h" + +// set the logging level +TLogLevel portsJNILogLevel = logWARNING; + +#define PORTSJNI_LOG(level) \ + if (level > portsJNILogLevel) \ + ; \ + else \ + Log().Get(level) + +extern "C" { +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumAccumulators + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAccumulators( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAccumulators"; + jint value = HAL_getNumAccumulators(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumAnalogTriggers + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAnalogTriggers( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAnalogTriggers"; + jint value = HAL_getNumAnalogTriggers(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumAnalogInputs + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAnalogInputs( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAnalogInputs"; + jint value = HAL_getNumAnalogInputs(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumAnalogOutputs + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAnalogOutputs( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAnalogOutputs"; + jint value = HAL_getNumAnalogOutputs(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumCounters + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumCounters( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumCounters"; + jint value = HAL_getNumCounters(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumDigitalHeaders + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalHeaders( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalHeaders"; + jint value = HAL_getNumDigitalHeaders(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumPWMHeaders + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMHeaders( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPWMHeaders"; + jint value = HAL_getNumPWMHeaders(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumDigitalPins + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalPins( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalPins"; + jint value = HAL_getNumDigitalPins(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumPWMPins + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMPins( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPWMPins"; + jint value = HAL_getNumPWMPins(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumDigitalPWMOutputs + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalPWMOutputs( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalPWMOutputs"; + jint value = HAL_getNumDigitalPWMOutputs(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumEncoders + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumEncoders( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumEncoders"; + jint value = HAL_getNumEncoders(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumInterrupts + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumInterrupts( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumInterrupts"; + jint value = HAL_getNumInterrupts(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumRelayPins + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumRelayPins( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumRelayPins"; + jint value = HAL_getNumRelayPins(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumRelayHeaders + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumRelayHeaders( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumRelayHeaders"; + jint value = HAL_getNumRelayHeaders(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumPCMModules + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPCMModules( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPCMModules"; + jint value = HAL_getNumPCMModules(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumSolenoidPins + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumSolenoidPins( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumSolenoidPins"; + jint value = HAL_getNumSolenoidPins(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumPDPModules + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPDPModules( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPDPModules"; + jint value = HAL_getNumPDPModules(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumPDPChannels + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPDPChannels( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPDPChannels"; + jint value = HAL_getNumPDPChannels(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} + + +/* + * Class: edu_wpi_first_wpilibj_hal_PortsJNI + * Method: getNumCanTalons + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumCanTalons( + JNIEnv *env, jclass) { + PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumCanTalons"; + jint value = HAL_getNumCanTalons(); + PORTSJNI_LOG(logDEBUG) << "Value = " << value; + return value; +} +} diff --git a/wpilibj/src/shared/java/edu/wpi/first/wpilibj/GyroBase.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/GyroBase.java similarity index 100% rename from wpilibj/src/shared/java/edu/wpi/first/wpilibj/GyroBase.java rename to wpilibj/src/athena/java/edu/wpi/first/wpilibj/GyroBase.java diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java new file mode 100644 index 0000000000..793d594baf --- /dev/null +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java @@ -0,0 +1,195 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008-2016. 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; + +import edu.wpi.first.wpilibj.hal.ConstantsJNI; +import edu.wpi.first.wpilibj.hal.PortsJNI; + +/** + * Base class for all sensors. Stores most recent status information as well as containing utility + * functions for checking channels and error processing. + */ +public abstract class SensorBase { // TODO: Refactor + /** + * Ticks per microsecond. + */ + public static final int kSystemClockTicksPerMicrosecond = + ConstantsJNI.getSystemClockTicksPerMicrosecond(); + /** + * Number of digital channels per roboRIO. + */ + public static final int kDigitalChannels = PortsJNI.getNumDigitalPins(); + /** + * Number of analog input channels. + */ + public static final int kAnalogInputChannels = PortsJNI.getNumAnalogInputs(); + /** + * Number of analog output channels. + */ + public static final int kAnalogOutputChannels = PortsJNI.getNumAnalogOutputs(); + /** + * Number of solenoid channels per module. + */ + public static final int kSolenoidChannels = PortsJNI.getNumSolenoidPins(); + /** + * Number of PWM channels per roboRIO. + */ + public static final int kPwmChannels = PortsJNI.getNumPWMPins(); + /** + * Number of relay channels per roboRIO. + */ + public static final int kRelayChannels = PortsJNI.getNumRelayPins(); + /** + * Number of power distribution channels. + */ + public static final int kPDPChannels = PortsJNI.getNumPDPChannels(); + /** + * Number of power distribution modules. + */ + public static final int kPDPModules = PortsJNI.getNumPDPModules(); + /** + * Number of PCM Modules. + */ + public static final int kPCMModules = PortsJNI.getNumPCMModules(); + + private static int m_defaultSolenoidModule = 0; + + /** + * 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) { + } + + /** + * 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) { + throw new IndexOutOfBoundsException("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) { + 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) { + 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) { + throw new IndexOutOfBoundsException("Requested analog input 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) { + throw new IndexOutOfBoundsException( + "Requested analog output 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) { + throw new IndexOutOfBoundsException("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) { + throw new IndexOutOfBoundsException("Requested PDP channel number is out of range."); + } + } + + /** + * Verify that the PDP module number is within limits. module numbers are 0-based. + * + * @param module The module number to check. + */ + protected static void checkPDPModule(final int module) { + if (module < 0 || module > kPDPModules) { + throw new IndexOutOfBoundsException("Requested PDP module 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() { + } +} diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/ConstantsJNI.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/ConstantsJNI.java new file mode 100644 index 0000000000..5e48f40c06 --- /dev/null +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/ConstantsJNI.java @@ -0,0 +1,12 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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.hal; + +public class ConstantsJNI extends JNIWrapper { + public static native int getSystemClockTicksPerMicrosecond(); +} diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/PortsJNI.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/PortsJNI.java new file mode 100644 index 0000000000..457643a535 --- /dev/null +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/PortsJNI.java @@ -0,0 +1,48 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. 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.hal; + +public class PortsJNI extends JNIWrapper { + public static native int getNumAccumulators(); + + public static native int getNumAnalogTriggers(); + + public static native int getNumAnalogInputs(); + + public static native int getNumAnalogOutputs(); + + public static native int getNumCounters(); + + public static native int getNumDigitalHeaders(); + + public static native int getNumPWMHeaders(); + + public static native int getNumDigitalPins(); + + public static native int getNumPWMPins(); + + public static native int getNumDigitalPWMOutputs(); + + public static native int getNumEncoders(); + + public static native int getNumInterrupts(); + + public static native int getNumRelayPins(); + + public static native int getNumRelayHeaders(); + + public static native int getNumPCMModules(); + + public static native int getNumSolenoidPins(); + + public static native int getNumPDPModules(); + + public static native int getNumPDPChannels(); + + public static native int getNumCanTalons(); +} diff --git a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/GyroBase.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/GyroBase.java new file mode 100644 index 0000000000..0aef1c4526 --- /dev/null +++ b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/GyroBase.java @@ -0,0 +1,90 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008-2016. 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; + +import edu.wpi.first.wpilibj.interfaces.Gyro; +import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; +import edu.wpi.first.wpilibj.tables.ITable; + +/** + * GyroBase is the common base class for Gyro implementations such as AnalogGyro. + */ +public abstract class GyroBase extends SensorBase implements Gyro, PIDSource, LiveWindowSendable { + private PIDSourceType m_pidSource = PIDSourceType.kDisplacement; + + /** + * Set which parameter of the gyro you are using as a process control variable. The Gyro class + * supports the rate and displacement parameters + * + * @param pidSource An enum to select the parameter. + */ + @Override + public void setPIDSourceType(PIDSourceType pidSource) { + m_pidSource = pidSource; + } + + @Override + public PIDSourceType getPIDSourceType() { + return m_pidSource; + } + + /** + * Get the output of the gyro for use with PIDControllers. May be the angle or rate depending on + * the set PIDSourceType + * + * @return the output according to the gyro + */ + @Override + public double pidGet() { + switch (m_pidSource) { + case kRate: + return getRate(); + case kDisplacement: + return getAngle(); + default: + return 0.0; + } + } + + /* + * Live Window code, only does anything if live window is activated. + */ + @Override + public String getSmartDashboardType() { + return "Gyro"; + } + + private ITable m_table; + + + @Override + public void initTable(ITable subtable) { + m_table = subtable; + updateTable(); + } + + @Override + public ITable getTable() { + return m_table; + } + + @Override + public void updateTable() { + if (m_table != null) { + m_table.putNumber("Value", getAngle()); + } + } + + @Override + public void startLiveWindowMode() { + } + + @Override + public void stopLiveWindowMode() { + } +} diff --git a/wpilibj/src/shared/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/SensorBase.java similarity index 100% rename from wpilibj/src/shared/java/edu/wpi/first/wpilibj/SensorBase.java rename to wpilibj/src/sim/java/edu/wpi/first/wpilibj/SensorBase.java diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java new file mode 100644 index 0000000000..8e899c67ac --- /dev/null +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/ConstantsPortsTest.java @@ -0,0 +1,102 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008-2016. 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; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.logging.Logger; + +import edu.wpi.first.wpilibj.test.AbstractComsSetup; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for checking our constant and port values. + */ +public class ConstantsPortsTest extends AbstractComsSetup { + private static final Logger logger = Logger.getLogger(ConstantsPortsTest.class.getName()); + + protected Logger getClassLogger() { + return logger; + } + + /** + * kDigitalChannels. + */ + @Test + public void testDigitalChannels() { + assertEquals(26, SensorBase.kDigitalChannels); + } + + /** + * kAnalogInputChannels. + */ + @Test + public void testAnalogInputChannels() { + assertEquals(8, SensorBase.kAnalogInputChannels); + } + + /** + * kAnalogOutputChannels. + */ + @Test + public void testAnalogOutputChannels() { + assertEquals(2, SensorBase.kAnalogOutputChannels); + } + + /** + * kSolenoidChannels. + */ + @Test + public void testSolenoidChannels() { + assertEquals(8, SensorBase.kSolenoidChannels); + } + + /** + * kPwmChannels. + */ + @Test + public void testPwmChannels() { + assertEquals(20, SensorBase.kPwmChannels); + } + + /** + * kRelayChannels. + */ + @Test + public void testRelayChannels() { + assertEquals(8, SensorBase.kRelayChannels); + } + + /** + * kPDPChannels. + */ + @Test + public void testPDPChannels() { + assertEquals(16, SensorBase.kPDPChannels); + } + + /** + * kPDPModules. + */ + @Test + public void testPDPModules() { + assertEquals(63, SensorBase.kPDPModules); + } + + /** + * kPCMModules. + */ + @Test + public void testPCMModules() { + assertEquals(63, SensorBase.kPCMModules); + } +} diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/WpiLibJTestSuite.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/WpiLibJTestSuite.java index 526d8261eb..a7af2f7cea 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/WpiLibJTestSuite.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/WpiLibJTestSuite.java @@ -20,9 +20,9 @@ import edu.wpi.first.wpilibj.test.AbstractTestSuite; @RunWith(Suite.class) @SuiteClasses({AnalogCrossConnectTest.class, AnalogPotentiometerTest.class, BuiltInAccelerometerTest.class, CANTalonTest.class, - CircularBufferTest.class, CounterTest.class, DigitalGlitchFilterTest.class, - DIOCrossConnectTest.class, EncoderTest.class, FilterNoiseTest.class, - FilterOutputTest.class, GyroTest.class, MotorEncoderTest.class, + CircularBufferTest.class, ConstantsPortsTest.class, CounterTest.class, + DigitalGlitchFilterTest.class, DIOCrossConnectTest.class, EncoderTest.class, + FilterNoiseTest.class, FilterOutputTest.class, GyroTest.class, MotorEncoderTest.class, MotorInvertingTest.class, PCMTest.class, PDPTest.class, PIDTest.class, PIDToleranceTest.class, PreferencesTest.class, RelayCrossConnectTest.class, SampleTest.class, TimerTest.class})