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;
|
|
|
|
|
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
|
2020-02-06 19:57:25 -07:00
|
|
|
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
|
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;
|
2020-02-10 16:57:41 -08:00
|
|
|
import com.revrobotics.ControlType;
|
2020-01-28 17:07:49 -08:00
|
|
|
import com.revrobotics.SparkMax;
|
|
|
|
|
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj.DigitalInput;
|
2020-02-10 19:13:34 -08:00
|
|
|
import edu.wpi.first.wpilibj.Encoder;
|
2020-01-28 17:07:49 -08:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
|
|
|
|
|
|
|
|
import frc4388.robot.Constants.StorageConstants;
|
|
|
|
|
|
|
|
|
|
public class Storage extends SubsystemBase {
|
2020-02-08 12:02:07 -08:00
|
|
|
private CANSparkMax m_storageMotor = new CANSparkMax(StorageConstants.STORAGE_CAN_ID, MotorType.kBrushless);
|
2020-01-28 17:07:49 -08:00
|
|
|
private DigitalInput[] m_beamSensors = new DigitalInput[6];
|
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-01-28 17:07:49 -08:00
|
|
|
/**
|
|
|
|
|
* Creates a new Storage.
|
|
|
|
|
*/
|
|
|
|
|
public Storage() {
|
2020-02-10 19:13:34 -08:00
|
|
|
resetEncoder();
|
|
|
|
|
|
2020-01-28 17:07:49 -08:00
|
|
|
m_beamSensors[0] = new DigitalInput(StorageConstants.BEAM_SENSOR_DIO_0);
|
2020-02-06 19:57:25 -07:00
|
|
|
m_beamSensors[1] = new DigitalInput(StorageConstants.BEAM_SENSOR_DIO_1);
|
|
|
|
|
m_beamSensors[2] = new DigitalInput(StorageConstants.BEAM_SENSOR_DIO_2);
|
|
|
|
|
m_beamSensors[3] = new DigitalInput(StorageConstants.BEAM_SENSOR_DIO_3);
|
|
|
|
|
m_beamSensors[4] = new DigitalInput(StorageConstants.BEAM_SENSOR_DIO_4);
|
|
|
|
|
m_beamSensors[5] = new DigitalInput(StorageConstants.BEAM_SENSOR_DIO_5);
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
// NO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs storage motor
|
2020-02-10 16:57:41 -08:00
|
|
|
*
|
2020-01-28 17:07:49 -08:00
|
|
|
* @param input the voltage to run motor at
|
|
|
|
|
*/
|
2020-02-10 16:57:41 -08:00
|
|
|
public void runStorage(final double input) {
|
2020-01-28 17:07:49 -08:00
|
|
|
m_storageMotor.set(input);
|
2020-02-10 16:57:41 -08:00
|
|
|
final boolean beam_on = m_beamSensors[0].get();
|
2020-02-06 19:57:25 -07:00
|
|
|
|
|
|
|
|
if (beam_on) {
|
|
|
|
|
System.err.println("Beam on");
|
|
|
|
|
} else {
|
|
|
|
|
System.err.println("Beam off");
|
|
|
|
|
}
|
2020-02-10 16:57:41 -08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 19:13:34 -08:00
|
|
|
public void resetEncoder()
|
|
|
|
|
{
|
|
|
|
|
m_encoder.setPosition(0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 16:57:41 -08:00
|
|
|
/* Storage PID Control */
|
|
|
|
|
public void runStoragePositionPID(double targetPos, double kP, double kI, double kD, double kIz, double kF, double kmaxOutput, double kminOutput)
|
|
|
|
|
{
|
|
|
|
|
// Set PID Coefficients
|
|
|
|
|
m_storagePIDController.setP(kP);
|
|
|
|
|
m_storagePIDController.setI(kI);
|
|
|
|
|
m_storagePIDController.setD(kD);
|
|
|
|
|
m_storagePIDController.setIZone(kIz);
|
|
|
|
|
m_storagePIDController.setFF(kF);
|
|
|
|
|
m_storagePIDController.setOutputRange(kminOutput, kmaxOutput);
|
|
|
|
|
|
|
|
|
|
m_storagePIDController.setReference(targetPos, ControlType.kPosition);
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|
2020-02-10 19:13:34 -08:00
|
|
|
|
|
|
|
|
public void getEncoderPos()
|
|
|
|
|
{
|
|
|
|
|
m_encoder.getPosition();
|
|
|
|
|
}
|
2020-01-28 17:07:49 -08:00
|
|
|
}
|