Files
2024AcrossTheRidgebotiverse/src/main/java/frc4388/robot/subsystems/Shooter.java
T

83 lines
2.1 KiB
Java
Raw Normal View History

2024-01-20 10:10:17 -07:00
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc4388.robot.subsystems;
2024-02-13 20:01:12 -07:00
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2024-01-20 10:10:17 -07:00
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants.ShooterConstants;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
2024-01-22 18:04:12 -07:00
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.NeutralModeValue;
2024-01-20 10:10:17 -07:00
import com.ctre.phoenix.motorcontrol.NeutralMode;
public class Shooter extends SubsystemBase {
2024-01-26 20:56:02 -07:00
2024-01-22 18:04:12 -07:00
private TalonFX leftShooter;
private TalonFX rightShooter;
2024-01-20 10:10:17 -07:00
2024-02-16 12:59:22 -07:00
private Limelight limelight;
// 0 = Stop
// 1 = Idle, no limelight
// 2 = limelight
// 3 = Shooting
private int shooterMode;
2024-01-20 10:10:17 -07:00
/** Creates a new Shooter. */
2024-02-16 12:59:22 -07:00
public Shooter(TalonFX leftTalonFX, TalonFX rightTalonFX, Limelight limelight) {
2024-01-20 10:10:17 -07:00
leftShooter = leftTalonFX;
rightShooter = rightTalonFX;
2024-02-16 12:59:22 -07:00
this.limelight = limelight;
2024-02-14 19:44:24 -07:00
leftShooter.setNeutralMode(NeutralModeValue.Coast);
rightShooter.setNeutralMode(NeutralModeValue.Coast);
2024-01-20 10:10:17 -07:00
}
public void spin() {
2024-02-16 12:59:22 -07:00
shooterMode = 3;
2024-01-20 10:10:17 -07:00
spin(ShooterConstants.SHOOTER_SPEED);
}
public void spin(double speed) {
2024-01-20 14:36:34 -07:00
leftShooter.set(-speed);
rightShooter.set(speed);
2024-01-20 10:10:17 -07:00
}
public void stop() {
2024-02-16 12:59:22 -07:00
shooterMode = 0;
2024-01-20 10:10:17 -07:00
spin(0.d);
}
2024-02-13 20:01:12 -07:00
public void idle() {
2024-02-16 12:59:22 -07:00
if(limelight.isNearSpeaker()){
shooterMode = 2;
spin(ShooterConstants.SHOOTER_IDLE_LIMELIGHT);
}else{
shooterMode = 1;
spin(ShooterConstants.SHOOTER_IDLE);
}
2024-02-13 20:01:12 -07:00
}
2024-01-20 10:10:17 -07:00
@Override
public void periodic() {
// This method will be called once per scheduler run
2024-02-16 12:59:22 -07:00
if(limelight.isNearSpeaker() && shooterMode == 0){
shooterMode = 1;
spin(ShooterConstants.SHOOTER_IDLE_LIMELIGHT);
}
SmartDashboard.putNumber("Shooter Speed mode", shooterMode);
2024-02-13 20:01:12 -07:00
SmartDashboard.putNumber("Left Shooter RPM", leftShooter.getRotorVelocity().getValue());
SmartDashboard.putNumber("Right Shooter RPM", rightShooter.getRotorVelocity().getValue());
2024-01-20 10:10:17 -07:00
}
}