mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Replace deprecated API usage in C++ examples
Since there is a new version of GearsBot using the new command-based API, the old GearsBot is just removed. PR #1842 is being included to verify this PR is correct.
This commit is contained in:
committed by
Peter Johnson
parent
d6b9c7e148
commit
c9f9feff1f
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. 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. */
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#include <frc/AnalogInput.h>
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/PIDController.h>
|
||||
#include <frc/PWMVictorSPX.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/controller/PIDController.h>
|
||||
|
||||
/**
|
||||
* This is a sample program to demonstrate how to use a soft potentiometer and a
|
||||
@@ -22,8 +22,6 @@ class Robot : public frc::TimedRobot {
|
||||
public:
|
||||
void RobotInit() override { m_pidController.SetInputRange(0, 5); }
|
||||
|
||||
void TeleopInit() override { m_pidController.Enable(); }
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// When the button is pressed once, the selected elevator setpoint is
|
||||
// incremented.
|
||||
@@ -35,6 +33,9 @@ class Robot : public frc::TimedRobot {
|
||||
m_previousButtonValue = currentButtonValue;
|
||||
|
||||
m_pidController.SetSetpoint(kSetPoints[m_index]);
|
||||
double output =
|
||||
m_pidController.Calculate(m_potentiometer.GetAverageVoltage());
|
||||
m_elevatorMotor.Set(output);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -64,11 +65,7 @@ class Robot : public frc::TimedRobot {
|
||||
frc::Joystick m_joystick{kJoystickChannel};
|
||||
frc::PWMVictorSPX m_elevatorMotor{kMotorChannel};
|
||||
|
||||
/* Potentiometer (AnalogInput) and elevatorMotor (Victor) can be used as a
|
||||
* PIDSource and PIDOutput respectively.
|
||||
*/
|
||||
frc::PIDController m_pidController{kP, kI, kD, m_potentiometer,
|
||||
m_elevatorMotor};
|
||||
frc2::PIDController m_pidController{kP, kI, kD};
|
||||
};
|
||||
|
||||
constexpr std::array<double, 3> Robot::kSetPoints;
|
||||
|
||||
Reference in New Issue
Block a user