diff --git a/hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java b/hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java index 37822697ab..560fbda8c1 100644 --- a/hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java @@ -34,7 +34,7 @@ public class DutyCycleJNI extends JNIWrapper { * @return frequency in Hertz * @see "HAL_GetDutyCycleFrequency" */ - public static native int getFrequency(int handle); + public static native double getFrequency(int handle); /** * Get the output ratio of the duty cycle signal. @@ -56,27 +56,6 @@ public class DutyCycleJNI extends JNIWrapper { */ public static native int getHighTime(int handle); - /** - * Get the scale factor of the output. - * - *

An output equal to this value is always high, and then linearly scales down to 0. Divide a - * raw result by this in order to get the percentage between 0 and 1. Used by DMA. - * - * @param handle the duty cycle handle - * @return the output scale factor - * @see "HAL_GetDutyCycleOutputScaleFactor" - */ - public static native int getOutputScaleFactor(int handle); - - /** - * Get the FPGA index for the DutyCycle. - * - * @param handle the duty cycle handle - * @return the FPGA index - * @see "HAL_GetDutyCycleFPGAIndex" - */ - public static native int getFPGAIndex(int handle); - /** Utility class. */ private DutyCycleJNI() {} } diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/DutyCycleDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/DutyCycleDataJNI.java index e2ed873582..916457fa04 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/DutyCycleDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/DutyCycleDataJNI.java @@ -22,9 +22,9 @@ public class DutyCycleDataJNI extends JNIWrapper { public static native void cancelFrequencyCallback(int index, int uid); - public static native int getFrequency(int index); + public static native double getFrequency(int index); - public static native void setFrequency(int index, int frequency); + public static native void setFrequency(int index, double frequency); public static native int registerOutputCallback( int index, NotifyCallback callback, boolean initialNotify); @@ -37,8 +37,6 @@ public class DutyCycleDataJNI extends JNIWrapper { public static native void resetData(int index); - public static native int findForChannel(int channel); - /** Utility class. */ private DutyCycleDataJNI() {} } diff --git a/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp b/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp index be67458b5a..dbbfa0ac82 100644 --- a/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp +++ b/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp @@ -46,9 +46,9 @@ Java_edu_wpi_first_hal_DutyCycleJNI_free /* * Class: edu_wpi_first_hal_DutyCycleJNI * Method: getFrequency - * Signature: (I)I + * Signature: (I)D */ -JNIEXPORT jint JNICALL +JNIEXPORT jdouble JNICALL Java_edu_wpi_first_hal_DutyCycleJNI_getFrequency (JNIEnv* env, jclass, jint handle) { @@ -91,36 +91,4 @@ Java_edu_wpi_first_hal_DutyCycleJNI_getHighTime return retVal; } -/* - * Class: edu_wpi_first_hal_DutyCycleJNI - * Method: getOutputScaleFactor - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_DutyCycleJNI_getOutputScaleFactor - (JNIEnv* env, jclass, jint handle) -{ - int32_t status = 0; - auto retVal = HAL_GetDutyCycleOutputScaleFactor( - static_cast(handle), &status); - CheckStatus(env, status); - return retVal; -} - -/* - * Class: edu_wpi_first_hal_DutyCycleJNI - * Method: getFPGAIndex - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_DutyCycleJNI_getFPGAIndex - (JNIEnv* env, jclass, jint handle) -{ - int32_t status = 0; - auto retVal = HAL_GetDutyCycleFPGAIndex( - static_cast(handle), &status); - CheckStatus(env, status); - return retVal; -} - } // extern "C" diff --git a/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp index 9cda86d2f7..13f413676f 100644 --- a/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp @@ -91,9 +91,9 @@ Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_cancelFrequencyCallback /* * Class: edu_wpi_first_hal_simulation_DutyCycleDataJNI * Method: getFrequency - * Signature: (I)I + * Signature: (I)D */ -JNIEXPORT jint JNICALL +JNIEXPORT jdouble JNICALL Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_getFrequency (JNIEnv*, jclass, jint index) { @@ -103,11 +103,11 @@ Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_getFrequency /* * Class: edu_wpi_first_hal_simulation_DutyCycleDataJNI * Method: setFrequency - * Signature: (II)V + * Signature: (ID)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_setFrequency - (JNIEnv*, jclass, jint index, jint value) + (JNIEnv*, jclass, jint index, jdouble value) { HALSIM_SetDutyCycleFrequency(index, value); } @@ -174,16 +174,4 @@ Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_resetData HALSIM_ResetDutyCycleData(index); } -/* - * Class: edu_wpi_first_hal_simulation_DutyCycleDataJNI - * Method: findForChannel - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_findForChannel - (JNIEnv*, jclass, jint channel) -{ - return HALSIM_FindDutyCycleForChannel(channel); -} - } // extern "C" diff --git a/hal/src/main/native/include/hal/DutyCycle.h b/hal/src/main/native/include/hal/DutyCycle.h index 4eaa26d142..59fb4149f5 100644 --- a/hal/src/main/native/include/hal/DutyCycle.h +++ b/hal/src/main/native/include/hal/DutyCycle.h @@ -52,8 +52,8 @@ void HAL_SetDutyCycleSimDevice(HAL_DutyCycleHandle handle, * @param[out] status Error status variable. 0 on success. * @return frequency in Hertz */ -int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status); +double HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle, + int32_t* status); /** * Get the output ratio of the duty cycle signal. @@ -77,30 +77,6 @@ double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle, int32_t HAL_GetDutyCycleHighTime(HAL_DutyCycleHandle dutyCycleHandle, int32_t* status); -/** - * Get the scale factor of the output. - * - *

An output equal to this value is always high, and then linearly scales - * down to 0. Divide a raw result by this in order to get the - * percentage between 0 and 1. Used by DMA. - * - * @param[in] dutyCycleHandle the duty cycle handle - * @param[out] status Error status variable. 0 on success. - * @return the output scale factor - */ -int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status); - -/** - * Get the FPGA index for the DutyCycle. - * - * @param[in] dutyCycleHandle the duty cycle handle - * @param[out] status Error status variable. 0 on success. - * @return the FPGA index - */ -int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status); - #ifdef __cplusplus } // extern "C" #endif diff --git a/hal/src/main/native/include/hal/simulation/DutyCycleData.h b/hal/src/main/native/include/hal/simulation/DutyCycleData.h index bbe5bf2728..b43dd4274b 100644 --- a/hal/src/main/native/include/hal/simulation/DutyCycleData.h +++ b/hal/src/main/native/include/hal/simulation/DutyCycleData.h @@ -11,10 +11,7 @@ extern "C" { #endif -int32_t HALSIM_FindDutyCycleForChannel(int32_t channel); - void HALSIM_ResetDutyCycleData(int32_t index); -int32_t HALSIM_GetDutyCycleDigitalChannel(int32_t index); int32_t HALSIM_RegisterDutyCycleInitializedCallback(int32_t index, HAL_NotifyCallback callback, @@ -39,8 +36,8 @@ int32_t HALSIM_RegisterDutyCycleFrequencyCallback(int32_t index, void* param, HAL_Bool initialNotify); void HALSIM_CancelDutyCycleFrequencyCallback(int32_t index, int32_t uid); -int32_t HALSIM_GetDutyCycleFrequency(int32_t index); -void HALSIM_SetDutyCycleFrequency(int32_t index, int32_t frequency); +double HALSIM_GetDutyCycleFrequency(int32_t index); +void HALSIM_SetDutyCycleFrequency(int32_t index, double frequency); void HALSIM_RegisterDutyCycleAllCallbacks(int32_t index, HAL_NotifyCallback callback, diff --git a/hal/src/main/native/sim/DutyCycle.cpp b/hal/src/main/native/sim/DutyCycle.cpp index 80c9ddbbc5..bfac85902d 100644 --- a/hal/src/main/native/sim/DutyCycle.cpp +++ b/hal/src/main/native/sim/DutyCycle.cpp @@ -4,11 +4,14 @@ #include "hal/DutyCycle.h" +#include + #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/Errors.h" #include "hal/handles/HandlesInternal.h" -#include "hal/handles/LimitedHandleResource.h" +#include "hal/handles/IndexedHandleResource.h" #include "mockdata/DutyCycleDataInternal.h" using namespace hal; @@ -16,16 +19,17 @@ using namespace hal; namespace { struct DutyCycle { uint8_t index; + std::string previousAllocation; }; struct Empty {}; } // namespace -static LimitedHandleResource* dutyCycleHandles; namespace hal::init { void InitializeDutyCycle() { - static LimitedHandleResource dcH; dutyCycleHandles = &dcH; @@ -38,23 +42,25 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel, int32_t* status) { hal::init::CheckInit(); - HAL_DutyCycleHandle handle = dutyCycleHandles->Allocate(); - if (handle == HAL_kInvalidHandle) { - *status = NO_AVAILABLE_RESOURCES; - return HAL_kInvalidHandle; - } + HAL_DutyCycleHandle handle = HAL_kInvalidHandle; + auto dutyCycle = dutyCycleHandles->Allocate(channel, &handle, status); - auto dutyCycle = dutyCycleHandles->Get(handle); - if (dutyCycle == nullptr) { // would only occur on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; + if (*status != 0) { + if (dutyCycle) { + hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel, + dutyCycle->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Duty Cycle", + 0, kNumDutyCycles, channel); + } + return HAL_kInvalidHandle; // failed to allocate. Pass error back. } int16_t index = getHandleIndex(handle); - SimDutyCycleData[index].digitalChannel = channel; SimDutyCycleData[index].initialized = true; SimDutyCycleData[index].simDevice = 0; dutyCycle->index = index; + dutyCycle->previousAllocation = allocationLocation ? allocationLocation : ""; return handle; } void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) { @@ -75,8 +81,8 @@ void HAL_SetDutyCycleSimDevice(HAL_EncoderHandle handle, SimDutyCycleData[dutyCycle->index].simDevice = device; } -int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status) { +double HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle, + int32_t* status) { auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle); if (dutyCycle == nullptr) { *status = HAL_HANDLE_ERROR; @@ -110,19 +116,4 @@ int32_t HAL_GetDutyCycleHighTime(HAL_DutyCycleHandle dutyCycleHandle, double period = 1e9 / SimDutyCycleData[dutyCycle->index].frequency; // ns return period * SimDutyCycleData[dutyCycle->index].output; } - -int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status) { - return 4e7 - 1; -} - -int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status) { - auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle); - if (dutyCycle == nullptr) { - *status = HAL_HANDLE_ERROR; - return -1; - } - return dutyCycle->index; -} } // extern "C" diff --git a/hal/src/main/native/sim/PortsInternal.h b/hal/src/main/native/sim/PortsInternal.h index 2c1d86c8ca..0ade7a25aa 100644 --- a/hal/src/main/native/sim/PortsInternal.h +++ b/hal/src/main/native/sim/PortsInternal.h @@ -31,7 +31,7 @@ constexpr int32_t kNumREVPDHModules = 63; constexpr int32_t kNumREVPDHChannels = 24; constexpr int32_t kNumPDSimModules = kNumREVPDHModules; constexpr int32_t kNumPDSimChannels = kNumREVPDHChannels; -constexpr int32_t kNumDutyCycles = 8; +constexpr int32_t kNumDutyCycles = 6; constexpr int32_t kNumAddressableLEDs = 1; constexpr int32_t kNumREVPHModules = 63; constexpr int32_t kNumREVPHChannels = 16; diff --git a/hal/src/main/native/sim/mockdata/DutyCycleData.cpp b/hal/src/main/native/sim/mockdata/DutyCycleData.cpp index de677a5897..b76044d135 100644 --- a/hal/src/main/native/sim/mockdata/DutyCycleData.cpp +++ b/hal/src/main/native/sim/mockdata/DutyCycleData.cpp @@ -17,7 +17,6 @@ void InitializeDutyCycleData() { DutyCycleData* hal::SimDutyCycleData; void DutyCycleData::ResetData() { - digitalChannel = 0; initialized.Reset(false); simDevice = 0; frequency.Reset(0); @@ -25,22 +24,10 @@ void DutyCycleData::ResetData() { } extern "C" { -int32_t HALSIM_FindDutyCycleForChannel(int32_t channel) { - for (int i = 0; i < kNumDutyCycles; ++i) { - if (SimDutyCycleData[i].initialized && - SimDutyCycleData[i].digitalChannel == channel) { - return i; - } - } - return -1; -} void HALSIM_ResetDutyCycleData(int32_t index) { SimDutyCycleData[index].ResetData(); } -int32_t HALSIM_GetDutyCycleDigitalChannel(int32_t index) { - return SimDutyCycleData[index].digitalChannel; -} HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index) { return SimDutyCycleData[index].simDevice; @@ -51,7 +38,7 @@ HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index) { SimDutyCycleData, LOWERNAME) DEFINE_CAPI(HAL_Bool, Initialized, initialized) -DEFINE_CAPI(int32_t, Frequency, frequency) +DEFINE_CAPI(double, Frequency, frequency) DEFINE_CAPI(double, Output, output) #define REGISTER(NAME) \ diff --git a/hal/src/main/native/sim/mockdata/DutyCycleDataInternal.h b/hal/src/main/native/sim/mockdata/DutyCycleDataInternal.h index 0eb8aff325..2f5d371e4d 100644 --- a/hal/src/main/native/sim/mockdata/DutyCycleDataInternal.h +++ b/hal/src/main/native/sim/mockdata/DutyCycleDataInternal.h @@ -17,11 +17,10 @@ class DutyCycleData { HAL_SIMDATAVALUE_DEFINE_NAME(Frequency) public: - std::atomic digitalChannel{0}; SimDataValue initialized{ false}; std::atomic simDevice; - SimDataValue frequency{0}; + SimDataValue frequency{0}; SimDataValue output{0}; virtual void ResetData(); diff --git a/hal/src/main/native/systemcore/DutyCycle.cpp b/hal/src/main/native/systemcore/DutyCycle.cpp index 03b3e148be..34b19ea101 100644 --- a/hal/src/main/native/systemcore/DutyCycle.cpp +++ b/hal/src/main/native/systemcore/DutyCycle.cpp @@ -88,16 +88,47 @@ void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) { void HAL_SetDutyCycleSimDevice(HAL_EncoderHandle handle, HAL_SimDeviceHandle device) {} -int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; +double HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle, + int32_t* status) { + auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle); + if (port == nullptr) { + *status = HAL_HANDLE_ERROR; + return 0; + } + + uint16_t ret = 0; + *status = port->GetPwmInputPeriodMicroseconds(&ret); + + if (ret == 0) { + return 0.0; + } + + return 1000000.0 / ret; } double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; + auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle); + if (port == nullptr) { + *status = HAL_HANDLE_ERROR; + return 0.0; + } + + uint16_t highTime = 0; + *status = port->GetPwmInputMicroseconds(&highTime); + + uint16_t period = 0; + *status = port->GetPwmInputPeriodMicroseconds(&period); + + if (period == 0) { + return 0.0; + } + + if (highTime >= period) { + return 1.0; + } + + return static_cast(highTime) / static_cast(period); } int32_t HAL_GetDutyCycleHighTime(HAL_DutyCycleHandle dutyCycleHandle, @@ -105,23 +136,11 @@ int32_t HAL_GetDutyCycleHighTime(HAL_DutyCycleHandle dutyCycleHandle, auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle); if (port == nullptr) { *status = HAL_HANDLE_ERROR; - return false; + return 0; } uint16_t ret = 0; *status = port->GetPwmInputMicroseconds(&ret); return static_cast(ret) * 1000; } - -int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} } // extern "C" diff --git a/hal/src/main/native/systemcore/SmartIo.cpp b/hal/src/main/native/systemcore/SmartIo.cpp index c2a3f54e00..2ce7d1399e 100644 --- a/hal/src/main/native/systemcore/SmartIo.cpp +++ b/hal/src/main/native/systemcore/SmartIo.cpp @@ -35,11 +35,11 @@ int32_t SmartIo::InitializeMode(SmartIoMode mode) { modePublisher = inst.GetIntegerTopic(subTableString + "type").Publish(); getSubscriber = inst.GetIntegerTopic(subTableString + "valget").Subscribe(0, options); - frequencySubscriber = - inst.GetIntegerTopic(subTableString + "freqget").Subscribe(0, options); + periodGetSubscriber = + inst.GetIntegerTopic(subTableString + "periodget").Subscribe(0, options); setPublisher = inst.GetIntegerTopic(subTableString + "valset").Publish(options); - periodPublisher = + periodSetPublisher = inst.GetIntegerTopic(subTableString + "periodset").Publish(options); currentMode = mode; @@ -107,6 +107,17 @@ int32_t SmartIo::GetPwmInputMicroseconds(uint16_t* microseconds) { return 0; } +int32_t SmartIo::GetPwmInputPeriodMicroseconds(uint16_t* microseconds) { + if (currentMode != SmartIoMode::PwmInput) { + return INCOMPATIBLE_STATE; + } + + int val = periodGetSubscriber.Get(); + *microseconds = val; + + return 0; +} + int32_t SmartIo::SetPwmOutputPeriod(PwmOutputPeriod period) { if (currentMode != SmartIoMode::PwmOutput) { return INCOMPATIBLE_STATE; @@ -117,7 +128,7 @@ int32_t SmartIo::SetPwmOutputPeriod(PwmOutputPeriod period) { case PwmOutputPeriod::k10ms: case PwmOutputPeriod::k5ms: case PwmOutputPeriod::k2ms: - periodPublisher.Set(static_cast(period)); + periodSetPublisher.Set(static_cast(period)); return 0; default: diff --git a/hal/src/main/native/systemcore/SmartIo.h b/hal/src/main/native/systemcore/SmartIo.h index a93d7a8324..368950ca24 100644 --- a/hal/src/main/native/systemcore/SmartIo.h +++ b/hal/src/main/native/systemcore/SmartIo.h @@ -19,12 +19,12 @@ constexpr int32_t kPwmAlwaysHigh = 0xFFFF; enum class SmartIoMode { DigitalInput = 0, - DigitalOutput, - AnalogInput, - PwmInput, - PwmOutput, - SingleCounterRising, - SingleCounterFalling, + DigitalOutput = 1, + AnalogInput = 2, + PwmInput = 3, + PwmOutput = 4, + SingleCounterRising = 5, + SingleCounterFalling = 6, }; enum class PwmOutputPeriod { @@ -43,8 +43,8 @@ struct SmartIo { nt::IntegerPublisher setPublisher; nt::IntegerSubscriber getSubscriber; - nt::IntegerPublisher periodPublisher; - nt::IntegerSubscriber frequencySubscriber; + nt::IntegerPublisher periodSetPublisher; + nt::IntegerSubscriber periodGetSubscriber; int32_t InitializeMode(SmartIoMode mode); int32_t SwitchDioDirection(bool input); @@ -53,6 +53,7 @@ struct SmartIo { int32_t GetDigitalInput(bool* value); int32_t GetPwmInputMicroseconds(uint16_t* microseconds); + int32_t GetPwmInputPeriodMicroseconds(uint16_t* microseconds); int32_t SetPwmOutputPeriod(PwmOutputPeriod period); diff --git a/hal/src/main/native/systemcore/mockdata/DutyCycleData.cpp b/hal/src/main/native/systemcore/mockdata/DutyCycleData.cpp index d63e27e273..d4e3a0e0dd 100644 --- a/hal/src/main/native/systemcore/mockdata/DutyCycleData.cpp +++ b/hal/src/main/native/systemcore/mockdata/DutyCycleData.cpp @@ -7,16 +7,9 @@ #include "hal/simulation/SimDataValue.h" extern "C" { -int32_t HALSIM_FindDutyCycleForChannel(int32_t channel) { - return 0; -} void HALSIM_ResetDutyCycleData(int32_t index) {} -int32_t HALSIM_GetDutyCycleDigitalChannel(int32_t index) { - return 0; -} - HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index) { return 0; } @@ -25,7 +18,7 @@ HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index) { HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, DutyCycle##CAPINAME, RETURN) DEFINE_CAPI(HAL_Bool, Initialized, false) -DEFINE_CAPI(int32_t, Frequency, 0) +DEFINE_CAPI(double, Frequency, 0) DEFINE_CAPI(double, Output, 0) void HALSIM_RegisterDutyCycleAllCallbacks(int32_t index, diff --git a/simulation/halsim_gui/src/main/native/cpp/DIOSimGui.cpp b/simulation/halsim_gui/src/main/native/cpp/DIOSimGui.cpp index fb24d97b8f..61e4da6d69 100644 --- a/simulation/halsim_gui/src/main/native/cpp/DIOSimGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/DIOSimGui.cpp @@ -187,7 +187,7 @@ void DIOsSimModel::Update() { auto& model = m_dutyCycleModels[i]; if (HALSIM_GetDutyCycleInitialized(i)) { if (!model) { - int channel = HALSIM_GetDutyCycleDigitalChannel(i); + int channel = i; if (channel >= 0 && channel < numDIO && m_dioModels[channel]) { model = std::make_unique(i); m_dioModels[channel]->SetDutyCycle(model.get()); diff --git a/wpilibc/src/main/native/cpp/DutyCycle.cpp b/wpilibc/src/main/native/cpp/DutyCycle.cpp index 32fac05945..09608b98f9 100644 --- a/wpilibc/src/main/native/cpp/DutyCycle.cpp +++ b/wpilibc/src/main/native/cpp/DutyCycle.cpp @@ -35,18 +35,11 @@ void DutyCycle::InitDutyCycle() { wpi::SendableRegistry::Add(this, "Duty Cycle", m_channel); } -int DutyCycle::GetFPGAIndex() const { - int32_t status = 0; - auto retVal = HAL_GetDutyCycleFPGAIndex(m_handle, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return retVal; -} - -int DutyCycle::GetFrequency() const { +units::hertz_t DutyCycle::GetFrequency() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleFrequency(m_handle, &status); FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return retVal; + return units::hertz_t{retVal}; } double DutyCycle::GetOutput() const { @@ -63,13 +56,6 @@ units::second_t DutyCycle::GetHighTime() const { return units::nanosecond_t{static_cast(retVal)}; } -unsigned int DutyCycle::GetOutputScaleFactor() const { - int32_t status = 0; - auto retVal = HAL_GetDutyCycleOutputScaleFactor(m_handle, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return retVal; -} - int DutyCycle::GetSourceChannel() const { return m_channel; } @@ -77,7 +63,7 @@ int DutyCycle::GetSourceChannel() const { void DutyCycle::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("Duty Cycle"); builder.AddDoubleProperty( - "Frequency", [this] { return this->GetFrequency(); }, nullptr); + "Frequency", [this] { return this->GetFrequency().value(); }, nullptr); builder.AddDoubleProperty( "Output", [this] { return this->GetOutput(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp b/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp index 4dcf04d543..f9e89d9fb1 100644 --- a/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp +++ b/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp @@ -122,7 +122,7 @@ void DutyCycleEncoder::SetDutyCycleRange(double min, double max) { m_sensorMax = std::clamp(max, 0.0, 1.0); } -int DutyCycleEncoder::GetFrequency() const { +units::hertz_t DutyCycleEncoder::GetFrequency() const { return m_dutyCycle->GetFrequency(); } @@ -133,9 +133,10 @@ bool DutyCycleEncoder::IsConnected() const { return GetFrequency() > m_frequencyThreshold; } -void DutyCycleEncoder::SetConnectedFrequencyThreshold(int frequency) { - if (frequency < 0) { - frequency = 0; +void DutyCycleEncoder::SetConnectedFrequencyThreshold( + units::hertz_t frequency) { + if (frequency < 0_Hz) { + frequency = 0_Hz; } m_frequencyThreshold = frequency; } @@ -152,10 +153,6 @@ void DutyCycleEncoder::SetAssumedFrequency(units::hertz_t frequency) { } } -int DutyCycleEncoder::GetFPGAIndex() const { - return m_dutyCycle->GetFPGAIndex(); -} - int DutyCycleEncoder::GetSourceChannel() const { return m_dutyCycle->GetSourceChannel(); } diff --git a/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp b/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp index c95093ccb4..0e447e7f10 100644 --- a/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp @@ -15,18 +15,10 @@ using namespace frc; using namespace frc::sim; DutyCycleSim::DutyCycleSim(const DutyCycle& dutyCycle) - : m_index{dutyCycle.GetFPGAIndex()} {} + : m_index{dutyCycle.GetSourceChannel()} {} DutyCycleSim DutyCycleSim::CreateForChannel(int channel) { - int index = HALSIM_FindDutyCycleForChannel(channel); - if (index < 0) { - throw std::out_of_range("no duty cycle found for channel"); - } - return DutyCycleSim{index}; -} - -DutyCycleSim DutyCycleSim::CreateForIndex(int index) { - return DutyCycleSim{index}; + return DutyCycleSim{channel}; } std::unique_ptr DutyCycleSim::RegisterInitializedCallback( @@ -55,12 +47,12 @@ std::unique_ptr DutyCycleSim::RegisterFrequencyCallback( return store; } -int DutyCycleSim::GetFrequency() const { - return HALSIM_GetDutyCycleFrequency(m_index); +units::hertz_t DutyCycleSim::GetFrequency() const { + return units::hertz_t{HALSIM_GetDutyCycleFrequency(m_index)}; } -void DutyCycleSim::SetFrequency(int frequency) { - HALSIM_SetDutyCycleFrequency(m_index, frequency); +void DutyCycleSim::SetFrequency(units::hertz_t frequency) { + HALSIM_SetDutyCycleFrequency(m_index, frequency.value()); } std::unique_ptr DutyCycleSim::RegisterOutputCallback( diff --git a/wpilibc/src/main/native/include/frc/DutyCycle.h b/wpilibc/src/main/native/include/frc/DutyCycle.h index a2d426ebb3..493989f8a2 100644 --- a/wpilibc/src/main/native/include/frc/DutyCycle.h +++ b/wpilibc/src/main/native/include/frc/DutyCycle.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -17,11 +18,7 @@ namespace frc { * Class to read a duty cycle PWM input. * *

PWM input signals are specified with a frequency and a ratio of high to - * low in that frequency. There are 8 of these in the roboRIO, and they can be - * attached to any DigitalSource. - * - *

These can be combined as the input of an AnalogTrigger to a Counter in - * order to implement rollover checking. + * low in that frequency. These can be attached to any SmartIO. * */ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper { @@ -44,9 +41,9 @@ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper { /** * Get the frequency of the duty cycle signal. * - * @return frequency in Hertz + * @return frequency */ - int GetFrequency() const; + units::hertz_t GetFrequency() const; /** * Get the output ratio of the duty cycle signal. @@ -64,24 +61,6 @@ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper { */ units::second_t GetHighTime() const; - /** - * Get the scale factor of the output. - * - *

An output equal to this value is always high, and then linearly scales - * down to 0. Divide a raw result by this in order to get the - * percentage between 0 and 1. Used by DMA. - * - * @return the output scale factor - */ - unsigned int GetOutputScaleFactor() const; - - /** - * Get the FPGA index for the DutyCycle. - * - * @return the FPGA index - */ - int GetFPGAIndex() const; - /** * Get the channel of the source. * diff --git a/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h b/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h index 399bdddf96..3b3329eeed 100644 --- a/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h +++ b/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h @@ -103,11 +103,11 @@ class DutyCycleEncoder : public wpi::Sendable, DutyCycleEncoder& operator=(DutyCycleEncoder&&) = default; /** - * Get the frequency in Hz of the duty cycle signal from the encoder. + * Get the frequency of the duty cycle signal from the encoder. * - * @return duty cycle frequency in Hz + * @return duty cycle frequency */ - int GetFrequency() const; + units::hertz_t GetFrequency() const; /** * Get if the sensor is connected @@ -124,9 +124,9 @@ class DutyCycleEncoder : public wpi::Sendable, * Change the frequency threshold for detecting connection used by * IsConnected. * - * @param frequency the minimum frequency in Hz. + * @param frequency the minimum frequency. */ - void SetConnectedFrequencyThreshold(int frequency); + void SetConnectedFrequencyThreshold(units::hertz_t frequency); /** * Get the encoder value. @@ -170,13 +170,6 @@ class DutyCycleEncoder : public wpi::Sendable, */ void SetInverted(bool inverted); - /** - * Get the FPGA index for the DutyCycleEncoder. - * - * @return the FPGA index - */ - int GetFPGAIndex() const; - /** * Get the channel of the source. * @@ -191,7 +184,7 @@ class DutyCycleEncoder : public wpi::Sendable, double MapSensorRange(double pos) const; std::shared_ptr m_dutyCycle; - int m_frequencyThreshold = 100; + units::hertz_t m_frequencyThreshold = {100_Hz}; double m_fullRange; double m_expectedZero; units::second_t m_period{0_s}; diff --git a/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h b/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h index f6f89ebc44..c93cccb75f 100644 --- a/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h @@ -6,6 +6,8 @@ #include +#include + #include "frc/simulation/CallbackStore.h" namespace frc { @@ -27,23 +29,13 @@ class DutyCycleSim { explicit DutyCycleSim(const DutyCycle& dutyCycle); /** - * Creates a DutyCycleSim for a digital input channel. + * Creates a DutyCycleSim for a SmartIO channel. * - * @param channel digital input channel + * @param channel SmartIO channel * @return Simulated object - * @throws std::out_of_range if no DutyCycle is configured for that channel */ static DutyCycleSim CreateForChannel(int channel); - /** - * Creates a DutyCycleSim for a simulated index. - * The index is incremented for each simulated DutyCycle. - * - * @param index simulator index - * @return Simulated object - */ - static DutyCycleSim CreateForIndex(int index); - /** * Register a callback to be run when this duty cycle input is initialized. * @@ -85,14 +77,14 @@ class DutyCycleSim { * * @return the duty cycle frequency */ - int GetFrequency() const; + units::hertz_t GetFrequency() const; /** * Change the duty cycle frequency. * * @param frequency the new frequency */ - void SetFrequency(int frequency); + void SetFrequency(units::hertz_t frequency); /** * Register a callback to be run whenever the output changes. diff --git a/wpilibc/src/test/native/cpp/simulation/DutyCycleSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/DutyCycleSimTest.cpp index 996cb42da8..9fa0281cc7 100644 --- a/wpilibc/src/test/native/cpp/simulation/DutyCycleSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/DutyCycleSimTest.cpp @@ -15,7 +15,7 @@ namespace frc::sim { TEST(DutyCycleSimTest, Initialization) { HAL_Initialize(500, 0); - DutyCycleSim sim = DutyCycleSim::CreateForIndex(0); + DutyCycleSim sim = DutyCycleSim::CreateForChannel(2); EXPECT_FALSE(sim.GetInitialized()); BooleanCallback callback; @@ -38,12 +38,12 @@ TEST(DutyCycleSimTest, SetFrequency) { DutyCycle dc{2}; DutyCycleSim sim(dc); - IntCallback callback; + DoubleCallback callback; auto cb = sim.RegisterFrequencyCallback(callback.GetCallback(), false); - sim.SetFrequency(191); - EXPECT_EQ(191, sim.GetFrequency()); - EXPECT_EQ(191, dc.GetFrequency()); + sim.SetFrequency(191_Hz); + EXPECT_EQ(191_Hz, sim.GetFrequency()); + EXPECT_EQ(191_Hz, dc.GetFrequency()); EXPECT_TRUE(callback.WasTriggered()); EXPECT_EQ(191, callback.GetLastValue()); } diff --git a/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp b/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp index 9ad63fe0b5..29e175bde1 100644 --- a/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp @@ -35,7 +35,7 @@ TEST(SimInitializationTest, AllInitialize) { PWMSim pwmsim{0}; RoboRioSim rrsim; (void)rrsim; - DutyCycleSim dcsim = DutyCycleSim::CreateForIndex(0); + DutyCycleSim dcsim = DutyCycleSim::CreateForChannel(0); (void)dcsim; AddressableLEDSim adLED; } diff --git a/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp index 9d506f64fc..72d6875d5a 100644 --- a/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp @@ -60,7 +60,7 @@ class Robot : public frc::TimedRobot { fullRange - percentOfRange); frc::SmartDashboard::PutBoolean("Connected", connected); - frc::SmartDashboard::PutNumber("Frequency", frequency); + frc::SmartDashboard::PutNumber("Frequency", frequency.value()); frc::SmartDashboard::PutNumber("Output", output); frc::SmartDashboard::PutNumber("ShiftedOutput", shiftedOutput); } diff --git a/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp index 38a7d258fa..1ceeec8dc0 100644 --- a/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp @@ -21,7 +21,7 @@ class Robot : public frc::TimedRobot { // 1 is fully on, 0 is fully off auto output = m_dutyCycle.GetOutput(); - frc::SmartDashboard::PutNumber("Frequency", frequency); + frc::SmartDashboard::PutNumber("Frequency", frequency.value()); frc::SmartDashboard::PutNumber("Duty Cycle", output); } }; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java index c366152c61..d37e767639 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java @@ -50,7 +50,7 @@ public class DutyCycle implements Sendable, AutoCloseable { * * @return frequency in Hertz */ - public int getFrequency() { + public double getFrequency() { return DutyCycleJNI.getFrequency(m_handle); } @@ -74,27 +74,6 @@ public class DutyCycle implements Sendable, AutoCloseable { return DutyCycleJNI.getHighTime(m_handle); } - /** - * Get the scale factor of the output. - * - *

An output equal to this value is always high, and then linearly scales down to 0. Divide a - * raw result by this in order to get the percentage between 0 and 1. Used by DMA. - * - * @return the output scale factor - */ - public int getOutputScaleFactor() { - return DutyCycleJNI.getOutputScaleFactor(m_handle); - } - - /** - * Get the FPGA index for the DutyCycle. - * - * @return the FPGA index - */ - public final int getFPGAIndex() { - return DutyCycleJNI.getFPGAIndex(m_handle); - } - /** * Get the channel of the source. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycleEncoder.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycleEncoder.java index e5e58fe8c9..be8e5ca1fd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycleEncoder.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycleEncoder.java @@ -19,7 +19,7 @@ import edu.wpi.first.util.sendable.SendableRegistry; public class DutyCycleEncoder implements Sendable, AutoCloseable { private final DutyCycle m_dutyCycle; private boolean m_ownsDutyCycle; - private int m_frequencyThreshold = 100; + private double m_frequencyThreshold = 100; private double m_fullRange; private double m_expectedZero; private double m_periodNanos; @@ -165,7 +165,7 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable { * * @return duty cycle frequency in Hz */ - public int getFrequency() { + public double getFrequency() { return m_dutyCycle.getFrequency(); } @@ -190,7 +190,7 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable { * * @param frequency the minimum frequency in Hz. */ - public void setConnectedFrequencyThreshold(int frequency) { + public void setConnectedFrequencyThreshold(double frequency) { if (frequency < 0) { frequency = 0; } @@ -235,15 +235,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable { } } - /** - * Get the FPGA index for the DutyCycleEncoder. - * - * @return the FPGA index - */ - public int getFPGAIndex() { - return m_dutyCycle.getFPGAIndex(); - } - /** * Get the channel of the source. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java index 7042a282a4..2b9155d333 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java @@ -7,7 +7,6 @@ package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.hal.simulation.DutyCycleDataJNI; import edu.wpi.first.hal.simulation.NotifyCallback; import edu.wpi.first.wpilibj.DutyCycle; -import java.util.NoSuchElementException; /** Class to control a simulated duty cycle digital input. */ public class DutyCycleSim { @@ -19,7 +18,7 @@ public class DutyCycleSim { * @param dutyCycle DutyCycle to simulate */ public DutyCycleSim(DutyCycle dutyCycle) { - m_index = dutyCycle.getFPGAIndex(); + m_index = dutyCycle.getSourceChannel(); } private DutyCycleSim(int index) { @@ -27,29 +26,13 @@ public class DutyCycleSim { } /** - * Creates a DutyCycleSim for a digital input channel. + * Creates a DutyCycleSim for a SmartIO channel. * - * @param channel digital input channel + * @param channel SmartIO channel * @return Simulated object - * @throws NoSuchElementException if no DutyCycle is configured for that channel */ public static DutyCycleSim createForChannel(int channel) { - int index = DutyCycleDataJNI.findForChannel(channel); - if (index < 0) { - throw new NoSuchElementException("no duty cycle found for channel " + channel); - } - return new DutyCycleSim(index); - } - - /** - * Creates a DutyCycleSim for a simulated index. The index is incremented for each simulated - * DutyCycle. - * - * @param index simulator index - * @return Simulated object - */ - public static DutyCycleSim createForIndex(int index) { - return new DutyCycleSim(index); + return new DutyCycleSim(channel); } /** @@ -99,7 +82,7 @@ public class DutyCycleSim { * * @return the duty cycle frequency */ - public int getFrequency() { + public double getFrequency() { return DutyCycleDataJNI.getFrequency(m_index); } @@ -108,7 +91,7 @@ public class DutyCycleSim { * * @param frequency the new frequency */ - public void setFrequency(int frequency) { + public void setFrequency(double frequency) { DutyCycleDataJNI.setFrequency(m_index, frequency); } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DutyCycleSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DutyCycleSimTest.java index 5029aa368f..eda97e9aac 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DutyCycleSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DutyCycleSimTest.java @@ -12,13 +12,12 @@ import edu.wpi.first.hal.HAL; import edu.wpi.first.wpilibj.DutyCycle; import edu.wpi.first.wpilibj.simulation.testutils.BooleanCallback; import edu.wpi.first.wpilibj.simulation.testutils.DoubleCallback; -import edu.wpi.first.wpilibj.simulation.testutils.IntCallback; import org.junit.jupiter.api.Test; class DutyCycleSimTest { @Test void testInitialization() { - DutyCycleSim sim = DutyCycleSim.createForIndex(0); + DutyCycleSim sim = DutyCycleSim.createForChannel(2); assertFalse(sim.getInitialized()); BooleanCallback callback = new BooleanCallback(); @@ -36,7 +35,7 @@ class DutyCycleSimTest { HAL.initialize(500, 0); try (DutyCycle dc = new DutyCycle(2)) { - IntCallback callback = new IntCallback(); + DoubleCallback callback = new DoubleCallback(); DutyCycleSim sim = new DutyCycleSim(dc); try (CallbackStore cb = sim.registerFrequencyCallback(callback, false)) { sim.setFrequency(191); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java index e352e84076..d9baccc07b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java @@ -45,7 +45,7 @@ public class Robot extends TimedRobot { boolean connected = m_dutyCycleEncoder.isConnected(); // Duty Cycle Frequency in Hz - int frequency = m_dutyCycleEncoder.getFrequency(); + double frequency = m_dutyCycleEncoder.getFrequency(); // Output of encoder double output = m_dutyCycleEncoder.get(); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java index d4d91a2658..9a22771477 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java @@ -18,7 +18,7 @@ public class Robot extends TimedRobot { @Override public void robotPeriodic() { // Duty Cycle Frequency in Hz - int frequency = m_dutyCycle.getFrequency(); + double frequency = m_dutyCycle.getFrequency(); // Output of duty cycle, ranging from 0 to 1 // 1 is fully on, 0 is fully off