Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.

Commit 23d5ce1

Browse files
committed
Fix REVLib deprecations
1 parent be4751d commit 23d5ce1

File tree

21 files changed

+81
-82
lines changed
  • C++
  • Java
    • Alternate Encoder/src/main/java/frc/robot
    • Analog Feedback Device/src/main/java/frc/robot
    • Bus Measurements/src/main/java/frc/robot
    • Encoder Feedback Device/src/main/java/frc/robot
    • Get and Set Parameters/src/main/java/frc/robot
    • Limit Switch/src/main/java/frc/robot
    • Motor Follower/src/main/java/frc/robot
    • Position Closed Loop Control/src/main/java/frc/robot
    • Read Encoder Values/src/main/java/frc/robot
    • Smart Motion Example/src/main/java/frc/robot
    • Soft Limits/src/main/java/frc/robot
    • Tank Drive With CAN/src/main/java/frc/robot
    • Velocity Closed Loop Control/src/main/java/frc/robot

21 files changed

+81
-82
lines changed

C++/Alternate Encoder/src/main/cpp/Robot.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Robot : public frc::TimedRobot {
3333
* A PID controller can be constructed in the normal way using the
3434
* GetPIDController() on the motor you want to control
3535
*/
36-
rev::SparkMaxPIDController m_pidController = m_motor.GetPIDController();
36+
rev::SparkPIDController m_pidController = m_motor.GetPIDController();
3737

3838
// PID coefficients
3939
double kP = 0.1, kI = 1e-4, kD = 1, kIz = 0, kFF = 0, kMaxOutput = 1, kMinOutput = -1;

C++/Analog Feedback Device/src/main/cpp/Robot.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ class Robot : public frc::TimedRobot {
1919
rev::CANSparkMax m_motor{deviceID, rev::CANSparkMax::MotorType::kBrushless};
2020

2121
/**
22-
* A SparkMaxAnalogSensor object is constructed using the GetAnalog() method on an
22+
* A SparkAnalogSensor object is constructed using the GetAnalog() method on an
2323
* existing CANSparkMax object.
2424
*/
25-
rev::SparkMaxAnalogSensor m_analogSensor = m_motor.GetAnalog();
25+
rev::SparkAnalogSensor m_analogSensor = m_motor.GetAnalog();
2626

2727
/**
28-
* In order to use PID functionality for a controller, a SparkMaxPIDController object
28+
* In order to use PID functionality for a controller, a SparkPIDController object
2929
* is constructed by calling the GetPIDController() method on an existing
3030
* CANSparkMax object.
3131
*
3232
*/
33-
rev::SparkMaxPIDController m_pidController = m_motor.GetPIDController();
33+
rev::SparkPIDController m_pidController = m_motor.GetPIDController();
3434

3535
// PID coefficients
3636
double kP = 0.1, kI = 1e-4, kD = 1, kIz = 0, kFF = 0, kMaxOutput = 1, kMinOutput = -1;
@@ -47,7 +47,7 @@ class Robot : public frc::TimedRobot {
4747
/**
4848
* The PID Controller can be configured to use the analog sensor as its feedback
4949
* device with the method SetFeedbackDevice() and passing the PID Controller
50-
* the SparkMaxAnalogSensor object.
50+
* the SparkAnalogSensor object.
5151
*/
5252

5353
m_pidController.SetFeedbackDevice(m_analogSensor);

C++/Encoder Feedback Device/src/main/cpp/Robot.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class Robot : public frc::TimedRobot {
2424
* or a sensor type and counts per revolution can be passed in to specify
2525
* a different kind of sensor. Here, it's a quadrature encoder with 4096 CPR.
2626
*/
27-
rev::SparkMaxRelativeEncoder m_encoder = m_motor.GetEncoder(rev::SparkMaxRelativeEncoder::Type::kQuadrature, 4096);
27+
rev::SparkRelativeEncoder m_encoder = m_motor.GetEncoder(rev::SparkRelativeEncoder::Type::kQuadrature, 4096);
2828

2929
/**
3030
* In order to use PID functionality for a controller, a CANPIDController object
3131
* is constructed by calling the GetPIDController() method on an existing
3232
* CANSparkMax object.
3333
*
3434
*/
35-
rev::SparkMaxPIDController m_pidController = m_motor.GetPIDController();
35+
rev::SparkPIDController m_pidController = m_motor.GetPIDController();
3636

3737
// PID coefficients
3838
double kP = 0.1, kI = 1e-4, kD = 1, kIz = 0, kFF = 0, kMaxOutput = 1, kMinOutput = -1;

C++/Limit Switch/src/main/cpp/Robot.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ class Robot : public frc::TimedRobot {
1616
rev::CANSparkMax m_motor{deviceID, rev::CANSparkMax::MotorType::kBrushless};
1717

1818
/**
19-
* A SparkMaxLimitSwitch object is constructed using the GetForwardLimitSwitch() or
19+
* A SparkLimitSwitch object is constructed using the GetForwardLimitSwitch() or
2020
* GetReverseLimitSwitch() method on an existing CANSparkMax object, depending
2121
* on which direction you would like to limit
2222
*
2323
* Limit switches can be configured to one of two polarities:
24-
* rev::SparkMaxLimitSwitch::Type::kNormallyOpen
25-
* rev::SparkMaxLimitSwitch::Type::kNormallyClosed
24+
* rev::SparkLimitSwitch::Type::kNormallyOpen
25+
* rev::SparkLimitSwitch::Type::kNormallyClosed
2626
*/
27-
rev::SparkMaxLimitSwitch m_forwardLimit = m_motor.GetForwardLimitSwitch(rev::SparkMaxLimitSwitch::Type::kNormallyClosed);
28-
rev::SparkMaxLimitSwitch m_reverseLimit = m_motor.GetReverseLimitSwitch(rev::SparkMaxLimitSwitch::Type::kNormallyClosed);
27+
rev::SparkLimitSwitch m_forwardLimit = m_motor.GetForwardLimitSwitch(rev::SparkLimitSwitch::Type::kNormallyClosed);
28+
rev::SparkLimitSwitch m_reverseLimit = m_motor.GetReverseLimitSwitch(rev::SparkLimitSwitch::Type::kNormallyClosed);
2929

3030
frc::Joystick m_stick{0};
3131

3232
public:
3333
void RobotInit() {
3434
/**
3535
* Limit switches are enabled by default when the are intialized. They can be disabled
36-
* by calling enableLimitSwitch(false) on a SparkMaxLimitSwitch object
36+
* by calling enableLimitSwitch(false) on a SparkLimitSwitch object
3737
*
3838
* Limit switches can be reenabled by calling enableLimitSwitch(true)
3939
*
@@ -52,7 +52,7 @@ class Robot : public frc::TimedRobot {
5252
m_reverseLimit.EnableLimitSwitch(frc::SmartDashboard::GetBoolean("Reverse Limit Enabled", false));
5353

5454
/**
55-
* The Get() method can be used on a SparkMaxLimitSwitch object to read the state of the switch.
55+
* The Get() method can be used on a SparkLimitSwitch object to read the state of the switch.
5656
*
5757
* In this example, the polarity of the switches are set to normally closed. In this case,
5858
* Get() will return true if the switch is pressed. It will also return true if you do not

C++/Position PID Control/src/main/cpp/Robot.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class Robot : public frc::TimedRobot {
1616
rev::CANSparkMax m_motor{deviceID, rev::CANSparkMax::MotorType::kBrushless};
1717

1818
/**
19-
* In order to use PID functionality for a controller, a SparkMaxPIDController object
19+
* In order to use PID functionality for a controller, a SparkPIDController object
2020
* is constructed by calling the GetPIDController() method on an existing
2121
* CANSparkMax object
2222
*/
23-
rev::SparkMaxPIDController m_pidController = m_motor.GetPIDController();
23+
rev::SparkPIDController m_pidController = m_motor.GetPIDController();
2424

2525
// Encoder object created to display position values
26-
rev::SparkMaxRelativeEncoder m_encoder = m_motor.GetEncoder();
26+
rev::SparkRelativeEncoder m_encoder = m_motor.GetEncoder();
2727

2828
// PID coefficients
2929
double kP = 0.1, kI = 1e-4, kD = 1, kIz = 0, kFF = 0, kMaxOutput = 1, kMinOutput = -1;

C++/Read Encoder Values/src/main/cpp/Robot.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Robot : public frc::TimedRobot {
2424
* In order to read encoder values an encoder object is created using the
2525
* GetEncoder() method from an existing CANSparkMax object
2626
*/
27-
rev::SparkMaxRelativeEncoder m_encoder = m_motor.GetEncoder();
27+
rev::SparkRelativeEncoder m_encoder = m_motor.GetEncoder();
2828

2929
frc::Joystick m_stick{0};
3030

@@ -36,15 +36,15 @@ class Robot : public frc::TimedRobot {
3636
m_motor.Set(m_stick.GetY());
3737

3838
/**
39-
* Encoder position is read from a SparkMaxRelativeEncoder object by calling the
39+
* Encoder position is read from a SparkRelativeEncoder object by calling the
4040
* GetPosition() method.
4141
*
4242
* GetPosition() returns the position of the encoder in units of revolutions
4343
*/
4444
frc::SmartDashboard::PutNumber("Encoder Position", m_encoder.GetPosition());
4545

4646
/**
47-
* Encoder velocity is read from a SparkMaxRelativeEncoder object by calling the
47+
* Encoder velocity is read from a SparkRelativeEncoder object by calling the
4848
* GetVelocity() method.
4949
*
5050
* GetVelocity() returns the velocity of the encoder in units of RPM

C++/Smart Motion Example/src/main/cpp/Robot.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
class Robot : public frc::TimedRobot {
4949
static const int deviceID = 9;
5050
rev::CANSparkMax m_motor{deviceID, rev::CANSparkMax::MotorType::kBrushless};
51-
rev::SparkMaxPIDController m_pidController = m_motor.GetPIDController();
52-
rev::SparkMaxRelativeEncoder m_encoder = m_motor.GetEncoder();
51+
rev::SparkPIDController m_pidController = m_motor.GetPIDController();
52+
rev::SparkRelativeEncoder m_encoder = m_motor.GetEncoder();
5353

5454
// default PID coefficients
5555
double kP = 5e-5, kI = 1e-6, kD = 0, kIz = 0, kFF = 0.000156, kMaxOutput = 1, kMinOutput = -1;
@@ -80,7 +80,7 @@ class Robot : public frc::TimedRobot {
8080
m_pidController.SetOutputRange(kMinOutput, kMaxOutput);
8181

8282
/**
83-
* Smart Motion coefficients are set on a SparkMaxPIDController object
83+
* Smart Motion coefficients are set on a SparkPIDController object
8484
*
8585
* - SetSmartMotionMaxVelocity() will limit the velocity in RPM of
8686
* the pid controller in Smart Motion mode

C++/Velocity PID Control/src/main/cpp/Robot.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class Robot : public frc::TimedRobot {
1616
rev::CANSparkMax m_motor{deviceID, rev::CANSparkMax::MotorType::kBrushless};
1717

1818
/**
19-
* In order to use PID functionality for a controller, a SparkMaxPIDController object
19+
* In order to use PID functionality for a controller, a SparkPIDController object
2020
* is constructed by calling the GetPIDController() method on an existing
2121
* CANSparkMax object
2222
*/
23-
rev::SparkMaxPIDController m_pidController = m_motor.GetPIDController();
23+
rev::SparkPIDController m_pidController = m_motor.GetPIDController();
2424

2525
// Encoder object created to display velocity values
26-
rev::SparkMaxRelativeEncoder m_encoder = m_motor.GetEncoder();
26+
rev::SparkRelativeEncoder m_encoder = m_motor.GetEncoder();
2727

2828
frc::Joystick m_stick{0};
2929

Java/Alternate Encoder/src/main/java/frc/robot/Robot.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
import com.revrobotics.RelativeEncoder;
1414
import com.revrobotics.SparkMaxAlternateEncoder;
15-
import com.revrobotics.SparkMaxPIDController;
15+
import com.revrobotics.SparkPIDController;
1616
import com.revrobotics.CANSparkMax;
17-
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
17+
import com.revrobotics.CANSparkLowLevel.MotorType;
1818

1919
public class Robot extends TimedRobot {
2020
/**
@@ -26,7 +26,7 @@ public class Robot extends TimedRobot {
2626
private static final int kCPR = 8192;
2727

2828
private CANSparkMax m_motor;
29-
private SparkMaxPIDController m_pidController;
29+
private SparkPIDController m_pidController;
3030
public double kP, kI, kD, kIz, kFF, kMaxOutput, kMinOutput;
3131

3232
/**
@@ -46,7 +46,7 @@ public void robotInit() {
4646
m_alternateEncoder = m_motor.getAlternateEncoder(kAltEncType, kCPR);
4747

4848
/**
49-
* In order to use PID functionality for a controller, a SparkMaxPIDController object
49+
* In order to use PID functionality for a controller, a SparkPIDController object
5050
* is constructed by calling the getPIDController() method on an existing
5151
* CANSparkMax object
5252
*/

Java/Analog Feedback Device/src/main/java/frc/robot/Robot.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,35 @@
1010
import edu.wpi.first.wpilibj.TimedRobot;
1111
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1212

13-
import com.revrobotics.SparkMaxAnalogSensor;
14-
import com.revrobotics.SparkMaxPIDController;
13+
import com.revrobotics.SparkAnalogSensor;
14+
import com.revrobotics.SparkPIDController;
1515
import com.revrobotics.CANSparkMax;
16-
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
16+
import com.revrobotics.CANSparkLowLevel.MotorType;
1717

1818
public class Robot extends TimedRobot {
1919

2020

2121
private static final int deviceID = 1;
2222
private CANSparkMax m_motor;
23-
private SparkMaxPIDController m_pidController;
23+
private SparkPIDController m_pidController;
2424
public double kP, kI, kD, kIz, kFF, kMaxOutput, kMinOutput;
2525

2626
/**
27-
* A SparkMaxAnalogSensor object is constructed using the GetAnalog() method on an
27+
* A SparkAnalogSensor object is constructed using the GetAnalog() method on an
2828
* existing CANSparkMax object.
2929
*/
30-
private SparkMaxAnalogSensor m_analogSensor;
30+
private SparkAnalogSensor m_analogSensor;
3131

3232
@Override
3333
public void robotInit() {
3434
// initialize SPARK MAX with CAN ID
3535
m_motor = new CANSparkMax(deviceID, MotorType.kBrushless);
36-
m_analogSensor = m_motor.getAnalog(SparkMaxAnalogSensor.Mode.kAbsolute);
36+
m_analogSensor = m_motor.getAnalog(SparkAnalogSensor.Mode.kAbsolute);
3737

3838
m_motor.restoreFactoryDefaults();
3939

4040
/**
41-
* In order to use PID functionality for a controller, a SparkMaxPIDController object
41+
* In order to use PID functionality for a controller, a SparkPIDController object
4242
* is constructed by calling the getPIDController() method on an existing
4343
* CANSparkMax object
4444
*/
@@ -47,7 +47,7 @@ public void robotInit() {
4747
/**
4848
* The PID Controller can be configured to use the analog sensor as its feedback
4949
* device with the method SetFeedbackDevice() and passing the PID Controller
50-
* the SparkMaxAnalogSensor object.
50+
* the SparkAnalogSensor object.
5151
*/
5252
m_pidController.setFeedbackDevice(m_analogSensor);
5353

Java/Bus Measurements/src/main/java/frc/robot/Robot.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1313

1414
import com.revrobotics.CANSparkMax;
15-
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
15+
import com.revrobotics.CANSparkLowLevel.MotorType;
1616

1717
/**
1818
* This sample program shows how to read basic bus measurements from the SparkMax

Java/Encoder Feedback Device/src/main/java/frc/robot/Robot.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1212

1313
import com.revrobotics.RelativeEncoder;
14-
import com.revrobotics.SparkMaxPIDController;
14+
import com.revrobotics.SparkPIDController;
1515
import com.revrobotics.CANSparkMax;
16-
import com.revrobotics.SparkMaxRelativeEncoder;
17-
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
16+
import com.revrobotics.SparkRelativeEncoder;
17+
import com.revrobotics.CANSparkLowLevel.MotorType;
1818

1919
public class Robot extends TimedRobot {
2020
private static final int deviceID = 0;
2121
private CANSparkMax m_motor;
22-
private SparkMaxPIDController m_pidController;
22+
private SparkPIDController m_pidController;
2323
public double kP, kI, kD, kIz, kFF, kMaxOutput, kMinOutput;
2424

2525
/**
@@ -34,12 +34,12 @@ public class Robot extends TimedRobot {
3434
public void robotInit() {
3535
// initialize SPARK MAX with CAN ID
3636
m_motor = new CANSparkMax(deviceID, MotorType.kBrushed);
37-
m_encoder = m_motor.getEncoder(SparkMaxRelativeEncoder.Type.kQuadrature, 4096);
37+
m_encoder = m_motor.getEncoder(SparkRelativeEncoder.Type.kQuadrature, 4096);
3838

3939
m_motor.restoreFactoryDefaults();
4040

4141
/**
42-
* In order to use PID functionality for a controller, a SparkMaxPIDController object
42+
* In order to use PID functionality for a controller, a SparkPIDController object
4343
* is constructed by calling the getPIDController() method on an existing
4444
* CANSparkMax object
4545
*/

Java/Get and Set Parameters/src/main/java/frc/robot/Robot.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
import com.revrobotics.REVLibError;
1515
import com.revrobotics.CANSparkMax;
16-
import com.revrobotics.CANSparkMax.IdleMode;
17-
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
16+
import com.revrobotics.CANSparkLowLevel.MotorType;
1817

1918
/**
2019
* This is a demo program showing the use of the CANSparkMax class, specifically
@@ -50,15 +49,15 @@ public void robotInit() {
5049
* REVLibError.kError
5150
* REVLibError.kTimeout
5251
*/
53-
if(m_motor.setIdleMode(IdleMode.kCoast) != REVLibError.kOk){
52+
if(m_motor.setIdleMode(CANSparkMax.IdleMode.kCoast) != REVLibError.kOk){
5453
SmartDashboard.putString("Idle Mode", "Error");
5554
}
5655

5756
/**
5857
* Similarly, parameters will have a Get method which allows you to retrieve their values
5958
* from the controller
6059
*/
61-
if(m_motor.getIdleMode() == IdleMode.kCoast) {
60+
if(m_motor.getIdleMode() == CANSparkMax.IdleMode.kCoast) {
6261
SmartDashboard.putString("Idle Mode", "Coast");
6362
} else {
6463
SmartDashboard.putString("Idle Mode", "Brake");

Java/Limit Switch/src/main/java/frc/robot/Robot.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
import edu.wpi.first.wpilibj.TimedRobot;
1212
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1313

14-
import com.revrobotics.SparkMaxLimitSwitch;
14+
import com.revrobotics.SparkLimitSwitch;
1515
import com.revrobotics.CANSparkMax;
16-
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
16+
import com.revrobotics.CANSparkLowLevel.MotorType;
1717

1818
public class Robot extends TimedRobot {
1919
private Joystick m_stick;
2020
private static final int deviceID = 1;
2121
private CANSparkMax m_motor;
22-
private SparkMaxLimitSwitch m_forwardLimit;
23-
private SparkMaxLimitSwitch m_reverseLimit;
22+
private SparkLimitSwitch m_forwardLimit;
23+
private SparkLimitSwitch m_reverseLimit;
2424

2525
public String kEnable;
2626
public String kDisable;
@@ -38,22 +38,22 @@ public void robotInit() {
3838
m_motor.restoreFactoryDefaults();
3939

4040
/**
41-
* A SparkMaxLimitSwitch object is constructed using the getForwardLimitSwitch() or
41+
* A SparkLimitSwitch object is constructed using the getForwardLimitSwitch() or
4242
* getReverseLimitSwitch() method on an existing CANSparkMax object, depending
4343
* on which direction you would like to limit
4444
*
4545
* Limit switches can be configured to one of two polarities:
46-
* com.revrobotics.SparkMaxLimitSwitch.SparkMaxLimitSwitch.Type.kNormallyOpen
47-
* com.revrobotics.SparkMaxLimitSwitch.SparkMaxLimitSwitch.Type.kNormallyClosed
46+
* com.revrobotics.SparkLimitSwitch.SparkLimitSwitch.Type.kNormallyOpen
47+
* com.revrobotics.SparkLimitSwitch.SparkLimitSwitch.Type.kNormallyClosed
4848
*/
49-
m_forwardLimit = m_motor.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyClosed);
50-
m_reverseLimit = m_motor.getReverseLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyClosed);
49+
m_forwardLimit = m_motor.getForwardLimitSwitch(SparkLimitSwitch.Type.kNormallyClosed);
50+
m_reverseLimit = m_motor.getReverseLimitSwitch(SparkLimitSwitch.Type.kNormallyClosed);
5151

5252
m_stick = new Joystick(0);
5353

5454
/**
5555
* Limit switches are enabled by default when they are intialized. They can be disabled
56-
* by calling enableLimitSwitch(false) on a SparkMaxLimitSwitch object
56+
* by calling enableLimitSwitch(false) on a SparkLimitSwitch object
5757
*
5858
* Limit switches can be reenabled by calling enableLimitSwitch(true)
5959
*
@@ -74,7 +74,7 @@ public void teleopPeriodic() {
7474
m_reverseLimit.enableLimitSwitch(SmartDashboard.getBoolean("Reverse Limit Enabled", false));
7575

7676
/**
77-
* The isPressed() method can be used on a SparkMaxLimitSwitch object to read the state of the switch.
77+
* The isPressed() method can be used on a SparkLimitSwitch object to read the state of the switch.
7878
*
7979
* In this example, the polarity of the switches are set to normally closed. In this case,
8080
* isPressed() will return true if the switch is pressed. It will also return true if you do not

0 commit comments

Comments
 (0)