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;
|
2020-01-20 08:59:20 -08:00
|
|
|
import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
|
2020-01-18 15:28:48 -08:00
|
|
|
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
|
2020-02-15 13:34:53 -07:00
|
|
|
import com.revrobotics.CANSparkMax;
|
|
|
|
|
import com.revrobotics.CANSparkMax.IdleMode;
|
|
|
|
|
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
|
2020-01-18 15:28:48 -08:00
|
|
|
|
2020-02-15 13:34:53 -07:00
|
|
|
import edu.wpi.first.wpilibj.Joystick;
|
|
|
|
|
import edu.wpi.first.wpilibj.XboxController;
|
2020-01-20 15:22:44 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2020-01-18 15:28:48 -08:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
|
|
|
import frc4388.robot.Gains;
|
2020-01-20 15:22:44 -07:00
|
|
|
import frc4388.robot.Constants.DriveConstants;
|
2020-01-18 15:28:48 -08:00
|
|
|
import frc4388.robot.Constants.ShooterConstants;
|
2020-02-15 13:34:53 -07:00
|
|
|
import frc4388.utility.controller.IHandController;
|
2020-01-18 15:28:48 -08:00
|
|
|
|
|
|
|
|
public class Shooter extends SubsystemBase {
|
|
|
|
|
|
2020-01-20 08:59:20 -08:00
|
|
|
public WPI_TalonFX m_shooterFalcon = new WPI_TalonFX(ShooterConstants.SHOOTER_FALCON_ID);
|
2020-01-18 15:28:48 -08:00
|
|
|
|
|
|
|
|
public static Gains m_shooterGains = ShooterConstants.SHOOTER_GAINS;
|
2020-02-15 13:34:53 -07:00
|
|
|
public static Shooter m_shooter;
|
|
|
|
|
public static IHandController m_controller;
|
2020-01-31 21:39:51 -07:00
|
|
|
double velP;
|
2020-02-15 13:34:53 -07:00
|
|
|
double input;
|
|
|
|
|
public static CANSparkMax m_shooterRotate = new CANSparkMax(ShooterConstants.SHOOTERROTATION_SPARK_ID, MotorType.kBrushless);
|
|
|
|
|
|
|
|
|
|
/*
|
2020-02-10 19:21:10 -07:00
|
|
|
* Creates a new Shooter subsystem.
|
2020-01-18 15:28:48 -08:00
|
|
|
*/
|
|
|
|
|
public Shooter() {
|
|
|
|
|
m_shooterFalcon.configFactoryDefault();
|
2020-02-15 13:34:53 -07:00
|
|
|
m_shooterRotate.setIdleMode(IdleMode.kBrake);
|
2020-01-18 15:28:48 -08:00
|
|
|
m_shooterFalcon.setNeutralMode(NeutralMode.Coast);
|
2020-02-11 17:35:36 -07:00
|
|
|
m_shooterFalcon.setInverted(false);
|
2020-01-19 00:28:21 -07:00
|
|
|
|
|
|
|
|
setShooterGains();
|
2020-02-04 18:09:40 -07:00
|
|
|
|
|
|
|
|
m_shooterFalcon.configPeakOutputReverse(0, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
2020-01-19 00:28:21 -07:00
|
|
|
|
|
|
|
|
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
|
2020-01-21 16:45:29 -07:00
|
|
|
SmartDashboard.putNumber("Shooter Velocity", m_shooterFalcon.getSelectedSensorVelocity()*600/ShooterConstants.ENCODER_TICKS_PER_REV);
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
2020-02-10 18:02:37 -07:00
|
|
|
m_shooterFalcon.config_kF(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.m_kF, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kP(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.m_kP, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kI(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.m_kI, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kD(ShooterConstants.SHOOTER_SLOT_IDX, m_shooterGains.m_kD, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|
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
|
|
|
|
|
*/
|
2020-01-31 21:39:51 -07:00
|
|
|
public void runDrumShooterVelocityPID(double targetVel, double actualVel) {
|
2020-02-04 18:09:40 -07:00
|
|
|
velP = actualVel/targetVel; //Percent of target
|
|
|
|
|
double runSpeed = actualVel + (12000*velP); //Ramp up equation
|
|
|
|
|
//if (runSpeed > targetVel) {runSpeed = targetVel;}
|
2020-02-01 12:40:39 -07:00
|
|
|
SmartDashboard.putNumber("shoot", actualVel);
|
2020-02-04 18:09:40 -07:00
|
|
|
runSpeed = runSpeed/targetVel; //Convert to percent
|
2020-02-10 19:21:10 -07:00
|
|
|
if (actualVel < targetVel - 1000){ //PID Based on ramp up amount
|
2020-02-04 18:09:40 -07:00
|
|
|
m_shooterFalcon.set(TalonFXControlMode.PercentOutput, runSpeed);
|
2020-02-01 16:07:59 -07:00
|
|
|
}
|
2020-02-10 19:21:10 -07:00
|
|
|
else{ //PID Based on targetVel
|
2020-02-04 18:09:40 -07:00
|
|
|
m_shooterFalcon.set(TalonFXControlMode.Velocity, targetVel); //Init PID
|
2020-02-01 16:07:59 -07:00
|
|
|
}
|
2020-01-19 00:28:21 -07:00
|
|
|
}
|
2020-02-15 13:34:53 -07:00
|
|
|
//PLZ Help I Have No Idea What I Am Doing
|
|
|
|
|
//Help PLZ
|
|
|
|
|
//I Am Desperate
|
|
|
|
|
//PLZ
|
|
|
|
|
//PLZ
|
|
|
|
|
//With A Cherry On Top
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#Janky
|
|
|
|
|
public void runShooterWithInput(IHandController controller) {
|
|
|
|
|
/* m_controller = controller;
|
|
|
|
|
input = controller.getLeftXAxis();
|
|
|
|
|
* System.err.println(input);
|
|
|
|
|
* m_shooterFalcon.set(TalonFXControlMode.PercentOutput, 0.3);
|
|
|
|
|
*/
|
|
|
|
|
input = controller.getLeftXAxis();
|
|
|
|
|
System.err.println(input);
|
|
|
|
|
m_shooterRotate.set(input);
|
|
|
|
|
}
|
|
|
|
|
//#Janky
|
2020-01-31 21:39:51 -07:00
|
|
|
}
|