mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Run wpiformat on merged repo (#1021)
This commit is contained in:
committed by
Peter Johnson
parent
0babbf317c
commit
6729a7d6b1
@@ -19,62 +19,56 @@
|
||||
* mechanism.
|
||||
*/
|
||||
class Robot : public frc::IterativeRobot {
|
||||
public:
|
||||
void RobotInit() override { m_pidController.SetInputRange(0, 5); }
|
||||
public:
|
||||
void RobotInit() override { m_pidController.SetInputRange(0, 5); }
|
||||
|
||||
void TeleopInit() override { m_pidController.Enable(); }
|
||||
void TeleopInit() override { m_pidController.Enable(); }
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// when the button is pressed once, the selected elevator
|
||||
// setpoint
|
||||
// is incremented
|
||||
bool currentButtonValue = m_joystick.GetTrigger();
|
||||
if (currentButtonValue && !m_previousButtonValue) {
|
||||
// index of the elevator setpoint wraps around.
|
||||
m_index = (m_index + 1) % (sizeof(kSetPoints) / 8);
|
||||
}
|
||||
m_previousButtonValue = currentButtonValue;
|
||||
void TeleopPeriodic() override {
|
||||
// When the button is pressed once, the selected elevator setpoint is
|
||||
// incremented.
|
||||
bool currentButtonValue = m_joystick.GetTrigger();
|
||||
if (currentButtonValue && !m_previousButtonValue) {
|
||||
// Index of the elevator setpoint wraps around
|
||||
m_index = (m_index + 1) % (sizeof(kSetPoints) / 8);
|
||||
}
|
||||
m_previousButtonValue = currentButtonValue;
|
||||
|
||||
m_pidController.SetSetpoint(kSetPoints[m_index]);
|
||||
}
|
||||
m_pidController.SetSetpoint(kSetPoints[m_index]);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int kPotChannel = 1;
|
||||
static constexpr int kMotorChannel = 7;
|
||||
static constexpr int kJoystickChannel = 0;
|
||||
private:
|
||||
static constexpr int kPotChannel = 1;
|
||||
static constexpr int kMotorChannel = 7;
|
||||
static constexpr int kJoystickChannel = 0;
|
||||
|
||||
// Bottom, middle, and top elevator setpoints
|
||||
static constexpr std::array<double, 3> kSetPoints = {{1.0, 2.6, 4.3}};
|
||||
// Bottom, middle, and top elevator setpoints
|
||||
static constexpr std::array<double, 3> kSetPoints = {{1.0, 2.6, 4.3}};
|
||||
|
||||
/* proportional, integral, and derivative speed constants; motor
|
||||
* inverted
|
||||
* DANGER: when tuning PID constants, high/inappropriate values for
|
||||
* pGain,
|
||||
* iGain, and dGain may cause dangerous, uncontrollable, or
|
||||
* undesired behavior!
|
||||
*
|
||||
* These may need to be positive for a non-inverted motor
|
||||
*/
|
||||
static constexpr double kP = -5.0;
|
||||
static constexpr double kI = -0.02;
|
||||
static constexpr double kD = -2.0;
|
||||
/* Proportional, integral, and derivative speed constants; motor inverted.
|
||||
*
|
||||
* DANGER: When tuning PID constants, high/inappropriate values for pGain,
|
||||
* iGain, and dGain may cause dangerous, uncontrollable, or undesired
|
||||
* behavior!
|
||||
*
|
||||
* These may need to be positive for a non-inverted motor.
|
||||
*/
|
||||
static constexpr double kP = -5.0;
|
||||
static constexpr double kI = -0.02;
|
||||
static constexpr double kD = -2.0;
|
||||
|
||||
int m_index = 0;
|
||||
bool m_previousButtonValue = false;
|
||||
int m_index = 0;
|
||||
bool m_previousButtonValue = false;
|
||||
|
||||
frc::AnalogInput m_potentiometer{kPotChannel};
|
||||
frc::Joystick m_joystick{kJoystickChannel};
|
||||
frc::Spark m_elevatorMotor{kMotorChannel};
|
||||
frc::AnalogInput m_potentiometer{kPotChannel};
|
||||
frc::Joystick m_joystick{kJoystickChannel};
|
||||
frc::Spark m_elevatorMotor{kMotorChannel};
|
||||
|
||||
/* potentiometer (AnalogInput) and elevatorMotor (Victor) can be used as
|
||||
* a
|
||||
* PIDSource and PIDOutput respectively. The PIDController takes
|
||||
* pointers
|
||||
* to the PIDSource and PIDOutput, so you must use &potentiometer and
|
||||
* &elevatorMotor to get their pointers.
|
||||
*/
|
||||
frc::PIDController m_pidController{
|
||||
kP, kI, kD, &m_potentiometer, &m_elevatorMotor};
|
||||
/* 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};
|
||||
};
|
||||
|
||||
constexpr std::array<double, 3> Robot::kSetPoints;
|
||||
|
||||
Reference in New Issue
Block a user