Added and implemented GetInverted method.

Change-Id: I53bd51e41311e3ffcd3fa3ffbc4e72cfab530109
This commit is contained in:
Joseph
2015-06-15 15:32:47 -04:00
committed by James Kuszmaul
parent 0122086d23
commit bd64d9a7ef
25 changed files with 226 additions and 32 deletions

View File

@@ -125,6 +125,7 @@ public:
//SpeedController overrides
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
protected:
// Control mode helpers
void SetSpeedReference(uint8_t reference);

View File

@@ -163,7 +163,9 @@ public:
void InitTable(ITable *subTable) override;
ITable * GetTable() const override;
//SpeedController overrides
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
// Values for various modes as is sent in the CAN packets for the Talon.
enum TalonControlMode {

View File

@@ -23,6 +23,7 @@ public:
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
void InitJaguar();
bool m_isInverted;

View File

@@ -22,19 +22,28 @@ public:
* @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup(). If 0, update immediately.
*/
virtual void Set(float speed, uint8_t syncGroup = 0) = 0;
/**
* Common interface for getting the current set speed of a speed controller.
*
* @return The current set speed. Value is between -1.0 and 1.0.
*/
virtual float Get() const = 0;
/**
* common interface for inverting direction of a speed controller
* @param isInverted The state of inversion true is inverted
* Common interface for inverting direction of a speed controller.
* @param isInverted The state of inversion, true is inverted.
*/
virtual void SetInverted(bool isInverted) = 0;
/**
* Common interface for disabling a motor.
*/
virtual void Disable() = 0;
/**
* Common interface for returning the inversion state of a speed controller.
* @return isInverted The state of inversion, true is inverted.
*/
virtual bool GetInverted() const = 0;
};

View File

@@ -23,6 +23,7 @@ public:
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
void InitTalon();
bool m_isInverted;

View File

@@ -24,7 +24,7 @@ public:
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
void InitTalonSRX();
bool m_isInverted;

View File

@@ -26,7 +26,8 @@ public:
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted);
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
void InitVictor();
bool m_isInverted;

View File

@@ -23,7 +23,8 @@ public:
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted);
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
void InitVictorSP();
bool m_isInverted;

View File

@@ -2119,14 +2119,24 @@ void CANJaguar::StopLiveWindowMode()
}
/**
* common interface for inverting direction of a speed controller
* Only works in PercentVbus, speed, and Voltage modes
* @param isInverted The state of inversion true is inverted
* Common interface for inverting direction of a speed controller.
* Only works in PercentVbus, speed, and Voltage modes.
* @param isInverted The state of inversion, true is inverted
*/
void CANJaguar::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 CANJaguar::GetInverted() const {
return m_isInverted;
}
std::string CANJaguar::GetSmartDashboardType() const
{
return "Speed Controller";

View File

@@ -1292,14 +1292,26 @@ void CANTalon::GetDescription(char *desc) const
{
sprintf(desc, "CANTalon ID %d", m_deviceNumber);
}
/**
* common interface for inverting direction of a speed controller
* Only works in PercentVbus, speed, and Voltage modes
* @param isInverted The state of inversion true is inverted
* Common interface for inverting direction of a speed controller.
* Only works in PercentVbus, speed, and Voltage modes.
* @param isInverted The state of inversion, true is inverted.
*/
void CANTalon::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 CANTalon::GetInverted() const {
return m_isInverted;
}
/**
* Common interface for stopping the motor
* Part of the MotorSafety interface

View File

@@ -77,13 +77,25 @@ void Jaguar::Disable()
{
SetRaw(kPwmDisabled);
}
/**
* common interface for inverting direction of a speed controller
* @param isInverted The state of inversion true is inverted
* 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.
*

View File

@@ -78,6 +78,7 @@ void Talon::Disable()
{
SetRaw(kPwmDisabled);
}
/**
* common interface for inverting direction of a speed controller
* @param isInverted The state of inversion true is inverted
@@ -85,6 +86,17 @@ void Talon::Disable()
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.
*

View File

@@ -77,13 +77,25 @@ void TalonSRX::Disable()
{
SetRaw(kPwmDisabled);
}
/**
* common interface for inverting direction of a speed controller
* @param isInverted The state of inversion true is inverted
* 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.
*

View File

@@ -81,12 +81,23 @@ void Victor::Disable()
SetRaw(kPwmDisabled);
}
/**
* common interface for inverting direction of a speed controller
* @param isInverted The state of inversion true is inverted
* 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.
*

View File

@@ -35,7 +35,7 @@ void VictorSP::InitVictorSP() {
}
/**
* Constructor for a VictorSP
* Constructor for a VictorSP
* @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)
@@ -70,13 +70,25 @@ float VictorSP::Get() const
{
return GetSpeed();
}
/**
* common interface for inverting direction of a speed controller
* @param isInverted The state of inversion true is inverted
*/
* 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.
*/

View File

@@ -432,6 +432,17 @@ public class CANJaguar implements MotorSafety, PIDOutput, PIDInterface, CANSpeed
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;
}
/**
* Check all unverified params and make sure they're equal to their local
* cached versions. If a value isn't available, it gets requested. If a value

View File

@@ -169,15 +169,26 @@ public class CANTalon implements MotorSafety, PIDOutput, PIDSource, PIDInterface
}
/**
* Inverts the direction of the motor's rotation
* Only works in PercentVbus mode
* Inverts the direction of the motor's rotation.
* Only works in PercentVbus mode.
*
* @param isInverted The state of inversion true is inverted
* @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;
}
/**
* Sets the output of the Talon.

View File

@@ -82,15 +82,26 @@ private boolean isInverted = false;
}
/**
* Common interface for inverting direction of a speed controller
* Common interface for inverting direction of a speed controller.
*
* @param isInverted The state of inversion true is inverted
* @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.
*

View File

@@ -35,11 +35,23 @@ public interface SpeedController extends PIDOutput {
void set(double speed);
/**
* Common interface for inverting direction of a speed controller
* Common interface for inverting direction of a speed controller.
*
* @param isInverted The state of inversion true is inverted
* @param isInverted The state of inversion true is inverted.
*/
void setInverted(boolean isInverted);
/**
* Common interface for returning if a speed controller
* is in the inverted state or not.
*
* @return isInverted The state of the inversion true is inverted.
*
*/
boolean getInverted();
/**
* Disable the speed controller
*/

View File

@@ -89,6 +89,17 @@ private boolean isInverted = false;
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.
*

View File

@@ -81,15 +81,26 @@ public class TalonSRX extends SafePWM implements SpeedController {
}
/**
* Common interface for inverting direction of a speed controller
* Common interface for inverting direction of a speed controller.
*
* @param isInverted The state of inversion true is inverted
* @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.
*

View File

@@ -94,6 +94,17 @@ private boolean isInverted = false;
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.
*

View File

@@ -89,6 +89,17 @@ private boolean isInverted = false;
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.
*

View File

@@ -33,6 +33,7 @@ public class MotorInvertingTest extends AbstractComsSetup {
fixture = afixture;
fixture.setup();
}
@Parameterized.Parameters(name= "{index}: {0}")
public static Collection<MotorEncoderFixture<?>[]> generateData(){
//logger.fine("Loading the MotorList");
@@ -42,11 +43,14 @@ public class MotorInvertingTest extends AbstractComsSetup {
{TestBench.getInstance().getJaguarPair()}
});
}
private static final Logger logger = Logger.getLogger(MotorInvertingTest.class.getName());
@Override
protected Logger getClassLogger(){
return logger;
}
@Before
public void setUp() {
// Reset the fixture elements before every test
@@ -59,8 +63,9 @@ public class MotorInvertingTest extends AbstractComsSetup {
// Clean up the fixture after the test
fixture.teardown();
}
@Test
public void testInvertingPositive(){
public void testInvertingPositive(){
fixture.getMotor().setInverted(false);
fixture.getMotor().set(motorspeed);
Timer.delay(delaytime);
@@ -71,6 +76,7 @@ public class MotorInvertingTest extends AbstractComsSetup {
assertFalse("Inverting with Positive value does not change direction",fixture.getEncoder().getDirection()==initDirection);
fixture.getMotor().set(0);
}
@Test
public void testInvertingNegative(){
fixture.getMotor().setInverted(false);
@@ -83,6 +89,7 @@ public class MotorInvertingTest extends AbstractComsSetup {
assertFalse("Inverting with Negative value does not change direction",fixture.getEncoder().getDirection()==initDirection);
fixture.getMotor().set(0);
}
@Test
public void testInvertingSwitchingPosToNeg(){
fixture.getMotor().setInverted(false);
@@ -95,6 +102,7 @@ public class MotorInvertingTest extends AbstractComsSetup {
assertTrue("Inverting with Switching value does change direction", fixture.getEncoder().getDirection() == initDirection);
fixture.getMotor().set(0);
}
@Test
public void testInvertingSwitchingNegToPos(){
fixture.getMotor().setInverted(false);

View File

@@ -28,7 +28,7 @@ import edu.wpi.first.wpilibj.test.AbstractTestSuite;
EncoderTest.class,
GyroTest.class,
MotorEncoderTest.class,
MotorInvertingTest.class,
MotorInvertingTest.class,
PCMTest.class,
PDPTest.class,
PIDTest.class,