diff --git a/wpilibc/Athena/include/Jaguar.h b/wpilibc/Athena/include/Jaguar.h index c129559869..34b1cd91a9 100644 --- a/wpilibc/Athena/include/Jaguar.h +++ b/wpilibc/Athena/include/Jaguar.h @@ -7,26 +7,13 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * Luminary Micro / Vex Robotics Jaguar Speed Controller with PWM control */ -class Jaguar : public SafePWM, public SpeedController { +class Jaguar : public PWMSpeedController { public: explicit Jaguar(uint32_t channel); virtual ~Jaguar() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - virtual void StopMotor() override; - - virtual void PIDWrite(float output) override; - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/PWMSpeedController.h b/wpilibc/Athena/include/PWMSpeedController.h new file mode 100644 index 0000000000..5b10972804 --- /dev/null +++ b/wpilibc/Athena/include/PWMSpeedController.h @@ -0,0 +1,32 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include "SafePWM.h" +#include "SpeedController.h" + +/** + * Common base class for all PWM Speed Controllers + */ +class PWMSpeedController : public SafePWM, public SpeedController { + public: + virtual ~PWMSpeedController() = default; + virtual void Set(float value, uint8_t syncGroup = 0) override; + virtual float Get() const override; + virtual void Disable() override; + virtual void StopMotor() override; + + virtual void PIDWrite(float output) override; + + virtual void SetInverted(bool isInverted) override; + virtual bool GetInverted() const override; + protected: + explicit PWMSpeedController(uint32_t channel); + private: + bool m_isInverted = false; +}; \ No newline at end of file diff --git a/wpilibc/Athena/include/SD540.h b/wpilibc/Athena/include/SD540.h index 9e98678929..94a1734859 100644 --- a/wpilibc/Athena/include/SD540.h +++ b/wpilibc/Athena/include/SD540.h @@ -7,27 +7,13 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * Mindsensors SD540 Speed Controller */ -class SD540 : public SafePWM, public SpeedController { +class SD540 : public PWMSpeedController { public: explicit SD540(uint32_t channel); virtual ~SD540() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - virtual void StopMotor() override; - - virtual void PIDWrite(float output) override; - - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/Spark.h b/wpilibc/Athena/include/Spark.h index d4859ce216..af5fafeb9a 100644 --- a/wpilibc/Athena/include/Spark.h +++ b/wpilibc/Athena/include/Spark.h @@ -7,27 +7,13 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * REV Robotics Speed Controller */ -class Spark : public SafePWM, public SpeedController { +class Spark : public PWMSpeedController { public: explicit Spark(uint32_t channel); virtual ~Spark() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - virtual void StopMotor() override; - - virtual void PIDWrite(float output) override; - - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/Talon.h b/wpilibc/Athena/include/Talon.h index 0a8801229b..6205acca8e 100644 --- a/wpilibc/Athena/include/Talon.h +++ b/wpilibc/Athena/include/Talon.h @@ -7,26 +7,13 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller */ -class Talon : public SafePWM, public SpeedController { +class Talon : public PWMSpeedController { public: explicit Talon(uint32_t channel); virtual ~Talon() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - - virtual void PIDWrite(float output) override; - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - virtual void StopMotor() override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/TalonSRX.h b/wpilibc/Athena/include/TalonSRX.h index 61b1fd8fbe..78725c339f 100644 --- a/wpilibc/Athena/include/TalonSRX.h +++ b/wpilibc/Athena/include/TalonSRX.h @@ -7,27 +7,14 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * Cross the Road Electronics (CTRE) Talon SRX Speed Controller with PWM control * @see CANTalon for CAN control */ -class TalonSRX : public SafePWM, public SpeedController { +class TalonSRX : public PWMSpeedController { public: explicit TalonSRX(uint32_t channel); virtual ~TalonSRX() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - virtual void StopMotor() override; - - virtual void PIDWrite(float output) override; - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/Victor.h b/wpilibc/Athena/include/Victor.h index 2aa2ecfd2b..9abc828213 100644 --- a/wpilibc/Athena/include/Victor.h +++ b/wpilibc/Athena/include/Victor.h @@ -7,9 +7,7 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * Vex Robotics Victor 888 Speed Controller @@ -17,20 +15,8 @@ * The Vex Robotics Victor 884 Speed Controller can also be used with this * class but may need to be calibrated per the Victor 884 user manual. */ -class Victor : public SafePWM, public SpeedController { +class Victor : public PWMSpeedController { public: explicit Victor(uint32_t channel); virtual ~Victor() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - virtual void StopMotor() override; - - virtual void PIDWrite(float output) override; - - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/VictorSP.h b/wpilibc/Athena/include/VictorSP.h index a53ccfde77..bc75e7fc63 100644 --- a/wpilibc/Athena/include/VictorSP.h +++ b/wpilibc/Athena/include/VictorSP.h @@ -7,27 +7,13 @@ #pragma once -#include "SafePWM.h" -#include "SpeedController.h" -#include "PIDOutput.h" +#include "PWMSpeedController.h" /** * Vex Robotics Victor SP Speed Controller */ -class VictorSP : public SafePWM, public SpeedController { +class VictorSP : public PWMSpeedController { public: explicit VictorSP(uint32_t channel); virtual ~VictorSP() = default; - virtual void Set(float value, uint8_t syncGroup = 0) override; - virtual float Get() const override; - virtual void Disable() override; - virtual void StopMotor() override; - - virtual void PIDWrite(float output) override; - - virtual void SetInverted(bool isInverted) override; - virtual bool GetInverted() const override; - - private: - bool m_isInverted = false; }; diff --git a/wpilibc/Athena/include/WPILib.h b/wpilibc/Athena/include/WPILib.h index 8780c8507c..ad7c26ef32 100644 --- a/wpilibc/Athena/include/WPILib.h +++ b/wpilibc/Athena/include/WPILib.h @@ -69,6 +69,7 @@ #include "Preferences.h" #include "PowerDistributionPanel.h" #include "PWM.h" +#include "PWMSpeedController.h" #include "Relay.h" #include "Resource.h" #include "RobotBase.h" diff --git a/wpilibc/Athena/src/Jaguar.cpp b/wpilibc/Athena/src/Jaguar.cpp index b2bd57aacb..29d603c34d 100644 --- a/wpilibc/Athena/src/Jaguar.cpp +++ b/wpilibc/Athena/src/Jaguar.cpp @@ -13,7 +13,7 @@ * @param channel The PWM channel that the Jaguar is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -Jaguar::Jaguar(uint32_t channel) : SafePWM(channel) { +Jaguar::Jaguar(uint32_t channel) : PWMSpeedController(channel) { /** * Input profile defined by Luminary Micro. * @@ -32,53 +32,3 @@ Jaguar::Jaguar(uint32_t channel) : SafePWM(channel) { LiveWindow::GetInstance()->AddActuator("Jaguar", GetChannel(), this); } -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void Jaguar::Set(float speed, uint8_t syncGroup) { - SetSpeed(m_isInverted ? -speed : speed); -} - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float Jaguar::Get() const { return GetSpeed(); } - -/** - * Common interface for disabling a motor. - */ -void Jaguar::Disable() { SetRaw(kPwmDisabled); } - -/** -* Common interface for inverting direction of a speed controller. -* @param isInverted The state of inversion, true is inverted. -*/ -void Jaguar::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool Jaguar::GetInverted() const { return m_isInverted; } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void Jaguar::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void Jaguar::StopMotor() { this->SafePWM::StopMotor(); } \ No newline at end of file diff --git a/wpilibc/Athena/src/PWMSpeedController.cpp b/wpilibc/Athena/src/PWMSpeedController.cpp new file mode 100644 index 0000000000..ee93a170d0 --- /dev/null +++ b/wpilibc/Athena/src/PWMSpeedController.cpp @@ -0,0 +1,67 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#include "PWMSpeedController.h" + +/** + * Constructor for a PWM Speed Controller connected via PWM + * @param channel The PWM channel that the controller is attached to. 0-9 are + * on-board, 10-19 are on the MXP port + */ +PWMSpeedController::PWMSpeedController(uint32_t channel) : SafePWM(channel) { +} + +/** + * Set the PWM value. + * + * The PWM value is set using a range of -1.0 to 1.0, appropriately + * scaling the value for the FPGA. + * + * @param speed The speed value between -1.0 and 1.0 to set. + * @param syncGroup Unused interface. + */ +void PWMSpeedController::Set(float speed, uint8_t syncGroup) { + SetSpeed(m_isInverted ? -speed : speed); +} + +/** + * Get the recently set value of the PWM. + * + * @return The most recently set value for the PWM between -1.0 and 1.0. + */ +float PWMSpeedController::Get() const { return GetSpeed(); } + +/** + * Common interface for disabling a motor. + */ +void PWMSpeedController::Disable() { SetRaw(kPwmDisabled); } + +/** +* Common interface for inverting direction of a speed controller. +* @param isInverted The state of inversion, true is inverted. +*/ +void PWMSpeedController::SetInverted(bool isInverted) { m_isInverted = isInverted; } + +/** + * Common interface for the inverting direction of a speed controller. + * + * @return isInverted The state of inversion, true is inverted. + * + */ +bool PWMSpeedController::GetInverted() const { return m_isInverted; } + +/** + * Write out the PID value as seen in the PIDOutput base object. + * + * @param output Write out the PWM value as was found in the PIDController + */ +void PWMSpeedController::PIDWrite(float output) { Set(output); } + +/** + * Common interface to stop the motor until Set is called again. + */ +void PWMSpeedController::StopMotor() { this->SafePWM::StopMotor(); } \ No newline at end of file diff --git a/wpilibc/Athena/src/SD540.cpp b/wpilibc/Athena/src/SD540.cpp index 9d2ad1eb0d..b74c18be5f 100644 --- a/wpilibc/Athena/src/SD540.cpp +++ b/wpilibc/Athena/src/SD540.cpp @@ -31,7 +31,7 @@ * @param channel The PWM channel that the SD540 is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -SD540::SD540(uint32_t channel) : SafePWM(channel) { +SD540::SD540(uint32_t channel) : PWMSpeedController(channel) { SetBounds(2.05, 1.55, 1.50, 1.44, .94); SetPeriodMultiplier(kPeriodMultiplier_1X); SetRaw(m_centerPwm); @@ -41,53 +41,3 @@ SD540::SD540(uint32_t channel) : SafePWM(channel) { LiveWindow::GetInstance()->AddActuator("SD540", GetChannel(), this); } -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void SD540::Set(float speed, uint8_t syncGroup) { - SetSpeed(m_isInverted ? -speed : speed); -} - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float SD540::Get() const { return GetSpeed(); } - -/** - * Common interface for inverting direction of a speed controller. - * @param isInverted The state of inversion, true is inverted. - */ -void SD540::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool SD540::GetInverted() const { return m_isInverted; } - -/** - * Common interface for disabling a motor. - */ -void SD540::Disable() { SetRaw(kPwmDisabled); } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void SD540::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void SD540::StopMotor() { this->SafePWM::StopMotor(); } diff --git a/wpilibc/Athena/src/Spark.cpp b/wpilibc/Athena/src/Spark.cpp index 35171220b0..35643b542a 100644 --- a/wpilibc/Athena/src/Spark.cpp +++ b/wpilibc/Athena/src/Spark.cpp @@ -31,7 +31,7 @@ * @param channel The PWM channel that the Spark is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -Spark::Spark(uint32_t channel) : SafePWM(channel) { +Spark::Spark(uint32_t channel) : PWMSpeedController(channel) { SetBounds(2.003, 1.55, 1.50, 1.46, .999); SetPeriodMultiplier(kPeriodMultiplier_1X); SetRaw(m_centerPwm); @@ -40,54 +40,3 @@ Spark::Spark(uint32_t channel) : SafePWM(channel) { HALReport(HALUsageReporting::kResourceType_RevSPARK, GetChannel()); LiveWindow::GetInstance()->AddActuator("Spark", GetChannel(), this); } - -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void Spark::Set(float speed, uint8_t syncGroup) { - SetSpeed(m_isInverted ? -speed : speed); -} - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float Spark::Get() const { return GetSpeed(); } - -/** - * Common interface for inverting direction of a speed controller. - * @param isInverted The state of inversion, true is inverted. - */ -void Spark::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool Spark::GetInverted() const { return m_isInverted; } - -/** - * Common interface for disabling a motor. - */ -void Spark::Disable() { SetRaw(kPwmDisabled); } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void Spark::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void Spark::StopMotor() { this->SafePWM::StopMotor(); } \ No newline at end of file diff --git a/wpilibc/Athena/src/Talon.cpp b/wpilibc/Athena/src/Talon.cpp index 64f9db83ea..e3674d11cc 100644 --- a/wpilibc/Athena/src/Talon.cpp +++ b/wpilibc/Athena/src/Talon.cpp @@ -14,7 +14,7 @@ * @param channel The PWM channel number that the Talon is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -Talon::Talon(uint32_t channel) : SafePWM(channel) { +Talon::Talon(uint32_t channel) : PWMSpeedController(channel) { /* Note that the Talon uses the following bounds for PWM values. These values * should work reasonably well for most controllers, but if users experience * issues such as asymmetric behavior around the deadband or inability to @@ -36,54 +36,3 @@ Talon::Talon(uint32_t channel) : SafePWM(channel) { HALReport(HALUsageReporting::kResourceType_Talon, GetChannel()); LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this); } - -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void Talon::Set(float speed, uint8_t syncGroup) { - SetSpeed(m_isInverted ? -speed : speed); -} - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float Talon::Get() const { return GetSpeed(); } - -/** - * Common interface for disabling a motor. - */ -void Talon::Disable() { SetRaw(kPwmDisabled); } - -/** -* common interface for inverting direction of a speed controller -* @param isInverted The state of inversion true is inverted -*/ -void Talon::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool Talon::GetInverted() const { return m_isInverted; } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void Talon::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void Talon::StopMotor() { this->SafePWM::StopMotor(); } diff --git a/wpilibc/Athena/src/TalonSRX.cpp b/wpilibc/Athena/src/TalonSRX.cpp index e06f8ca2aa..22cefac174 100644 --- a/wpilibc/Athena/src/TalonSRX.cpp +++ b/wpilibc/Athena/src/TalonSRX.cpp @@ -14,7 +14,7 @@ * @param channel The PWM channel that the TalonSRX is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -TalonSRX::TalonSRX(uint32_t channel) : SafePWM(channel) { +TalonSRX::TalonSRX(uint32_t channel) : PWMSpeedController(channel) { /* Note that the TalonSRX uses the following bounds for PWM values. These * values should work reasonably well for most controllers, but if users * experience issues such as asymmetric behavior around the deadband or @@ -35,52 +35,3 @@ TalonSRX::TalonSRX(uint32_t channel) : SafePWM(channel) { HALReport(HALUsageReporting::kResourceType_TalonSRX, GetChannel()); LiveWindow::GetInstance()->AddActuator("TalonSRX", GetChannel(), this); } - -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void TalonSRX::Set(float speed, uint8_t syncGroup) { SetSpeed(speed); } - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float TalonSRX::Get() const { return GetSpeed(); } - -/** - * Common interface for disabling a motor. - */ -void TalonSRX::Disable() { SetRaw(kPwmDisabled); } - -/** -* Common interface for inverting direction of a speed controller. -* @param isInverted The state of inversion, true is inverted. -*/ -void TalonSRX::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool TalonSRX::GetInverted() const { return m_isInverted; } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void TalonSRX::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void TalonSRX::StopMotor() { this->SafePWM::StopMotor(); } \ No newline at end of file diff --git a/wpilibc/Athena/src/Victor.cpp b/wpilibc/Athena/src/Victor.cpp index 81c863c1ea..1a3f0c463b 100644 --- a/wpilibc/Athena/src/Victor.cpp +++ b/wpilibc/Athena/src/Victor.cpp @@ -14,7 +14,7 @@ * @param channel The PWM channel number that the Victor is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -Victor::Victor(uint32_t channel) : SafePWM(channel) { +Victor::Victor(uint32_t channel) : PWMSpeedController(channel) { /* Note that the Victor uses the following bounds for PWM values. These * values were determined empirically and optimized for the Victor 888. These * values should work reasonably well for Victor 884 controllers as well but @@ -37,53 +37,3 @@ Victor::Victor(uint32_t channel) : SafePWM(channel) { LiveWindow::GetInstance()->AddActuator("Victor", GetChannel(), this); HALReport(HALUsageReporting::kResourceType_Victor, GetChannel()); } - -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void Victor::Set(float speed, uint8_t syncGroup) { - SetSpeed(m_isInverted ? -speed : speed); -} - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float Victor::Get() const { return GetSpeed(); } - -/** - * Common interface for disabling a motor. - */ -void Victor::Disable() { SetRaw(kPwmDisabled); } -/** -* Common interface for inverting direction of a speed controller. -* @param isInverted The state of inversion, true is inverted. -*/ -void Victor::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool Victor::GetInverted() const { return m_isInverted; } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void Victor::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void Victor::StopMotor() { this->SafePWM::StopMotor(); } \ No newline at end of file diff --git a/wpilibc/Athena/src/VictorSP.cpp b/wpilibc/Athena/src/VictorSP.cpp index 57dddea9a2..e59a050591 100644 --- a/wpilibc/Athena/src/VictorSP.cpp +++ b/wpilibc/Athena/src/VictorSP.cpp @@ -31,7 +31,7 @@ * @param channel The PWM channel that the VictorSP is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ -VictorSP::VictorSP(uint32_t channel) : SafePWM(channel) { +VictorSP::VictorSP(uint32_t channel) : PWMSpeedController(channel) { SetBounds(2.004, 1.52, 1.50, 1.48, .997); SetPeriodMultiplier(kPeriodMultiplier_1X); SetRaw(m_centerPwm); @@ -40,54 +40,3 @@ VictorSP::VictorSP(uint32_t channel) : SafePWM(channel) { HALReport(HALUsageReporting::kResourceType_VictorSP, GetChannel()); LiveWindow::GetInstance()->AddActuator("VictorSP", GetChannel(), this); } - -/** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately - * scaling the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - * @param syncGroup Unused interface. - */ -void VictorSP::Set(float speed, uint8_t syncGroup) { - SetSpeed(m_isInverted ? -speed : speed); -} - -/** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ -float VictorSP::Get() const { return GetSpeed(); } - -/** - * Common interface for inverting direction of a speed controller. - * @param isInverted The state of inversion, true is inverted. - */ -void VictorSP::SetInverted(bool isInverted) { m_isInverted = isInverted; } - -/** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ -bool VictorSP::GetInverted() const { return m_isInverted; } - -/** - * Common interface for disabling a motor. - */ -void VictorSP::Disable() { SetRaw(kPwmDisabled); } - -/** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ -void VictorSP::PIDWrite(float output) { Set(output); } - -/** - * Common interface to stop the motor until Set is called again. - */ -void VictorSP::StopMotor() { this->SafePWM::StopMotor(); } \ No newline at end of file diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Jaguar.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Jaguar.java index 6d59edd2ff..870acea468 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Jaguar.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Jaguar.java @@ -16,8 +16,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; *$ * @see CANJaguar CANJaguar for CAN control */ -public class Jaguar extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class Jaguar extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -50,78 +49,4 @@ public class Jaguar extends SafePWM implements SpeedController { super(channel); initJaguar(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - @Deprecated - @Override - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - @Override - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller. - * - * @param isInverted The state of inversion, true is inverted. - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - @Override - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - @Override - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/PWMSpeedController.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/PWMSpeedController.java new file mode 100644 index 0000000000..e3fc112638 --- /dev/null +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/PWMSpeedController.java @@ -0,0 +1,95 @@ +/*----------------------------------------------------------------------------*/ +/* 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; + +/** + * Common base class for all PWM Speed Controllers. + */ +public abstract class PWMSpeedController extends SafePWM implements SpeedController { + private boolean isInverted = false; + + /** + * Constructor. + * + * @param channel The PWM channel that the controller is attached to. 0-9 are + * on-board, 10-19 are on the MXP port + */ + protected PWMSpeedController(int channel) { + super(channel); + } + + /** + * Set the PWM value. + * + * @deprecated For compatibility with CANJaguar + * + * The PWM value is set using a range of -1.0 to 1.0, + * appropriately scaling the value for the FPGA. + * + * @param speed The speed to set. Value should be between -1.0 and 1.0. + * @param syncGroup The update group to add this Set() to, pending + * UpdateSyncGroup(). If 0, update immediately. + */ + @Deprecated + public void set(double speed, byte syncGroup) { + setSpeed(isInverted ? -speed : speed); + Feed(); + } + + /** + * Set the PWM value. + * + * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling + * the value for the FPGA. + * + * @param speed The speed value between -1.0 and 1.0 to set. + */ + public void set(double speed) { + setSpeed(isInverted ? -speed : speed); + Feed(); + } + + /** + * Common interface for inverting direction of a speed controller + * + * @param isInverted The state of inversion true is inverted + */ + @Override + public void setInverted(boolean isInverted) { + this.isInverted = isInverted; + } + + /** + * Common interface for the inverting direction of a speed controller. + * + * @return isInverted The state of inversion, true is inverted. + * + */ + @Override + public boolean getInverted() { + return this.isInverted; + } + + /** + * Get the recently set value of the PWM. + * + * @return The most recently set value for the PWM between -1.0 and 1.0. + */ + public double get() { + return getSpeed(); + } + + /** + * Write out the PID value as seen in the PIDOutput base object. + * + * @param output Write out the PWM value as was found in the PIDController + */ + public void pidWrite(double output) { + set(output); + } +} \ No newline at end of file diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SD540.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SD540.java index 8527277eed..adad37e02b 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SD540.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SD540.java @@ -14,8 +14,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** * Mindsensors SD540 Speed Controller */ -public class SD540 extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class SD540 extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -51,73 +50,4 @@ public class SD540 extends SafePWM implements SpeedController { super(channel); initSD540(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller - * - * @param isInverted The state of inversion true is inverted - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Spark.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Spark.java index c7aaa27a3c..8f9dcf097f 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Spark.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Spark.java @@ -14,8 +14,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** * REV Robotics SPARK Speed Controller */ -public class Spark extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class Spark extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -51,73 +50,4 @@ public class Spark extends SafePWM implements SpeedController { super(channel); initSpark(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller - * - * @param isInverted The state of inversion true is inverted - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Talon.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Talon.java index f74c1a3bd5..179697a907 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Talon.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Talon.java @@ -14,8 +14,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** * Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller */ -public class Talon extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class Talon extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -51,74 +50,4 @@ public class Talon extends SafePWM implements SpeedController { super(channel); initTalon(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller - * - * @param isInverted The state of inversion true is inverted - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/TalonSRX.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/TalonSRX.java index 804a390568..b1fd39c8f0 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/TalonSRX.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/TalonSRX.java @@ -16,8 +16,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; *$ * @see CANTalon CANTalon for CAN control of Talon SRX */ -public class TalonSRX extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class TalonSRX extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -53,73 +52,4 @@ public class TalonSRX extends SafePWM implements SpeedController { super(channel); initTalonSRX(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller. - * - * @param isInverted The state of inversion, true is inverted. - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Victor.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Victor.java index 9cb1ed06ad..e4a54a822e 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Victor.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Victor.java @@ -17,8 +17,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; * The Vex Robotics Victor 884 Speed Controller can also be used with this class * but may need to be calibrated per the Victor 884 user manual. */ -public class Victor extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class Victor extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -56,73 +55,4 @@ public class Victor extends SafePWM implements SpeedController { super(channel); initVictor(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller - * - * @param isInverted The state of inversion true is inverted - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/VictorSP.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/VictorSP.java index 581dc60d37..9967823803 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/VictorSP.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/VictorSP.java @@ -14,8 +14,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** * VEX Robotics Victor SP Speed Controller */ -public class VictorSP extends SafePWM implements SpeedController { - private boolean isInverted = false; +public class VictorSP extends PWMSpeedController { /** * Common initialization code called by all constructors. @@ -51,73 +50,4 @@ public class VictorSP extends SafePWM implements SpeedController { super(channel); initVictorSP(); } - - /** - * Set the PWM value. - * - * @deprecated For compatibility with CANJaguar - * - * The PWM value is set using a range of -1.0 to 1.0, - * appropriately scaling the value for the FPGA. - * - * @param speed The speed to set. Value should be between -1.0 and 1.0. - * @param syncGroup The update group to add this Set() to, pending - * UpdateSyncGroup(). If 0, update immediately. - */ - public void set(double speed, byte syncGroup) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Set the PWM value. - * - * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling - * the value for the FPGA. - * - * @param speed The speed value between -1.0 and 1.0 to set. - */ - public void set(double speed) { - setSpeed(isInverted ? -speed : speed); - Feed(); - } - - /** - * Common interface for inverting direction of a speed controller - * - * @param isInverted The state of inversion true is inverted - */ - @Override - public void setInverted(boolean isInverted) { - this.isInverted = isInverted; - } - - /** - * Common interface for the inverting direction of a speed controller. - * - * @return isInverted The state of inversion, true is inverted. - * - */ - @Override - public boolean getInverted() { - return this.isInverted; - } - - /** - * Get the recently set value of the PWM. - * - * @return The most recently set value for the PWM between -1.0 and 1.0. - */ - public double get() { - return getSpeed(); - } - - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - public void pidWrite(double output) { - set(output); - } }