From b799b285b33c81f81812aa65144de674bc775848 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 28 Jan 2025 05:43:09 -0800 Subject: [PATCH] [hal, wpilib] Remove digital source from encoder (#7740) --- .../java/edu/wpi/first/hal/EncoderJNI.java | 28 +- hal/src/main/native/cpp/jni/EncoderJNI.cpp | 34 +-- hal/src/main/native/include/hal/Encoder.h | 39 +-- hal/src/main/native/sim/Encoder.cpp | 20 +- hal/src/main/native/systemcore/Encoder.cpp | 30 +- wpilibc/src/main/native/cpp/Encoder.cpp | 72 +---- wpilibc/src/main/native/include/frc/Encoder.h | 100 +------ .../java/edu/wpi/first/wpilibj/Encoder.java | 282 ++---------------- 8 files changed, 61 insertions(+), 544 deletions(-) diff --git a/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java b/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java index 59503f8c43e..87040eec7f9 100644 --- a/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java @@ -13,22 +13,15 @@ public class EncoderJNI extends JNIWrapper { /** * Initializes an encoder. * - * @param digitalSourceHandleA the A source handle (either a digital or analog trigger) - * @param analogTriggerTypeA the analog trigger type of the A source if it is an analog trigger - * @param digitalSourceHandleB the B source handle (either a digital or analog trigger) - * @param analogTriggerTypeB the analog trigger type of the B source if it is an analog trigger + * @param aChannel the A channel + * @param bChannel the B channel * @param reverseDirection true to reverse the counting direction from standard, otherwise false * @param encodingType the encoding type * @return the created encoder handle * @see "HAL_InitializeEncoder" */ public static native int initializeEncoder( - int digitalSourceHandleA, - int analogTriggerTypeA, - int digitalSourceHandleB, - int analogTriggerTypeB, - boolean reverseDirection, - int encodingType); + int aChannel, int bChannel, boolean reverseDirection, int encodingType); /** * Frees an encoder. @@ -212,21 +205,6 @@ public static native int initializeEncoder( */ public static native int getEncoderSamplesToAverage(int encoderHandle); - /** - * Sets the source for an index pulse on the encoder. - * - *

The index pulse can be used to cause an encoder to reset based on an external input. - * - * @param encoderHandle the encoder handle - * @param digitalSourceHandle the index source handle (either a HAL_AnalogTriggerHandle or a - * HAL_DigitalHandle) - * @param analogTriggerType the analog trigger type if the source is an analog trigger - * @param indexingType the index triggering type - * @see "HAL_SetEncoderIndexSource" - */ - public static native void setEncoderIndexSource( - int encoderHandle, int digitalSourceHandle, int analogTriggerType, int indexingType); - /** * Gets the FPGA index of the encoder. * diff --git a/hal/src/main/native/cpp/jni/EncoderJNI.cpp b/hal/src/main/native/cpp/jni/EncoderJNI.cpp index e15c36f8484..50845e8ee31 100644 --- a/hal/src/main/native/cpp/jni/EncoderJNI.cpp +++ b/hal/src/main/native/cpp/jni/EncoderJNI.cpp @@ -18,21 +18,17 @@ extern "C" { /* * Class: edu_wpi_first_hal_EncoderJNI * Method: initializeEncoder - * Signature: (IIIIZI)I + * Signature: (IIZI)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_EncoderJNI_initializeEncoder - (JNIEnv* env, jclass, jint digitalSourceHandleA, jint analogTriggerTypeA, - jint digitalSourceHandleB, jint analogTriggerTypeB, - jboolean reverseDirection, jint encodingType) + (JNIEnv* env, jclass, jint aChannel, jint bChannel, jboolean reverseDirection, + jint encodingType) { int32_t status = 0; - auto encoder = HAL_InitializeEncoder( - (HAL_Handle)digitalSourceHandleA, - (HAL_AnalogTriggerType)analogTriggerTypeA, - (HAL_Handle)digitalSourceHandleB, - (HAL_AnalogTriggerType)analogTriggerTypeB, reverseDirection, - (HAL_EncoderEncodingType)encodingType, &status); + auto encoder = + HAL_InitializeEncoder(aChannel, bChannel, reverseDirection, + (HAL_EncoderEncodingType)encodingType, &status); CheckStatusForceThrow(env, status); return (jint)encoder; } @@ -286,24 +282,6 @@ Java_edu_wpi_first_hal_EncoderJNI_getEncoderSamplesToAverage return returnValue; } -/* - * Class: edu_wpi_first_hal_EncoderJNI - * Method: setEncoderIndexSource - * Signature: (IIII)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_EncoderJNI_setEncoderIndexSource - (JNIEnv* env, jclass, jint id, jint digitalSourceHandle, - jint analogTriggerType, jint type) -{ - int32_t status = 0; - HAL_SetEncoderIndexSource((HAL_EncoderHandle)id, - (HAL_Handle)digitalSourceHandle, - (HAL_AnalogTriggerType)analogTriggerType, - (HAL_EncoderIndexingType)type, &status); - CheckStatus(env, status); -} - /* * Class: edu_wpi_first_hal_EncoderJNI * Method: getEncoderFPGAIndex diff --git a/hal/src/main/native/include/hal/Encoder.h b/hal/src/main/native/include/hal/Encoder.h index 749c282c1b4..968d1d905e8 100644 --- a/hal/src/main/native/include/hal/Encoder.h +++ b/hal/src/main/native/include/hal/Encoder.h @@ -41,25 +41,18 @@ extern "C" { /** * Initializes an encoder. * - * @param[in] digitalSourceHandleA the A source (either a HAL_DigitalHandle or a - * HAL_AnalogTriggerHandle) - * @param[in] analogTriggerTypeA the analog trigger type of the A source if it - * is an analog trigger - * @param[in] digitalSourceHandleB the B source (either a HAL_DigitalHandle or a - * HAL_AnalogTriggerHandle) - * @param[in] analogTriggerTypeB the analog trigger type of the B source if it - * is an analog trigger + * @param[in] aChannel the A channel + * @param[in] bChannel the B channel * @param[in] reverseDirection true to reverse the counting direction from * standard, otherwise false * @param[in] encodingType the encoding type * @param[out] status Error status variable. 0 on success. * @return the created encoder handle */ -HAL_EncoderHandle HAL_InitializeEncoder( - HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA, - HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB, - HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType, - int32_t* status); +HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel, + HAL_Bool reverseDirection, + HAL_EncoderEncodingType encodingType, + int32_t* status); /** * Frees an encoder. @@ -260,26 +253,6 @@ void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle, int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle, int32_t* status); -/** - * Sets the source for an index pulse on the encoder. - * - * The index pulse can be used to cause an encoder to reset based on an external - * input. - * - * @param[in] encoderHandle the encoder handle - * @param[in] digitalSourceHandle the index source handle (either a - * HAL_AnalogTriggerHandle or a - * HAL_DigitalHandle) - * @param[in] analogTriggerType the analog trigger type if the source is an - * analog trigger - * @param[in] type the index triggering type - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle, - HAL_Handle digitalSourceHandle, - HAL_AnalogTriggerType analogTriggerType, - HAL_EncoderIndexingType type, int32_t* status); - /** * Gets the FPGA index of the encoder. * diff --git a/hal/src/main/native/sim/Encoder.cpp b/hal/src/main/native/sim/Encoder.cpp index f7be2bdd9bd..fb469dcfe53 100644 --- a/hal/src/main/native/sim/Encoder.cpp +++ b/hal/src/main/native/sim/Encoder.cpp @@ -66,11 +66,10 @@ bool GetEncoderBaseHandle(HAL_EncoderHandle handle, } // namespace hal extern "C" { -HAL_EncoderHandle HAL_InitializeEncoder( - HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA, - HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB, - HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType, - int32_t* status) { +HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel, + HAL_Bool reverseDirection, + HAL_EncoderEncodingType encodingType, + int32_t* status) { hal::init::CheckInit(); HAL_Handle nativeHandle = HAL_kInvalidHandle; if (encodingType == HAL_EncoderEncodingType::HAL_Encoder_k4X) { @@ -95,8 +94,8 @@ HAL_EncoderHandle HAL_InitializeEncoder( return HAL_kInvalidHandle; } int16_t index = getHandleIndex(handle); - SimEncoderData[index].digitalChannelA = getHandleIndex(digitalSourceHandleA); - SimEncoderData[index].digitalChannelB = getHandleIndex(digitalSourceHandleB); + SimEncoderData[index].digitalChannelA = aChannel; + SimEncoderData[index].digitalChannelB = bChannel; SimEncoderData[index].initialized = true; SimEncoderData[index].reverseDirection = reverseDirection; SimEncoderData[index].simDevice = 0; @@ -328,13 +327,6 @@ int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle, return SimEncoderData[encoder->index].samplesToAverage; } -void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle, - HAL_Handle digitalSourceHandle, - HAL_AnalogTriggerType analogTriggerType, - HAL_EncoderIndexingType type, int32_t* status) { - // Not implemented yet -} - int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle, int32_t* status) { auto encoder = encoderHandles->Get(encoderHandle); diff --git a/hal/src/main/native/systemcore/Encoder.cpp b/hal/src/main/native/systemcore/Encoder.cpp index 1f2c4216dfb..b48de62b3ea 100644 --- a/hal/src/main/native/systemcore/Encoder.cpp +++ b/hal/src/main/native/systemcore/Encoder.cpp @@ -17,25 +17,15 @@ using namespace hal; -namespace hal { - -namespace init { +namespace hal::init { void InitializeEncoder() {} -} // namespace init - -bool GetEncoderBaseHandle(HAL_EncoderHandle handle, - HAL_FPGAEncoderHandle* fpgaHandle, - HAL_CounterHandle* counterHandle) { - return false; -} -} // namespace hal +} // namespace hal::init extern "C" { -HAL_EncoderHandle HAL_InitializeEncoder( - HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA, - HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB, - HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType, - int32_t* status) { +HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel, + HAL_Bool reverseDirection, + HAL_EncoderEncodingType encodingType, + int32_t* status) { hal::init::CheckInit(); *status = HAL_HANDLE_ERROR; return HAL_kInvalidHandle; @@ -150,14 +140,6 @@ HAL_EncoderEncodingType HAL_GetEncoderEncodingType( return HAL_Encoder_k4X; } -void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle, - HAL_Handle digitalSourceHandle, - HAL_AnalogTriggerType analogTriggerType, - HAL_EncoderIndexingType type, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle, int32_t* status) { *status = HAL_HANDLE_ERROR; diff --git a/wpilibc/src/main/native/cpp/Encoder.cpp b/wpilibc/src/main/native/cpp/Encoder.cpp index 522f4801faf..a3d4432747e 100644 --- a/wpilibc/src/main/native/cpp/Encoder.cpp +++ b/wpilibc/src/main/native/cpp/Encoder.cpp @@ -20,44 +20,7 @@ using namespace frc; Encoder::Encoder(int aChannel, int bChannel, bool reverseDirection, EncodingType encodingType) { - m_aSource = std::make_shared(aChannel); - m_bSource = std::make_shared(bChannel); - InitEncoder(reverseDirection, encodingType); - wpi::SendableRegistry::AddChild(this, m_aSource.get()); - wpi::SendableRegistry::AddChild(this, m_bSource.get()); -} - -Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource, - bool reverseDirection, EncodingType encodingType) - : m_aSource(aSource, wpi::NullDeleter()), - m_bSource(bSource, wpi::NullDeleter()) { - if (!m_aSource) { - throw FRC_MakeError(err::NullParameter, "aSource"); - } - if (!m_bSource) { - throw FRC_MakeError(err::NullParameter, "bSource"); - } - InitEncoder(reverseDirection, encodingType); -} - -Encoder::Encoder(DigitalSource& aSource, DigitalSource& bSource, - bool reverseDirection, EncodingType encodingType) - : m_aSource(&aSource, wpi::NullDeleter()), - m_bSource(&bSource, wpi::NullDeleter()) { - InitEncoder(reverseDirection, encodingType); -} - -Encoder::Encoder(std::shared_ptr aSource, - std::shared_ptr bSource, bool reverseDirection, - EncodingType encodingType) - : m_aSource(std::move(aSource)), m_bSource(std::move(bSource)) { - if (!m_aSource) { - throw FRC_MakeError(err::NullParameter, "aSource"); - } - if (!m_bSource) { - throw FRC_MakeError(err::NullParameter, "bSource"); - } - InitEncoder(reverseDirection, encodingType); + InitEncoder(aChannel, bChannel, reverseDirection, encodingType); } int Encoder::Get() const { @@ -172,24 +135,6 @@ int Encoder::GetSamplesToAverage() const { return result; } -void Encoder::SetIndexSource(int channel, Encoder::IndexingType type) { - // Force digital input if just given an index - m_indexSource = std::make_shared(channel); - wpi::SendableRegistry::AddChild(this, m_indexSource.get()); - SetIndexSource(*m_indexSource.get(), type); -} - -void Encoder::SetIndexSource(const DigitalSource& source, - Encoder::IndexingType type) { - int32_t status = 0; - HAL_SetEncoderIndexSource(m_encoder, source.GetPortHandleForRouting(), - static_cast( - source.GetAnalogTriggerTypeForRouting()), - static_cast(type), - &status); - FRC_CheckErrorStatus(status, "SetIndexSource"); -} - void Encoder::SetSimDevice(HAL_SimDeviceHandle device) { HAL_SetEncoderSimDevice(m_encoder, device); } @@ -219,22 +164,17 @@ void Encoder::InitSendable(wpi::SendableBuilder& builder) { nullptr); } -void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) { +void Encoder::InitEncoder(int aChannel, int bChannel, bool reverseDirection, + EncodingType encodingType) { int32_t status = 0; m_encoder = HAL_InitializeEncoder( - m_aSource->GetPortHandleForRouting(), - static_cast( - m_aSource->GetAnalogTriggerTypeForRouting()), - m_bSource->GetPortHandleForRouting(), - static_cast( - m_bSource->GetAnalogTriggerTypeForRouting()), - reverseDirection, static_cast(encodingType), - &status); + aChannel, bChannel, reverseDirection, + static_cast(encodingType), &status); FRC_CheckErrorStatus(status, "InitEncoder"); HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex() + 1, encodingType); - wpi::SendableRegistry::Add(this, "Encoder", m_aSource->GetChannel()); + // wpi::SendableRegistry::Add(this, "Encoder", m_aSource->GetChannel()); } double Encoder::DecodingScaleFactor() const { diff --git a/wpilibc/src/main/native/include/frc/Encoder.h b/wpilibc/src/main/native/include/frc/Encoder.h index f05c33cc048..e2e58e516d3 100644 --- a/wpilibc/src/main/native/include/frc/Encoder.h +++ b/wpilibc/src/main/native/include/frc/Encoder.h @@ -37,20 +37,6 @@ class Encoder : public CounterBase, public wpi::Sendable, public wpi::SendableHelper { public: - /** - * Encoder indexing types. - */ - enum IndexingType { - /// Reset while the signal is high. - kResetWhileHigh, - /// Reset while the signal is low. - kResetWhileLow, - /// Reset on falling edge of the signal. - kResetOnFallingEdge, - /// Reset on rising edge of the signal. - kResetOnRisingEdge - }; - /** * Encoder constructor. * @@ -77,62 +63,6 @@ class Encoder : public CounterBase, Encoder(int aChannel, int bChannel, bool reverseDirection = false, EncodingType encodingType = k4X); - /** - * Encoder constructor. - * - * Construct a Encoder given a and b channels as digital inputs. This is used - * in the case where the digital inputs are shared. The Encoder class will not - * allocate the digital inputs and assume that they already are counted. - * - * The counter will start counting immediately. - * - * @param aSource The source that should be used for the a channel. - * @param bSource the source that should be used for the b channel. - * @param reverseDirection represents the orientation of the encoder and - * inverts the output values if necessary so forward - * represents positive values. - * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X - * decoding. If 4X is selected, then an encoder FPGA - * object is used and the returned counts will be 4x - * the encoder spec'd value since all rising and - * falling edges are counted. If 1X or 2X are selected - * then a counter object will be used and the returned - * value will either exactly match the spec'd count or - * be double (2x) the spec'd count. - */ - Encoder(DigitalSource* aSource, DigitalSource* bSource, - bool reverseDirection = false, EncodingType encodingType = k4X); - - /** - * Encoder constructor. - * - * Construct a Encoder given a and b channels as digital inputs. This is used - * in the case where the digital inputs are shared. The Encoder class will not - * allocate the digital inputs and assume that they already are counted. - * - * The counter will start counting immediately. - * - * @param aSource The source that should be used for the a channel. - * @param bSource the source that should be used for the b channel. - * @param reverseDirection represents the orientation of the encoder and - * inverts the output values if necessary so forward - * represents positive values. - * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X - * decoding. If 4X is selected, then an encoder FPGA - * object is used and the returned counts will be 4x - * the encoder spec'd value since all rising and - * falling edges are counted. If 1X or 2X are selected - * then a counter object will be used and the returned - * value will either exactly match the spec'd count or - * be double (2x) the spec'd count. - */ - Encoder(DigitalSource& aSource, DigitalSource& bSource, - bool reverseDirection = false, EncodingType encodingType = k4X); - - Encoder(std::shared_ptr aSource, - std::shared_ptr bSource, bool reverseDirection = false, - EncodingType encodingType = k4X); - Encoder(Encoder&&) = default; Encoder& operator=(Encoder&&) = default; @@ -312,27 +242,6 @@ class Encoder : public CounterBase, */ int GetSamplesToAverage() const; - /** - * Set the index source for the encoder. - * - * When this source is activated, the encoder count automatically resets. - * - * @param channel A DIO channel to set as the encoder index - * @param type The state that will cause the encoder to reset - */ - void SetIndexSource(int channel, IndexingType type = kResetOnRisingEdge); - - /** - * Set the index source for the encoder. - * - * When this source is activated, the encoder count automatically resets. - * - * @param source A digital source to set as the encoder index - * @param type The state that will cause the encoder to reset - */ - void SetIndexSource(const DigitalSource& source, - IndexingType type = kResetOnRisingEdge); - /** * Indicates this encoder is used by a simulated device. * @@ -350,7 +259,8 @@ class Encoder : public CounterBase, * * This code allocates resources for Encoders and is common to all * constructors. The counter will start counting immediately. - * + * @param aChannel The a channel. + * @param bChannel The b channel. * @param reverseDirection If true, counts down instead of up (this is all * relative) * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X @@ -362,7 +272,8 @@ class Encoder : public CounterBase, * value will either exactly match the spec'd count or * be double (2x) the spec'd count. */ - void InitEncoder(bool reverseDirection, EncodingType encodingType); + void InitEncoder(int aChannel, int bChannel, bool reverseDirection, + EncodingType encodingType); /** * The scale needed to convert a raw counter value into a number of encoder @@ -370,9 +281,6 @@ class Encoder : public CounterBase, */ double DecodingScaleFactor() const; - std::shared_ptr m_aSource; // The A phase of the quad encoder - std::shared_ptr m_bSource; // The B phase of the quad encoder - std::shared_ptr m_indexSource = nullptr; hal::Handle m_encoder; }; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java index c851de15d07..b757fb13bab 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java @@ -10,7 +10,6 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.util.AllocationException; import edu.wpi.first.util.sendable.Sendable; import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.util.sendable.SendableRegistry; @@ -29,37 +28,6 @@ * before use. */ public class Encoder implements CounterBase, Sendable, AutoCloseable { - /** Encoder indexing types. */ - public enum IndexingType { - /** Reset while the signal is high. */ - kResetWhileHigh(0), - /** Reset while the signal is low. */ - kResetWhileLow(1), - /** Reset on falling edge of the signal. */ - kResetOnFallingEdge(2), - /** Reset on rising edge of the signal. */ - kResetOnRisingEdge(3); - - /** IndexingType value. */ - public final int value; - - IndexingType(int value) { - this.value = value; - } - } - - /** The 'a' source. */ - protected DigitalSource m_aSource; // the A phase of the quad encoder - - /** The 'b' source. */ - protected DigitalSource m_bSource; // the B phase of the quad encoder - - /** The index source. */ - protected DigitalSource m_indexSource; // Index on some encoders - - private boolean m_allocatedA; - private boolean m_allocatedB; - private boolean m_allocatedI; private final EncodingType m_encodingType; int m_encoder; // the HAL encoder object @@ -70,17 +38,13 @@ public enum IndexingType { * *

The encoder will start counting immediately. * + * @param aChannel The a channel. + * @param bChannel The b channel. * @param reverseDirection If true, counts down instead of up (this is all relative) */ - private void initEncoder(boolean reverseDirection, final EncodingType type) { - m_encoder = - EncoderJNI.initializeEncoder( - m_aSource.getPortHandleForRouting(), - m_aSource.getAnalogTriggerTypeForRouting(), - m_bSource.getPortHandleForRouting(), - m_bSource.getAnalogTriggerTypeForRouting(), - reverseDirection, - type.value); + private void initEncoder( + int aChannel, int bChannel, boolean reverseDirection, final EncodingType type) { + m_encoder = EncoderJNI.initializeEncoder(aChannel, bChannel, reverseDirection, type.value); int fpgaIndex = getFPGAIndex(); HAL.report(tResourceType.kResourceType_Encoder, fpgaIndex + 1, type.value + 1); @@ -136,156 +100,10 @@ public Encoder( final EncodingType encodingType) { requireNonNullParam(encodingType, "encodingType", "Encoder"); - m_allocatedA = true; - m_allocatedB = true; - m_allocatedI = false; - m_aSource = new DigitalInput(channelA); - m_bSource = new DigitalInput(channelB); - m_encodingType = encodingType; - SendableRegistry.addChild(this, m_aSource); - SendableRegistry.addChild(this, m_bSource); - initEncoder(reverseDirection, encodingType); - } - - /** - * Encoder constructor. Construct an Encoder given a and b channels. Using an index pulse forces - * 4x encoding - * - *

The encoder will start counting immediately. - * - * @param channelA The a channel digital input channel. - * @param channelB The b channel digital input channel. - * @param indexChannel The index channel digital input channel. - * @param reverseDirection represents the orientation of the encoder and inverts the output values - * if necessary so forward represents positive values. - */ - @SuppressWarnings("this-escape") - public Encoder( - final int channelA, final int channelB, final int indexChannel, boolean reverseDirection) { - this(channelA, channelB, reverseDirection); - m_allocatedI = true; - m_indexSource = new DigitalInput(indexChannel); - SendableRegistry.addChild(this, m_indexSource); - setIndexSource(m_indexSource); - } - - /** - * Encoder constructor. Construct an Encoder given a and b channels. Using an index pulse forces - * 4x encoding - * - *

The encoder will start counting immediately. - * - * @param channelA The a channel digital input channel. - * @param channelB The b channel digital input channel. - * @param indexChannel The index channel digital input channel. - */ - public Encoder(final int channelA, final int channelB, final int indexChannel) { - this(channelA, channelB, indexChannel, false); - } - - /** - * Encoder constructor. Construct an Encoder given a and b channels as digital inputs. This is - * used in the case where the digital inputs are shared. The Encoder class will not allocate the - * digital inputs and assume that they already are counted. - * - *

The encoder will start counting immediately. - * - * @param sourceA The source that should be used for the 'a' channel. - * @param sourceB the source that should be used for the 'b' channel. - * @param reverseDirection represents the orientation of the encoder and inverts the output values - * if necessary so forward represents positive values. - */ - public Encoder(DigitalSource sourceA, DigitalSource sourceB, boolean reverseDirection) { - this(sourceA, sourceB, reverseDirection, EncodingType.k4X); - } - - /** - * Encoder constructor. Construct an Encoder given a and b channels as digital inputs. This is - * used in the case where the digital inputs are shared. The Encoder class will not allocate the - * digital inputs and assume that they already are counted. - * - *

The encoder will start counting immediately. - * - * @param sourceA The source that should be used for the 'a' channel. - * @param sourceB the source that should be used for the 'b' channel. - */ - public Encoder(DigitalSource sourceA, DigitalSource sourceB) { - this(sourceA, sourceB, false); - } - - /** - * Encoder constructor. Construct an Encoder given a and b channels as digital inputs. This is - * used in the case where the digital inputs are shared. The Encoder class will not allocate the - * digital inputs and assume that they already are counted. - * - *

The encoder will start counting immediately. - * - * @param sourceA The source that should be used for the 'a' channel. - * @param sourceB the source that should be used for the 'b' channel. - * @param reverseDirection represents the orientation of the encoder and inverts the output values - * if necessary so forward represents positive values. - * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X decoding. If 4X is - * selected, then an encoder FPGA object is used and the returned counts will be 4x the - * encoder spec'd value since all rising and falling edges are counted. If 1X or 2X are - * selected then a counter object will be used and the returned value will either exactly - * match the spec'd count or be double (2x) the spec'd count. - */ - @SuppressWarnings("this-escape") - public Encoder( - DigitalSource sourceA, - DigitalSource sourceB, - boolean reverseDirection, - final EncodingType encodingType) { - requireNonNullParam(sourceA, "sourceA", "Encoder"); - requireNonNullParam(sourceB, "sourceB", "Encoder"); - requireNonNullParam(encodingType, "encodingType", "Encoder"); - - m_allocatedA = false; - m_allocatedB = false; - m_allocatedI = false; m_encodingType = encodingType; - m_aSource = sourceA; - m_bSource = sourceB; - initEncoder(reverseDirection, encodingType); - } - - /** - * Encoder constructor. Construct an Encoder given a, b and index channels as digital inputs. This - * is used in the case where the digital inputs are shared. The Encoder class will not allocate - * the digital inputs and assume that they already are counted. - * - *

The encoder will start counting immediately. - * - * @param sourceA The source that should be used for the 'a' channel. - * @param sourceB the source that should be used for the 'b' channel. - * @param indexSource the source that should be used for the index channel. - * @param reverseDirection represents the orientation of the encoder and inverts the output values - * if necessary so forward represents positive values. - */ - public Encoder( - DigitalSource sourceA, - DigitalSource sourceB, - DigitalSource indexSource, - boolean reverseDirection) { - this(sourceA, sourceB, reverseDirection); - m_allocatedI = false; - m_indexSource = indexSource; - setIndexSource(indexSource); - } - - /** - * Encoder constructor. Construct an Encoder given a, b and index channels as digital inputs. This - * is used in the case where the digital inputs are shared. The Encoder class will not allocate - * the digital inputs and assume that they already are counted. - * - *

The encoder will start counting immediately. - * - * @param sourceA The source that should be used for the 'a' channel. - * @param sourceB the source that should be used for the 'b' channel. - * @param indexSource the source that should be used for the index channel. - */ - public Encoder(DigitalSource sourceA, DigitalSource sourceB, DigitalSource indexSource) { - this(sourceA, sourceB, indexSource, false); + // SendableRegistry.addChild(this, m_aSource); + // SendableRegistry.addChild(this, m_bSource); + initEncoder(channelA, channelB, reverseDirection, encodingType); } /** @@ -309,22 +127,22 @@ public int getEncodingScale() { @Override public void close() { SendableRegistry.remove(this); - if (m_aSource != null && m_allocatedA) { - m_aSource.close(); - m_allocatedA = false; - } - if (m_bSource != null && m_allocatedB) { - m_bSource.close(); - m_allocatedB = false; - } - if (m_indexSource != null && m_allocatedI) { - m_indexSource.close(); - m_allocatedI = false; - } - - m_aSource = null; - m_bSource = null; - m_indexSource = null; + // if (m_aSource != null && m_allocatedA) { + // m_aSource.close(); + // m_allocatedA = false; + // } + // if (m_bSource != null && m_allocatedB) { + // m_bSource.close(); + // m_allocatedB = false; + // } + // if (m_indexSource != null && m_allocatedI) { + // m_indexSource.close(); + // m_allocatedI = false; + // } + + // m_aSource = null; + // m_bSource = null; + // m_indexSource = null; EncoderJNI.freeEncoder(m_encoder); m_encoder = 0; } @@ -495,58 +313,6 @@ public int getSamplesToAverage() { return EncoderJNI.getEncoderSamplesToAverage(m_encoder); } - /** - * Set the index source for the encoder. When this source is activated, the encoder count - * automatically resets. - * - * @param channel A DIO channel to set as the encoder index - */ - public final void setIndexSource(int channel) { - setIndexSource(channel, IndexingType.kResetOnRisingEdge); - } - - /** - * Set the index source for the encoder. When this source is activated, the encoder count - * automatically resets. - * - * @param source A digital source to set as the encoder index - */ - public final void setIndexSource(DigitalSource source) { - setIndexSource(source, IndexingType.kResetOnRisingEdge); - } - - /** - * Set the index source for the encoder. When this source rises, the encoder count automatically - * resets. - * - * @param channel A DIO channel to set as the encoder index - * @param type The state that will cause the encoder to reset - */ - public final void setIndexSource(int channel, IndexingType type) { - if (m_allocatedI) { - throw new AllocationException("Digital Input for Indexing already allocated"); - } - m_indexSource = new DigitalInput(channel); - m_allocatedI = true; - SendableRegistry.addChild(this, m_indexSource); - setIndexSource(m_indexSource, type); - } - - /** - * Set the index source for the encoder. When this source rises, the encoder count automatically - * resets. - * - * @param source A digital source to set as the encoder index - * @param type The state that will cause the encoder to reset - */ - public final void setIndexSource(DigitalSource source, IndexingType type) { - EncoderJNI.setEncoderIndexSource( - m_encoder, - source.getPortHandleForRouting(), - source.getAnalogTriggerTypeForRouting(), - type.value); - } - /** * Indicates this input is used by a simulated device. *