Implements a common PWMSpeedController base class

There was a lot of duplicated code between all 7 PWM speed controllers.
This moves all the duplicated code down to a base class, that will make
it easier to add speed controllers in future years if needed again. Also
if we need to add a method to all speed controllers, we only have to do
it in 1 place, and not 7.

Change-Id: I25eb1d097c0f5f7dbd7656db2f4a30d006d50f98
This commit is contained in:
Thad House
2016-02-05 13:38:21 -08:00
committed by Gerrit Code Review
parent 686f5d9fef
commit 0f228e7b7d
25 changed files with 223 additions and 971 deletions

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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"

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}