2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2017-10-17 21:37:58 -07:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <frc/AnalogPotentiometer.h>
|
|
|
|
|
#include <frc/DigitalInput.h>
|
2021-02-13 01:14:56 -05:00
|
|
|
#include <frc/PWMSparkMax.h>
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <frc/commands/PIDSubsystem.h>
|
2017-10-17 21:37:58 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Pivot subsystem contains the Van-door motor and the pot for PID control
|
|
|
|
|
* of angle of the pivot and claw.
|
|
|
|
|
*/
|
|
|
|
|
class Pivot : public frc::PIDSubsystem {
|
2018-05-13 17:09:56 -07:00
|
|
|
public:
|
|
|
|
|
// Constants for some useful angles
|
|
|
|
|
static constexpr double kCollect = 105;
|
|
|
|
|
static constexpr double kLowGoal = 90;
|
|
|
|
|
static constexpr double kShoot = 45;
|
|
|
|
|
static constexpr double kShootNear = 30;
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
Pivot();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* No default command, if PID is enabled, the current setpoint will be
|
|
|
|
|
* maintained.
|
|
|
|
|
*/
|
|
|
|
|
void InitDefaultCommand() override {}
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return The angle read in by the potentiometer
|
|
|
|
|
*/
|
|
|
|
|
double ReturnPIDInput() override;
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* Set the motor speed based off of the PID output
|
|
|
|
|
*/
|
|
|
|
|
void UsePIDOutput(double output) override;
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return If the pivot is at its upper limit.
|
|
|
|
|
*/
|
|
|
|
|
bool IsAtUpperLimit();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return If the pivot is at its lower limit.
|
|
|
|
|
*/
|
|
|
|
|
bool IsAtLowerLimit();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/**
|
|
|
|
|
* @return The current angle of the pivot.
|
|
|
|
|
*/
|
|
|
|
|
double GetAngle();
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
private:
|
|
|
|
|
// Subsystem devices
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
// Sensors for measuring the position of the pivot
|
|
|
|
|
frc::DigitalInput m_upperLimitSwitch{13};
|
|
|
|
|
frc::DigitalInput m_lowerLimitSwitch{12};
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
/* 0 degrees is vertical facing up.
|
|
|
|
|
* Angle increases the more forward the pivot goes.
|
|
|
|
|
*/
|
|
|
|
|
frc::AnalogPotentiometer m_pot{1};
|
2017-10-17 21:37:58 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
// Motor to move the pivot
|
2021-02-13 01:14:56 -05:00
|
|
|
frc::PWMSparkMax m_motor{5};
|
2017-10-17 21:37:58 -07:00
|
|
|
};
|