2020-01-18 15:28:48 -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.NeutralMode;
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
|
|
|
import frc4388.robot.Gains;
|
|
|
|
|
import frc4388.robot.Constants.ShooterConstants;
|
|
|
|
|
|
|
|
|
|
public class Shooter extends SubsystemBase {
|
|
|
|
|
|
|
|
|
|
WPI_TalonFX m_shooterFalcon = new WPI_TalonFX(ShooterConstants.SHOOTER_FALCON_ID);
|
|
|
|
|
|
|
|
|
|
public static Gains m_shooterGains = ShooterConstants.SHOOTER_GAINS;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new Shooter.
|
|
|
|
|
*/
|
|
|
|
|
public Shooter() {
|
|
|
|
|
m_shooterFalcon.configFactoryDefault();
|
|
|
|
|
|
|
|
|
|
m_shooterFalcon.setNeutralMode(NeutralMode.Coast);
|
|
|
|
|
|
|
|
|
|
m_shooterFalcon.setInverted(false);
|
2020-01-19 00:28:21 -07:00
|
|
|
|
|
|
|
|
setShooterGains();
|
|
|
|
|
|
|
|
|
|
m_shooterFalcon.setSelectedSensorPosition(0, ShooterConstants.SHOOTER_PID_LOOP_IDX, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
|
|
|
|
|
int closedLoopTimeMs = 1;
|
|
|
|
|
m_shooterFalcon.configClosedLoopPeriod(0, closedLoopTimeMs, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.configClosedLoopPeriod(1, closedLoopTimeMs, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
// This method will be called once per scheduler run
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs drum shooter motor.
|
2020-01-19 00:28:21 -07:00
|
|
|
* @param speed Speed to set the motor at
|
2020-01-18 15:28:48 -08:00
|
|
|
*/
|
|
|
|
|
public void runDrumShooter(double speed) {
|
|
|
|
|
m_shooterFalcon.set(speed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configures gains for shooter PID.
|
|
|
|
|
*/
|
|
|
|
|
public void setShooterGains() {
|
|
|
|
|
m_shooterFalcon.selectProfileSlot(ShooterConstants.SHOOTER_SLOT_IDX, ShooterConstants.SHOOTER_PID_LOOP_IDX);
|
|
|
|
|
m_shooterFalcon.config_kF(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.kF, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kP(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.kP, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kI(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.kI, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kD(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.kD, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
}
|
2020-01-19 00:28:21 -07:00
|
|
|
/**
|
|
|
|
|
* Runs drum shooter velocity PID.
|
|
|
|
|
* @param falcon Motor to use
|
|
|
|
|
* @param targetVel Target velocity to run motor at
|
|
|
|
|
*/
|
|
|
|
|
public void runDrumShooterVelocityPID(WPI_TalonFX falcon, double targetVel) {
|
|
|
|
|
falcon.set(TalonFXControlMode.Velocity, targetVel);
|
|
|
|
|
}
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|