From df33a782213528a3a1a6e4fc5d8a21a8c408300a Mon Sep 17 00:00:00 2001 From: Omar Zrien Date: Mon, 8 Feb 2016 18:32:08 -0500 Subject: [PATCH] Added Config routine to allow enabling/disabling of limit switch and soft limits. This improves upon the ConfigLimitMode routine, which does not allow certain combinations of enable/disabled limit features. Also keeps parity with LV and Java. Change-Id: Id2f4c9f169effc6bc3ea48529e8f04f387609ddc --- wpilibc/Athena/include/CANTalon.h | 3 ++ wpilibc/Athena/src/CANTalon.cpp | 64 ++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/wpilibc/Athena/include/CANTalon.h b/wpilibc/Athena/include/CANTalon.h index 2d866d197b..8ea9ae169c 100644 --- a/wpilibc/Athena/include/CANTalon.h +++ b/wpilibc/Athena/include/CANTalon.h @@ -286,6 +286,9 @@ class CANTalon : public MotorSafety, virtual void ConfigLimitMode(LimitMode mode) override; virtual void ConfigForwardLimit(double forwardLimitPosition) override; virtual void ConfigReverseLimit(double reverseLimitPosition) override; + void ConfigLimitSwitchOverrides(bool bForwardLimitSwitchEn, bool bReverseLimitSwitchEn); + void ConfigForwardSoftLimitEnable(bool bForwardSoftLimitEn); + void ConfigReverseSoftLimitEnable(bool bReverseSoftLimitEn); /** * Change the fwd limit switch setting to normally open or closed. * Talon will disable momentarilly if the Talon's current setting diff --git a/wpilibc/Athena/src/CANTalon.cpp b/wpilibc/Athena/src/CANTalon.cpp index 2198eda08d..e59982cff6 100644 --- a/wpilibc/Athena/src/CANTalon.cpp +++ b/wpilibc/Athena/src/CANTalon.cpp @@ -1212,7 +1212,43 @@ void CANTalon::DisableSoftPositionLimits() { } /** - * TODO documentation (see CANJaguar.cpp) + * Overrides the forward and reverse limit switch enables. + * Unlike ConfigLimitMode, this function allows individual control of forward and + * reverse limit switch enables. + * Unlike ConfigLimitMode, this function does not affect the soft-limit features of Talon SRX. + * @see ConfigLimitMode() + */ +void CANTalon::ConfigLimitSwitchOverrides(bool bForwardLimitSwitchEn, bool bReverseLimitSwitchEn) { + CTR_Code status = CTR_OKAY; + int fwdRevEnable; + /* chose correct signal value based on caller's requests enables */ + if(!bForwardLimitSwitchEn) { + /* caller wants Forward Limit Switch OFF */ + if(!bReverseLimitSwitchEn) { + /* caller wants both OFF */ + fwdRevEnable = CanTalonSRX::kLimitSwitchOverride_DisableFwd_DisableRev; + } else { + /* caller Forward OFF and Reverse ON */ + fwdRevEnable = CanTalonSRX::kLimitSwitchOverride_DisableFwd_EnableRev; + } + } else { + /* caller wants Forward Limit Switch ON */ + if(!bReverseLimitSwitchEn) { + /* caller wants Forward ON and Reverse OFF */ + fwdRevEnable = CanTalonSRX::kLimitSwitchOverride_EnableFwd_DisableRev; + } else { + /* caller wants both ON */ + fwdRevEnable = CanTalonSRX::kLimitSwitchOverride_EnableFwd_EnableRev; + } + } + /* update signal and error check code */ + status = m_impl->SetOverrideLimitSwitchEn(fwdRevEnable); + if (status != CTR_OKAY) { + wpi_setErrorWithContext(status, getHALErrorMessage(status)); + } +} + +/** * Configures the soft limit enable (wear leveled persistent memory). * Also sets the limit switch overrides. */ @@ -1289,6 +1325,32 @@ void CANTalon::ConfigForwardLimit(double forwardLimitPosition) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } } + +/** + * Set the Forward Soft Limit Enable. + * This is the same setting that is in the Web-Based Configuration. + * @param bForwardSoftLimitEn true to enable Soft limit, false to disable. + */ +void CANTalon::ConfigForwardSoftLimitEnable(bool bForwardSoftLimitEn) { + CTR_Code status = CTR_OKAY; + status = m_impl->SetForwardSoftEnable(bForwardSoftLimitEn); + if (status != CTR_OKAY) { + wpi_setErrorWithContext(status, getHALErrorMessage(status)); + } +} + +/** + * Set the Reverse Soft Limit Enable. + * This is the same setting that is in the Web-Based Configuration. + * @param bReverseSoftLimitEn true to enable Soft limit, false to disable. + */ +void CANTalon::ConfigReverseSoftLimitEnable(bool bReverseSoftLimitEn) { + CTR_Code status = CTR_OKAY; + status = m_impl->SetReverseSoftEnable(bReverseSoftLimitEn); + if (status != CTR_OKAY) { + wpi_setErrorWithContext(status, getHALErrorMessage(status)); + } +} /** * Change the fwd limit switch setting to normally open or closed. * Talon will disable momentarilly if the Talon's current setting