From 96fc4edefb05ad90a61457207a781835099ee8b6 Mon Sep 17 00:00:00 2001 From: edelmanjm Date: Thu, 18 Jan 2018 16:42:16 -0800 Subject: [PATCH 1/4] Add deprecated compatibility methods So now you can basically just drop it in place of CANTalon. Note that motion profiling and stuff isn't included, only 1:1 translations. Yes, we're aware of CTRE's wrapper. --- .../team1540/base/wrappers/ChickenTalon.java | 226 ++++++++++++++++++ 1 file changed, 226 insertions(+) diff --git a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java index 823a7e2e..e7a1a82b 100644 --- a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java +++ b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java @@ -880,4 +880,230 @@ 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) { + switch (controlMode) { + case PercentVbus: + setControlMode(ControlMode.PercentOutput); + case Position: + setControlMode(ControlMode.Position); + case Speed: + setControlMode(ControlMode.Velocity); + case Current: + setControlMode(ControlMode.Current); + case Follower: + setControlMode(ControlMode.Follower); + case MotionProfile: + setControlMode(ControlMode.MotionProfile); + case MotionMagic: + setControlMode(ControlMode.MotionMagic); + case Disabled: + setControlMode(ControlMode.Disabled); + } + } + + /** + * @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); + } + + /** + * @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), + Position(1), + Speed(2), + Current(3), + Voltage(4), + Follower(5), + MotionProfile(6), + MotionMagic(7), + Disabled(15); + + public final int value; + + TalonControlMode(int value) { + this.value = value; + } + + 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; + } + + } + } From 747eb4d3bd4d072e99fa7fde8d456deea1bbfe84 Mon Sep 17 00:00:00 2001 From: edelmanjm Date: Thu, 18 Jan 2018 16:50:43 -0800 Subject: [PATCH 2/4] Fix semicolon in JavaDoc --- src/main/java/org/team1540/base/wrappers/ChickenTalon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java index e7a1a82b..c50e2f9f 100644 --- a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java +++ b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java @@ -1024,7 +1024,7 @@ public void setVoltageRampRate(double 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 Use {@link #selectProfileSlot(int)} */ @Deprecated public void setProfile(int profile) { From 61ab0a0e7848596bea0b5e646728210dafd2a5aa Mon Sep 17 00:00:00 2001 From: edelmanjm Date: Thu, 18 Jan 2018 17:13:41 -0800 Subject: [PATCH 3/4] Add sensor reversing, setF --- .../team1540/base/wrappers/ChickenTalon.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java index c50e2f9f..fa67e64a 100644 --- a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java +++ b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java @@ -961,6 +961,17 @@ 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)} */ @@ -1106,4 +1117,28 @@ public int getValue() { } + /** + * 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); + } + } From 08a4cd0956d8ad639b6f9113497f5b06f35b0707 Mon Sep 17 00:00:00 2001 From: Zachary Robinson Date: Thu, 18 Jan 2018 18:06:57 -0800 Subject: [PATCH 4/4] Make changeControlMode() more elegant because Jonathan can't be bothered --- .../team1540/base/wrappers/ChickenTalon.java | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java index fa67e64a..ffbf2f7a 100644 --- a/src/main/java/org/team1540/base/wrappers/ChickenTalon.java +++ b/src/main/java/org/team1540/base/wrappers/ChickenTalon.java @@ -897,23 +897,8 @@ public void setControlMode(int mode) { */ @Deprecated public void changeControlMode(TalonControlMode controlMode) { - switch (controlMode) { - case PercentVbus: - setControlMode(ControlMode.PercentOutput); - case Position: - setControlMode(ControlMode.Position); - case Speed: - setControlMode(ControlMode.Velocity); - case Current: - setControlMode(ControlMode.Current); - case Follower: - setControlMode(ControlMode.Follower); - case MotionProfile: - setControlMode(ControlMode.MotionProfile); - case MotionMagic: - setControlMode(ControlMode.MotionMagic); - case Disabled: - setControlMode(ControlMode.Disabled); + if (controlMode.ctrl != null) { + setControlMode(controlMode.ctrl); } } @@ -1078,20 +1063,22 @@ public double getError() { */ @Deprecated public enum TalonControlMode { - PercentVbus(0), - Position(1), - Speed(2), - Current(3), - Voltage(4), - Follower(5), - MotionProfile(6), - MotionMagic(7), - Disabled(15); + 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) { + TalonControlMode(int value, ControlMode ctrl) { this.value = value; + this.ctrl = ctrl; } public static TalonControlMode valueOf(int value) {