2020-01-28 17:07:49 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
package frc4388.robot.subsystems;
|
|
|
|
|
|
2020-02-10 19:13:34 -08:00
|
|
|
import com.revrobotics.CANEncoder;
|
2020-02-10 16:57:41 -08:00
|
|
|
import com.revrobotics.CANPIDController;
|
2020-01-28 17:07:49 -08:00
|
|
|
import com.revrobotics.CANSparkMax;
|
|
|
|
|
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
|
2020-03-02 21:23:33 -07:00
|
|
|
import com.revrobotics.ControlType;
|
|
|
|
|
|
2020-01-28 17:07:49 -08:00
|
|
|
import edu.wpi.first.wpilibj.DigitalInput;
|
2020-02-28 20:05:56 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2020-01-28 17:07:49 -08:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
|
|
|
import frc4388.robot.Constants.StorageConstants;
|
2020-03-02 21:23:33 -07:00
|
|
|
import frc4388.utility.Gains;
|
2020-01-28 17:07:49 -08:00
|
|
|
|
|
|
|
|
public class Storage extends SubsystemBase {
|
2020-02-28 20:05:56 -07:00
|
|
|
public CANSparkMax m_storageMotor = new CANSparkMax(StorageConstants.STORAGE_CAN_ID, MotorType.kBrushless);
|
2020-03-08 12:14:24 -06:00
|
|
|
private DigitalInput m_beamShooter = new DigitalInput(StorageConstants.BEAM_SENSOR_SHOOTER);
|
|
|
|
|
private DigitalInput m_beamUseless = new DigitalInput(StorageConstants.BEAM_SENSOR_USELESS);
|
|
|
|
|
private DigitalInput m_beamStorage = new DigitalInput(StorageConstants.BEAM_SENSOR_STORAGE);
|
|
|
|
|
private DigitalInput m_beamIntake = new DigitalInput(StorageConstants.BEAM_SENSOR_INTAKE);
|
2020-02-10 16:57:41 -08:00
|
|
|
|
|
|
|
|
CANPIDController m_storagePIDController = m_storageMotor.getPIDController();
|
|
|
|
|
|
2020-02-10 19:13:34 -08:00
|
|
|
CANEncoder m_encoder = m_storageMotor.getEncoder();
|
|
|
|
|
|
2020-02-11 20:07:35 -07:00
|
|
|
Gains storageGains = StorageConstants.STORAGE_GAINS;
|
|
|
|
|
|
2020-02-15 11:16:12 -08:00
|
|
|
Intake m_intake;
|
|
|
|
|
|
2020-03-03 01:12:07 -07:00
|
|
|
public boolean m_isStorageReadyToFire = false;
|
2020-02-21 20:41:36 -07:00
|
|
|
|
2020-01-28 17:07:49 -08:00
|
|
|
/**
|
|
|
|
|
* Creates a new Storage.
|
|
|
|
|
*/
|
|
|
|
|
public Storage() {
|
2020-02-10 19:13:34 -08:00
|
|
|
resetEncoder();
|
2020-03-08 12:14:24 -06:00
|
|
|
|
|
|
|
|
// Set PID Coefficients
|
|
|
|
|
m_storagePIDController.setP(storageGains.m_kP);
|
|
|
|
|
m_storagePIDController.setI(storageGains.m_kI);
|
|
|
|
|
m_storagePIDController.setD(storageGains.m_kD);
|
|
|
|
|
m_storagePIDController.setIZone(storageGains.m_kIzone);
|
|
|
|
|
m_storagePIDController.setFF(storageGains.m_kF);
|
|
|
|
|
m_storagePIDController.setOutputRange(storageGains.m_kminOutput, storageGains.m_kmaxOutput);
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
2020-03-08 12:35:14 -06:00
|
|
|
SmartDashboard.putBoolean("Intake Beam", getBeamIntake());
|
|
|
|
|
SmartDashboard.putBoolean("Storage Beam", getBeamStorage());
|
|
|
|
|
SmartDashboard.putBoolean("Upper Beam", getBeamUseless());
|
|
|
|
|
SmartDashboard.putBoolean("Shooter Beam", getBeamShooter());
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs storage motor
|
2020-02-10 16:57:41 -08:00
|
|
|
*
|
2020-03-08 12:14:24 -06:00
|
|
|
* @param input the percent output to run motor at
|
2020-01-28 17:07:49 -08:00
|
|
|
*/
|
2020-02-21 21:11:43 -07:00
|
|
|
public void runStorage(double input) {
|
2020-01-28 17:07:49 -08:00
|
|
|
m_storageMotor.set(input);
|
2020-02-10 16:57:41 -08:00
|
|
|
}
|
|
|
|
|
|
2020-02-21 20:41:36 -07:00
|
|
|
public void resetEncoder(){
|
2020-02-10 19:13:34 -08:00
|
|
|
m_encoder.setPosition(0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 12:14:24 -06:00
|
|
|
/**
|
|
|
|
|
* Runs Storage to a particular position
|
|
|
|
|
* @param targetPos in inches
|
|
|
|
|
*/
|
2020-02-21 20:41:36 -07:00
|
|
|
public void runStoragePositionPID(double targetPos){
|
2020-03-02 22:32:29 -07:00
|
|
|
//SmartDashboard.putNumber("Storage Position PID Target", targetPos);
|
|
|
|
|
//SmartDashboard.putNumber("Storage Position Pos", getEncoderPos());
|
2020-03-08 12:14:24 -06:00
|
|
|
targetPos = InchesToMotorRots(targetPos);
|
2020-02-10 16:57:41 -08:00
|
|
|
m_storagePIDController.setReference(targetPos, ControlType.kPosition);
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|
2020-02-10 19:13:34 -08:00
|
|
|
|
2020-03-08 12:14:24 -06:00
|
|
|
/**
|
|
|
|
|
* Runs Storage to a particular position
|
|
|
|
|
* @param position in motor rotations
|
|
|
|
|
*/
|
|
|
|
|
public void setStoragePID(double position){
|
|
|
|
|
m_storagePIDController.setReference(position, ControlType.kPosition);
|
|
|
|
|
}
|
2020-02-21 20:42:45 -07:00
|
|
|
|
2020-02-21 20:41:36 -07:00
|
|
|
public double getEncoderPos(){
|
|
|
|
|
return m_encoder.getPosition();
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|
2020-02-11 17:35:16 -07:00
|
|
|
|
2020-03-08 12:14:24 -06:00
|
|
|
/**
|
|
|
|
|
* @param motorRots
|
|
|
|
|
* @return inches
|
|
|
|
|
*/
|
|
|
|
|
public double motorRotsToInches(double motorRots) {
|
|
|
|
|
return motorRots * (1/StorageConstants.MOTOR_ROTS_PER_STORAGE_ROT) * (StorageConstants.INCHES_PER_STORAGE_ROT);
|
2020-02-13 19:07:36 -07:00
|
|
|
}
|
2020-02-21 20:41:36 -07:00
|
|
|
|
2020-03-08 12:14:24 -06:00
|
|
|
/**
|
|
|
|
|
* @param inches
|
|
|
|
|
* @return motorRots
|
|
|
|
|
*/
|
|
|
|
|
public double InchesToMotorRots(double inches) {
|
|
|
|
|
return inches * (1/StorageConstants.INCHES_PER_STORAGE_ROT) * (StorageConstants.MOTOR_ROTS_PER_STORAGE_ROT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getBeamShooter(){
|
|
|
|
|
return m_beamShooter.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getBeamUseless(){
|
|
|
|
|
return m_beamUseless.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getBeamStorage(){
|
|
|
|
|
return m_beamStorage.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getBeamIntake(){
|
|
|
|
|
return m_beamIntake.get();
|
2020-02-11 17:35:16 -07:00
|
|
|
}
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|