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-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.Constants.ShooterConstants;
|
2020-03-02 21:23:33 -07:00
|
|
|
import frc4388.utility.Gains;
|
2020-02-22 15:34:10 -07:00
|
|
|
import frc4388.utility.ShooterTables;
|
2020-03-02 21:23:33 -07:00
|
|
|
import frc4388.utility.Trims;
|
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
|
|
|
|
2020-02-15 14:23:41 -07:00
|
|
|
public static Gains m_drumShooterGains = ShooterConstants.DRUM_SHOOTER_GAINS;
|
2020-02-15 13:34:53 -07:00
|
|
|
public static Shooter m_shooter;
|
|
|
|
|
public static IHandController m_controller;
|
2020-02-22 11:23:57 -07:00
|
|
|
|
2020-01-31 21:39:51 -07:00
|
|
|
double velP;
|
2020-02-15 13:34:53 -07:00
|
|
|
double input;
|
2020-02-22 15:34:10 -07:00
|
|
|
|
2020-03-02 21:03:39 -07:00
|
|
|
public ShooterTables m_shooterTable;
|
2020-02-15 13:34:53 -07:00
|
|
|
|
2020-03-03 01:12:07 -07:00
|
|
|
public boolean m_isDrumReady = false;
|
2020-02-20 20:21:28 -07:00
|
|
|
public double m_fireVel;
|
2020-02-29 23:45:07 -07:00
|
|
|
|
|
|
|
|
public Trims shooterTrims;
|
2020-03-02 23:56:05 -07:00
|
|
|
|
|
|
|
|
public ShooterHood m_shooterHoodSubsystem;
|
|
|
|
|
public ShooterAim m_shooterAimSubsystem;
|
2020-02-15 13:34:53 -07:00
|
|
|
|
|
|
|
|
/*
|
2020-03-01 00:41:23 -07:00
|
|
|
* Creates a new Shooter subsystem, with the drum shooter and the angle adjsuter.
|
2020-01-18 15:28:48 -08:00
|
|
|
*/
|
|
|
|
|
public Shooter() {
|
2020-02-13 18:57:11 -08:00
|
|
|
//Testing purposes reseting gyros
|
2020-02-29 18:42:37 -07:00
|
|
|
//resetGyroAngleAdj();
|
2020-02-29 23:45:07 -07:00
|
|
|
shooterTrims = new Trims(0, 0);
|
2020-03-03 20:59:00 -07:00
|
|
|
//SmartDashboard.putNumber("Velocity Target", 10000);
|
|
|
|
|
//SmartDashboard.putNumber("Angle Target", 3);
|
2020-02-29 23:45:07 -07:00
|
|
|
|
2020-01-18 15:28:48 -08:00
|
|
|
m_shooterFalcon.configFactoryDefault();
|
|
|
|
|
m_shooterFalcon.setNeutralMode(NeutralMode.Coast);
|
2020-02-29 18:42:37 -07:00
|
|
|
m_shooterFalcon.setInverted(true);
|
2020-02-25 17:44:59 -07:00
|
|
|
m_shooterFalcon.configOpenloopRamp(1, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
2020-03-03 20:59:00 -07:00
|
|
|
m_shooterFalcon.configClosedloopRamp(1.0, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
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);
|
2020-02-22 15:34:10 -07:00
|
|
|
|
|
|
|
|
m_shooterTable = new ShooterTables();
|
|
|
|
|
|
2020-03-03 20:59:00 -07:00
|
|
|
m_shooterFalcon.configSupplyCurrentLimit(ShooterConstants.SUPPLY_CURRENT_LIMIT_CONFIG, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
|
2020-03-02 22:32:29 -07:00
|
|
|
//SmartDashboard.putNumber("CSV 10", m_shooterTable.getVelocity(10));
|
|
|
|
|
//SmartDashboard.putNumber("CSV 200", m_shooterTable.getVelocity(200));
|
|
|
|
|
//SmartDashboard.putNumber("CSV 250", m_shooterTable.getVelocity(250));
|
|
|
|
|
//SmartDashboard.putNumber("CSV 500", m_shooterTable.getVelocity(500));
|
2020-02-22 15:34:10 -07:00
|
|
|
|
2020-03-02 22:32:29 -07:00
|
|
|
//SmartDashboard.putNumber("CSV A -30", m_shooterTable.getAngleDisplacement(-30));
|
|
|
|
|
//SmartDashboard.putNumber("CSV A 10", m_shooterTable.getAngleDisplacement(10));
|
|
|
|
|
//SmartDashboard.putNumber("CSV A 5", m_shooterTable.getAngleDisplacement(5));
|
|
|
|
|
//SmartDashboard.putNumber("CSV A 30", m_shooterTable.getAngleDisplacement(30));
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
// This method will be called once per scheduler run
|
2020-03-02 21:03:39 -07:00
|
|
|
try{
|
|
|
|
|
SmartDashboard.putNumber("Drum Velocity", m_shooterFalcon.getSelectedSensorVelocity());
|
|
|
|
|
|
2020-03-02 22:32:29 -07:00
|
|
|
SmartDashboard.putNumber("Drum Velocity CSV", m_fireVel);
|
2020-03-02 21:03:39 -07:00
|
|
|
|
2020-03-03 20:59:00 -07:00
|
|
|
SmartDashboard.putNumber("Shooter Temp C", m_shooterFalcon.getTemperature());
|
|
|
|
|
|
|
|
|
|
SmartDashboard.putNumber("Shooter Current", m_shooterFalcon.getSupplyCurrent());
|
|
|
|
|
|
2020-03-07 14:50:46 -07:00
|
|
|
SmartDashboard.putBoolean("Drum Ready", m_isDrumReady);
|
|
|
|
|
|
2020-03-02 21:03:39 -07:00
|
|
|
//SmartDashboard.putNumber("Hood Position", m_shooter.getAnglePosition());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:56:05 -07:00
|
|
|
/**
|
|
|
|
|
* Passes subsystem needed.
|
|
|
|
|
* @param subsystem Subsystem needed.
|
|
|
|
|
*/
|
|
|
|
|
public void passRequiredSubsystem(ShooterHood subsystem0, ShooterAim subsystem1) {
|
|
|
|
|
m_shooterHoodSubsystem = subsystem0;
|
|
|
|
|
m_shooterAimSubsystem = subsystem1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 20:21:28 -07:00
|
|
|
public double addFireVel() {
|
|
|
|
|
return m_fireVel;
|
|
|
|
|
}
|
2020-02-29 18:42:37 -07:00
|
|
|
|
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-21 21:58:56 -07:00
|
|
|
m_shooterFalcon.config_kF(ShooterConstants.SHOOTER_SLOT_IDX, m_drumShooterGains.m_kF, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kP(ShooterConstants.SHOOTER_SLOT_IDX, m_drumShooterGains.m_kP, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kI(ShooterConstants.SHOOTER_SLOT_IDX, m_drumShooterGains.m_kI, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
|
|
|
|
m_shooterFalcon.config_kD(ShooterConstants.SHOOTER_SLOT_IDX, m_drumShooterGains.m_kD, ShooterConstants.SHOOTER_TIMEOUT_MS);
|
2020-01-18 15:28:48 -08:00
|
|
|
}
|
2020-02-21 21:58:56 -07:00
|
|
|
|
2020-01-19 00:28:21 -07:00
|
|
|
/**
|
|
|
|
|
* Runs drum shooter velocity PID.
|
|
|
|
|
* @param targetVel Target velocity to run motor at
|
|
|
|
|
*/
|
2020-03-02 21:03:39 -07:00
|
|
|
public void runDrumShooterVelocityPID(double targetVel) {
|
2020-03-03 20:59:00 -07:00
|
|
|
//System.out.println("Target Velocity" + targetVel);
|
2020-03-02 21:03:39 -07:00
|
|
|
m_shooterFalcon.set(TalonFXControlMode.Velocity, targetVel); //Init PID
|
2020-01-19 00:28:21 -07:00
|
|
|
}
|
2020-01-31 21:39:51 -07:00
|
|
|
}
|