2024-01-19 21:24:11 -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-10 15:48:00 -07:00
|
|
|
import java.util.function.BooleanSupplier;
|
|
|
|
|
|
2024-02-20 00:46:44 -07:00
|
|
|
import com.ctre.phoenix.motorcontrol.ControlMode;
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.LimitSwitchNormal;
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.can.TalonSRXPIDSetConfiguration;
|
|
|
|
|
import com.ctre.phoenix6.configs.HardwareLimitSwitchConfigs;
|
|
|
|
|
import com.ctre.phoenix6.configs.Slot0Configs;
|
|
|
|
|
import com.ctre.phoenix6.configs.TalonFXConfiguration;
|
|
|
|
|
import com.ctre.phoenix6.controls.PositionVoltage;
|
|
|
|
|
import com.ctre.phoenix6.hardware.CANcoder;
|
|
|
|
|
import com.ctre.phoenix6.hardware.TalonFX;
|
|
|
|
|
import com.ctre.phoenix6.signals.ForwardLimitTypeValue;
|
|
|
|
|
import com.ctre.phoenix6.signals.ForwardLimitValue;
|
|
|
|
|
import com.ctre.phoenix6.signals.NeutralModeValue;
|
|
|
|
|
import com.ctre.phoenix6.signals.ReverseLimitTypeValue;
|
|
|
|
|
import com.ctre.phoenix6.signals.ReverseLimitValue;
|
2024-02-14 19:44:24 -07:00
|
|
|
import com.revrobotics.CANSparkBase;
|
2024-01-19 21:24:11 -07:00
|
|
|
import com.revrobotics.CANSparkMax;
|
|
|
|
|
import com.revrobotics.SparkLimitSwitch;
|
2024-02-07 18:53:57 -07:00
|
|
|
import com.revrobotics.SparkPIDController;
|
2024-02-06 19:24:32 -07:00
|
|
|
import com.revrobotics.RelativeEncoder;
|
2024-01-19 21:24:11 -07:00
|
|
|
import edu.wpi.first.wpilibj.CAN;
|
|
|
|
|
import edu.wpi.first.wpilibj.motorcontrol.Spark;
|
2024-02-20 00:46:44 -07:00
|
|
|
import edu.wpi.first.wpilibj.motorcontrol.Talon;
|
2024-02-09 22:01:27 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2024-01-19 21:24:11 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
2024-02-07 18:53:57 -07:00
|
|
|
import frc4388.robot.Constants;
|
2024-01-20 10:10:17 -07:00
|
|
|
import frc4388.robot.Constants.IntakeConstants;
|
2024-02-07 18:53:57 -07:00
|
|
|
import frc4388.robot.commands.PID;
|
|
|
|
|
import frc4388.utility.Gains;
|
2024-03-07 19:22:41 -07:00
|
|
|
import frc4388.utility.configurable.ConfigurableDouble;
|
2024-01-19 21:24:11 -07:00
|
|
|
|
|
|
|
|
public class Intake extends SubsystemBase {
|
2024-01-26 20:56:02 -07:00
|
|
|
|
2024-02-20 00:46:44 -07:00
|
|
|
//NEO
|
2024-01-22 18:04:12 -07:00
|
|
|
private CANSparkMax intakeMotor;
|
|
|
|
|
private CANSparkMax pivot;
|
2024-02-07 18:53:57 -07:00
|
|
|
private SparkPIDController m_spedController;
|
|
|
|
|
private SparkLimitSwitch forwardLimit;
|
|
|
|
|
private SparkLimitSwitch reverseLimit;
|
2024-02-10 13:11:30 -07:00
|
|
|
private SparkLimitSwitch intakeforwardLimit;
|
|
|
|
|
private SparkLimitSwitch intakereverseLimit;
|
2024-02-20 00:46:44 -07:00
|
|
|
|
|
|
|
|
//Talon
|
|
|
|
|
private TalonFX talonIntake;
|
|
|
|
|
private TalonFX talonPivot;
|
|
|
|
|
private CANcoder encoder;
|
|
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
private boolean r;
|
|
|
|
|
|
2024-02-20 00:46:44 -07:00
|
|
|
private HardwareLimitSwitchConfigs l;
|
|
|
|
|
|
|
|
|
|
TalonFXConfiguration doodooController = new TalonFXConfiguration();
|
|
|
|
|
|
|
|
|
|
public static Gains armGains = IntakeConstants.ArmPID.INTAKE_GAINS;
|
2024-03-07 19:22:41 -07:00
|
|
|
private ConfigurableDouble outtakeSpeed = new ConfigurableDouble("Outtake Speed", IntakeConstants.INTAKE_OUT_SPEED_UNPRESSED);
|
2024-02-13 20:01:12 -07:00
|
|
|
private BooleanSupplier sup = () -> true;
|
|
|
|
|
private BooleanSupplier dup = () -> false;
|
2024-02-16 21:49:50 -07:00
|
|
|
|
2024-02-17 10:16:20 -07:00
|
|
|
private double smartDashboardOuttakeValue;
|
2024-02-06 19:24:32 -07:00
|
|
|
|
2024-01-26 20:56:02 -07:00
|
|
|
/** Creates a new Intake. */
|
2024-02-20 00:46:44 -07:00
|
|
|
//For NEO
|
2024-02-21 00:03:15 -07:00
|
|
|
// public Intake(CANSparkMax intakeMotor, CANSparkMax pivot) {
|
|
|
|
|
// this.intakeMotor = intakeMotor;
|
|
|
|
|
// this.pivot = pivot;
|
2024-02-07 18:53:57 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// pivot.restoreFactoryDefaults();
|
|
|
|
|
// //pivot.setInverted(true);
|
2024-02-07 18:53:57 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// forwardLimit = pivot.getForwardLimitSwitch(SparkLimitSwitch.Type.kNormallyOpen);
|
|
|
|
|
// reverseLimit = pivot.getReverseLimitSwitch(SparkLimitSwitch.Type.kNormallyOpen);
|
|
|
|
|
// forwardLimit.enableLimitSwitch(true);
|
|
|
|
|
// reverseLimit.enableLimitSwitch(true);
|
2024-02-10 13:11:30 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// intakeMotor.restoreFactoryDefaults();
|
2024-02-07 18:53:57 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// intakeforwardLimit = intakeMotor.getForwardLimitSwitch(SparkLimitSwitch.Type.kNormallyOpen);
|
|
|
|
|
// intakereverseLimit = intakeMotor.getReverseLimitSwitch(SparkLimitSwitch.Type.kNormallyOpen);
|
|
|
|
|
// intakeforwardLimit.enableLimitSwitch(true);
|
|
|
|
|
// intakereverseLimit.enableLimitSwitch(false);
|
|
|
|
|
|
|
|
|
|
// //Arm PID
|
|
|
|
|
// m_spedController = pivot.getPIDController();
|
|
|
|
|
// m_spedController.setP(armGains.kP);
|
|
|
|
|
// m_spedController.setI(armGains.kI);
|
|
|
|
|
// m_spedController.setD(armGains.kD);
|
|
|
|
|
|
|
|
|
|
// SmartDashboard.putNumber("Outtake Speed", IntakeConstants.INTAKE_OUT_SPEED_UNPRESSED);
|
|
|
|
|
// }
|
2024-01-19 21:24:11 -07:00
|
|
|
|
2024-02-20 00:46:44 -07:00
|
|
|
//For Talon
|
|
|
|
|
public Intake(TalonFX talonIntake, TalonFX talonPivot) {
|
|
|
|
|
this.talonIntake = talonIntake;
|
|
|
|
|
this.talonPivot = talonPivot;
|
|
|
|
|
|
|
|
|
|
talonIntake.getConfigurator().apply(new TalonFXConfiguration());
|
|
|
|
|
talonPivot.getConfigurator().apply(new TalonFXConfiguration());
|
|
|
|
|
|
|
|
|
|
talonIntake.setNeutralMode(NeutralModeValue.Brake);
|
|
|
|
|
talonPivot.setNeutralMode(NeutralModeValue.Brake);
|
|
|
|
|
|
2024-02-20 17:40:33 -07:00
|
|
|
// talonPivot.getConfigurator().apply(new HardwareLimitSwitchConfigs());
|
|
|
|
|
// talonIntake.getConfigurator().apply(new HardwareLimitSwitchConfigs());
|
2024-02-20 00:46:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-02-20 17:40:33 -07:00
|
|
|
// doodooController.Slot0.kP = armGains.kP;
|
|
|
|
|
// doodooController.Slot1.kI = armGains.kI;
|
|
|
|
|
// doodooController.Slot2.kD = armGains.kD;
|
2024-02-20 00:46:44 -07:00
|
|
|
|
|
|
|
|
// in init function, set slot 0 gains
|
|
|
|
|
var slot0Configs = new Slot0Configs();
|
2024-02-21 00:03:15 -07:00
|
|
|
slot0Configs.kP = 0.7; // An error of 0.5 rotations results in 12 V output
|
2024-02-20 00:46:44 -07:00
|
|
|
slot0Configs.kI = 0.0; // no output for integrated error
|
2024-02-21 00:03:15 -07:00
|
|
|
slot0Configs.kD = 0.06; // A velocity of 1 rps results in 0.1 V output
|
2024-02-20 00:46:44 -07:00
|
|
|
|
|
|
|
|
talonPivot.getConfigurator().apply(slot0Configs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ! Talon Methods
|
|
|
|
|
public void talonPIDIn() {
|
2024-02-21 00:03:15 -07:00
|
|
|
PositionVoltage request = new PositionVoltage(-59);
|
2024-02-29 06:45:18 -07:00
|
|
|
talonPivot.setControl(request.withPosition(0));
|
2024-02-20 00:46:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void talonPIDOut() {
|
2024-02-21 00:03:15 -07:00
|
|
|
PositionVoltage request = new PositionVoltage(0);
|
2024-02-29 06:45:18 -07:00
|
|
|
talonPivot.setControl(request.withPosition(-59));
|
2024-02-20 00:46:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void talonHandoff() {
|
2024-03-07 19:22:41 -07:00
|
|
|
talonIntake.set(-outtakeSpeed.get());
|
2024-02-20 00:46:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void talonSpinIntakeMotor() {
|
|
|
|
|
talonIntake.set(IntakeConstants.INTAKE_SPEED);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 16:29:42 -07:00
|
|
|
public void talonSpinIntakeMotor(double speed) {
|
|
|
|
|
talonIntake.set(speed);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 00:46:44 -07:00
|
|
|
public boolean getTalonIntakeLimitSwitchState() {
|
2024-02-21 00:03:15 -07:00
|
|
|
if(r = talonIntake.getForwardLimit().getValue().value == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2024-02-20 00:46:44 -07:00
|
|
|
}
|
|
|
|
|
|
2024-02-20 18:56:57 -07:00
|
|
|
public void talonSetPivotEncoderPosition(int val) {
|
|
|
|
|
talonPivot.setPosition(val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void talonStopIntakeMotors() {
|
|
|
|
|
talonIntake.set(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void talonStopArmMotor() {
|
|
|
|
|
talonPivot.set(0);
|
|
|
|
|
}
|
2024-02-20 00:46:44 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
public double getArmPos() {
|
|
|
|
|
return talonPivot.getPosition().getValue();
|
2024-02-09 22:01:27 -07:00
|
|
|
}
|
|
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
public void resetArmPosition() {
|
|
|
|
|
if(getTalonIntakeLimitSwitchState()){
|
|
|
|
|
// talonPivot.setPosition(0);
|
2024-02-09 22:01:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 16:29:42 -07:00
|
|
|
public void ampPosition() {
|
|
|
|
|
PositionVoltage request = new PositionVoltage(-0);
|
|
|
|
|
talonPivot.setControl(request.withPosition(-59)); //TODO: Find actual value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ampShoot(double speed) {
|
|
|
|
|
talonSpinIntakeMotor(speed);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 22:01:27 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// ! NEO Methods
|
|
|
|
|
//hanoff
|
|
|
|
|
// public void spinIntakeMotor() {
|
|
|
|
|
// intakeMotor.set(IntakeConstants.INTAKE_SPEED);
|
|
|
|
|
// }
|
2024-02-16 21:49:50 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// //Rotate robot in for handoff
|
|
|
|
|
// public void rotateArmIn() {
|
|
|
|
|
// pivot.set(IntakeConstants.PIVOT_SPEED);
|
|
|
|
|
// }
|
2024-02-06 19:24:32 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// //Rotates robot out for intake
|
|
|
|
|
// public void rotateArmOut() {
|
|
|
|
|
// pivot.set(-IntakeConstants.PIVOT_SPEED);
|
2024-01-22 17:43:40 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// }
|
2024-02-10 15:48:00 -07:00
|
|
|
|
2024-02-21 00:03:15 -07:00
|
|
|
// public void pidIn() {
|
|
|
|
|
// m_spedController.setReference(2.5, CANSparkMax.ControlType.kPosition);
|
|
|
|
|
// //SmartDashboard.putNumber("Velocity Output", pivot.getEncoder().getVelocity());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void pidOut() {
|
|
|
|
|
// m_spedController.setReference(-53, CANSparkMax.ControlType.kPosition);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void limitNote() {
|
|
|
|
|
// if (intakeforwardLimit.isPressed()) {
|
|
|
|
|
// rotateArmIn2();
|
|
|
|
|
// } else {
|
|
|
|
|
// spinIntakeMotor();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void rotateArmOut2() {
|
|
|
|
|
// if(reverseLimit.isPressed()){
|
|
|
|
|
// stopArmMotor();
|
|
|
|
|
// } else {
|
|
|
|
|
// pidOut();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void rotateArmIn2() {
|
|
|
|
|
// if(forwardLimit.isPressed()){
|
|
|
|
|
// stopArmMotor();
|
|
|
|
|
// } else {
|
|
|
|
|
// pidIn();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void handoff() {
|
|
|
|
|
// intakeMotor.set(-IntakeConstants.INTAKE_OUT_SPEED_UNPRESSED);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void handoff2() {
|
|
|
|
|
// if(intakeforwardLimit.isPressed()) {
|
|
|
|
|
// intakeMotor.set(-smartDashboardOuttakeValue);
|
|
|
|
|
// } else {
|
|
|
|
|
// intakeMotor.set(-smartDashboardOuttakeValue);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void stopIntakeMotors() {
|
|
|
|
|
// intakeMotor.set(0);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void stopArmMotor() {
|
|
|
|
|
// pivot.set(0);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public RelativeEncoder getEncoder() {
|
|
|
|
|
// return pivot.getEncoder();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public boolean getForwardLimitSwitchState() {
|
|
|
|
|
// return forwardLimit.isPressed();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public boolean getReverseLimitSwitchState() {
|
|
|
|
|
// return reverseLimit.isPressed();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public boolean getIntakeLimitSwtichState() {
|
|
|
|
|
// return intakeforwardLimit.isPressed();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void setVoltage(double voltage) {
|
|
|
|
|
// pivot.setVoltage(voltage);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public double getVelocity() {
|
|
|
|
|
// return pivot.getEncoder().getVelocity();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void setPivotEncoderPosition(int val) {
|
|
|
|
|
// pivot.getEncoder().setPosition(val);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void resetPosition() {
|
|
|
|
|
// if(forwardLimit.isPressed()) {
|
|
|
|
|
// setPivotEncoderPosition(0);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public double getPos() {
|
|
|
|
|
// return pivot.getEncoder().getPosition();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public double getIntakeVelocity() {
|
|
|
|
|
// return intakeMotor.getEncoder().getVelocity();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void rotateArm() {
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public BooleanSupplier getArmFowardLimitState() {
|
|
|
|
|
// if(forwardLimit.isPressed()) {
|
|
|
|
|
// return sup;
|
|
|
|
|
// } else {
|
|
|
|
|
// return dup;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void changeIntakeNeutralState() {
|
|
|
|
|
// if(forwardLimit.isPressed()) {
|
|
|
|
|
// intakeMotor.setIdleMode(CANSparkBase.IdleMode.kCoast);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-02-16 21:49:50 -07:00
|
|
|
|
2024-01-19 21:24:11 -07:00
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
// This method will be called once per scheduler run
|
2024-02-21 00:03:15 -07:00
|
|
|
// SmartDashboard.putNumber("Vel Output", getVelocity());
|
|
|
|
|
// SmartDashboard.putNumber("Position", getPos());
|
|
|
|
|
// resetPosition();
|
|
|
|
|
// changeIntakeNeutralState();
|
|
|
|
|
|
|
|
|
|
resetArmPosition();
|
|
|
|
|
|
|
|
|
|
SmartDashboard.putNumber("Pivot Position", getArmPos());
|
2024-02-16 21:49:50 -07:00
|
|
|
|
2024-02-17 11:06:50 -07:00
|
|
|
smartDashboardOuttakeValue = SmartDashboard.getNumber("Outtake Speed", IntakeConstants.INTAKE_OUT_SPEED_UNPRESSED);
|
2024-01-19 21:24:11 -07:00
|
|
|
}
|
|
|
|
|
}
|