Skip to content

Commit

Permalink
Merge pull request #16 from flamingchickens1540/compatibility
Browse files Browse the repository at this point in the history
 Add deprecated compatibility methods
  • Loading branch information
RobinsonZ authored Jan 19, 2018
2 parents c6db12c + 0db8b26 commit bfd5d95
Showing 1 changed file with 248 additions and 0 deletions.
248 changes: 248 additions & 0 deletions src/main/java/org/team1540/base/wrappers/ChickenTalon.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,4 +904,252 @@ public ErrorCode setStatusFramePeriod(int frameValue, int periodMs) {
public ErrorCode setStatusFramePeriod(StatusFrame frame, int periodMs) {
return super.setStatusFramePeriod(frame, periodMs, defaultTimeoutMs);
}

// HERE ON DOWN IS DEPRECATED STUFF FOR COMPATIBILITY PURPOSES
// Yes, we're aware that CTRE wrote their own compatbility thing, but it's big and sucky so here's this

/**
* @deprecated Use {@link #setControlMode(ControlMode)}
*/
@Deprecated
public void setControlMode(int mode) {
changeControlMode(TalonControlMode.valueOf(mode));
}

/**
* @deprecated Use {@link #setControlMode(ControlMode)}
*/
@Deprecated
public void changeControlMode(TalonControlMode controlMode) {
if (controlMode.ctrl != null) {
setControlMode(controlMode.ctrl);
}
}

/**
* @deprecated Use {@link #config_kP(int, double)}, {@link #config_kI(int, double)}, and {@link
* #config_kD(int, double)}
*/
@Deprecated
public void setPID(double p, double i, double d) {
config_kP(defaultPidIdx, p);
config_kI(defaultPidIdx, i);
config_kP(defaultPidIdx, d);
}

/**
* Set the proportional value of the currently selected profile.
*
* @param p Proportional constant for the currently selected PID profile.
* @deprecated Use {@link #config_kP(int, double)}
*/
@Deprecated
public void setP(double p) {
config_kP(defaultPidIdx, p);
}

/**
* Set the integration constant of the currently selected profile.
*
* @param i Integration constant for the currently selected PID profile.
* @deprecated Use {@link #config_kI(int, double)}
*/
@Deprecated
public void setI(double i) {
config_kI(defaultPidIdx, i);
}

/**
* Set the derivative constant of the currently selected profile.
*
* @param d Derivative constant for the currently selected PID profile.
* @deprecated Use {@link #config_kD(int, double)}
*/
@Deprecated
public void setD(double d) {
config_kD(defaultPidIdx, d);
}

/**
* Set the feedforward value of the currently selected profile.
*
* @param f Feedforward constant for the currently selected PID profile.
* @deprecated Use {@link #config_kF(int, double, int)}
*/
@Deprecated
public void setF(double f) {
config_kF(defaultPidIdx, f);
}

/**
* @deprecated Use {@link #setBrake(boolean)}
*/
@Deprecated
public void enableBrakeMode(boolean brake) {
setBrake(brake);
}

/**
* Configure how many codes per revolution are generated by your encoder.
*
* @param codesPerRev The number of counts per revolution.
* @deprecated Use {@link #setEncoderCodesPerRev(double)}
*/
@Deprecated
public void configEncoderCodesPerRev(int codesPerRev) {
this.setEncoderCodesPerRev(codesPerRev);
}

/**
* When using analog sensors, 0 units corresponds to 0V, 1023 units corresponds to 3.3V. When
* using an analog encoder (wrapping around 1023 to 0 is possible) the units are still 3.3V per
* 1023 units. When using quadrature, each unit is a quadrature edge (4X) mode.
*
* @return The position of the sensor currently providing feedback.
* @deprecated Use {@link #getSelectedSensorPosition()}
*/
@Deprecated
public double getPosition() {
return getSelectedSensorPosition();
}

/**
* @deprecated Use {@link #setSelectedSensorPosition(int)}
*/
@Deprecated
public void setPosition(double pos) {
setSelectedSensorPosition(Math.toIntExact(Math.round(pos)));
}

/**
* @deprecated Use {@link #configSelectedFeedbackSensor(FeedbackDevice)}
*/
@Deprecated
public void setFeedbackDevice(FeedbackDevice device) {
configSelectedFeedbackSensor(device);
}

/**
* Set the voltage ramp rate for the current profile. Limits the rate at which the throttle will
* change. Affects all modes.
*
* @deprecated Use {@link #configOpenloopRamp(double)}
*/
@Deprecated
public void setVoltageRampRate(double rampRate) {
configOpenloopRamp(rampRate);
}

/**
* Select which closed loop profile to use, and uses whatever PIDF gains and the such that are
* already there.
*
* @deprecated Use {@link #selectProfileSlot(int)}
*/
@Deprecated
public void setProfile(int profile) {
selectProfileSlot(profile);
}

/**
* Get the current encoder position, regardless of whether it is the current feedback device.
*
* @deprecated Use {@link #getQuadraturePosition()}
*/
@Deprecated
public int getEncPosition() {
return getQuadraturePosition();
}

/**
* Get the current encoder velocity, regardless of whether it is the current feedback device.
*
* @deprecated Use {@link #getQuadratureVelocity()}
*/
@Deprecated
public int getEncVelocity() {
return getQuadratureVelocity();
}

/**
* Returns the difference between the setpoint and the current position.
*
* @return The error in units corresponding to whichever mode we are in.
* @deprecated Use {@link #getClosedLoopError()}
*/
@Deprecated
public double getError() {
return getClosedLoopError();
}

/**
* @deprecated Use {@link ControlMode}
*/
@Deprecated
public enum TalonControlMode {
PercentVbus(0, ControlMode.PercentOutput),
Position(1, ControlMode.Position),
Speed(2, ControlMode.Velocity),
Current(3, ControlMode.Current),
Voltage(4, null),
Follower(5, ControlMode.Follower),
MotionProfile(6, ControlMode.MotionProfile),
MotionMagic(7, ControlMode.MotionMagic),
Disabled(15, ControlMode.Disabled);

public final int value;
private final ControlMode ctrl;

TalonControlMode(int value, ControlMode ctrl) {
this.value = value;
this.ctrl = ctrl;
}

public static TalonControlMode valueOf(int value) {
TalonControlMode[] var1 = values();
int var2 = var1.length;

for (TalonControlMode mode : var1) {
if (mode.value == value) {
return mode;
}
}

return null;
}

public boolean isPID() {
return this == Current || this == Speed || this == Position;
}

public int getValue() {
return this.value;
}

}

/**
* Flips the sign (multiplies by negative one) the throttle values going into the motor on the
* talon in closed loop modes.
*
* @param flip True if motor output should be flipped; False if not.
* @deprecated Use {@link #setInverted(boolean)}
*/
@Deprecated
public void reverseOutput(boolean flip) {
setInverted(flip);
}

/**
* Flips the sign (multiplies by negative one) the sensor values going into the talon. This only
* affects position and velocity closed loop control. Allows for situations where you may have a
* sensor flipped and going in the wrong direction.
*
* @param flip True if sensor input should be flipped; False if not.
* @deprecated Use {@link #setSensorPhase(boolean)}
*/
public void reverseSensor(boolean flip) {
setSensorPhase(flip);
}

}

0 comments on commit bfd5d95

Please sign in to comment.