Files
2022NoWayHome/src/main/java/frc4388/robot/subsystems/Claws.java
T

171 lines
6.2 KiB
Java
Raw Normal View History

2022-03-05 14:21:48 -07:00
package frc4388.robot.subsystems;
2022-03-16 14:41:27 -06:00
import java.nio.file.ClosedWatchServiceException;
2022-03-05 14:21:48 -07:00
import com.ctre.phoenix.motorcontrol.LimitSwitchNormal;
import com.revrobotics.CANSparkMax;
import com.revrobotics.SparkMaxLimitSwitch;
import edu.wpi.first.wpilibj.DigitalInput;
2022-03-16 14:49:41 -06:00
import edu.wpi.first.wpilibj.Servo;
2022-03-16 22:32:57 -06:00
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2022-03-05 14:21:48 -07:00
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants.ClawConstants;
2022-03-16 14:41:27 -06:00
import frc4388.robot.Constants.ClimberConstants;
2022-03-05 14:21:48 -07:00
public class Claws extends SubsystemBase {
2022-03-16 14:49:41 -06:00
public Servo m_leftClaw;
public Servo m_rightClaw;
// public CANSparkMax m_leftClaw;
// public CANSparkMax m_rightClaw;
// private SparkMaxLimitSwitch m_leftLimitSwitchF;
// private SparkMaxLimitSwitch m_rightLimitSwitchF;
// private SparkMaxLimitSwitch m_leftLimitSwitchR;
// private SparkMaxLimitSwitch m_rightLimitSwitchR;
2022-03-05 14:21:48 -07:00
private double m_leftOffset;
private double m_rightOffset;
private boolean m_open;
2022-03-05 14:38:54 -07:00
public static enum ClawType {LEFT, RIGHT}
2022-03-05 14:21:48 -07:00
2022-03-16 14:49:41 -06:00
public Claws(/*CANSparkMax*/Servo leftClaw, /*CANSparkMax*/Servo rightClaw) {
2022-03-05 14:21:48 -07:00
m_leftClaw = leftClaw;
m_rightClaw = rightClaw;
2022-03-16 14:49:41 -06:00
// m_leftLimitSwitchF = m_leftClaw.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
// m_rightLimitSwitchF = m_rightClaw.getForwardLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
// m_leftLimitSwitchR = m_leftClaw.getReverseLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyClosed); //Wired wrong lol
// m_rightLimitSwitchR = m_rightClaw.getReverseLimitSwitch(SparkMaxLimitSwitch.Type.kNormallyOpen);
// m_leftLimitSwitchF.enableLimitSwitch(true);
// m_rightLimitSwitchF.enableLimitSwitch(true);
// m_leftLimitSwitchR.enableLimitSwitch(true);
// m_rightLimitSwitchR.enableLimitSwitch(true);
2022-03-05 14:21:48 -07:00
2022-03-16 14:49:41 -06:00
// m_leftClaw.setInverted(true);
// m_rightClaw.setInverted(true);
2022-03-05 14:21:48 -07:00
m_open = false;
// m_leftClaw.set(ClawConstants.CALIBRATION_SPEED);
// m_rightClaw.set(ClawConstants.CALIBRATION_SPEED);
}
2022-03-05 14:38:54 -07:00
/**
* Run a specific claw to open or close.
* @param which Which claw to run.
* @param open Whether to open or close the claw.
*/
2022-03-16 22:32:57 -06:00
// public void runClaw(ClawType which, boolean open) {
2022-03-05 23:07:12 -07:00
2022-03-16 22:32:57 -06:00
// int direction = open ? 1 : -1;
2022-03-05 23:07:12 -07:00
2022-03-16 22:32:57 -06:00
// if (which == Claws.ClawType.LEFT) {
2022-03-05 14:38:54 -07:00
2022-03-16 22:32:57 -06:00
// // double setPos = open ? ClawsConstants.OPEN_POSITION + m_leftOffset : ClawsConstants.CLOSE_POSITION + m_leftOffset;
// // m_leftClaw.getEncoder().setPosition(setPos);
// m_leftClaw.setSpeed(direction * 0.1);
2022-03-05 14:38:54 -07:00
2022-03-16 22:32:57 -06:00
// } else if (which == Claws.ClawType.RIGHT) {
2022-03-05 14:38:54 -07:00
2022-03-16 22:32:57 -06:00
// // double setPos = open ? ClawsConstants.OPEN_POSITION + m_rightOffset : ClawsConstants.CLOSE_POSITION + m_rightOffset;
// // m_rightClaw.getEncoder().setPosition(setPos);
// m_rightClaw.setSpeed(direction * 0.1);
// }
2022-03-05 23:07:12 -07:00
2022-03-16 22:32:57 -06:00
// m_open = open;
// }
2022-03-10 17:06:17 -07:00
2022-03-16 22:32:57 -06:00
// public void runClaw(ClawType which, double input) {
// if (which == Claws.ClawType.LEFT) {
// m_leftClaw.setSpeed(input);
2022-03-10 17:06:17 -07:00
2022-03-16 22:32:57 -06:00
// } else if (which == Claws.ClawType.RIGHT) {
// m_rightClaw.setSpeed(input);
// }
// }
2022-03-10 17:06:17 -07:00
2022-03-16 22:32:57 -06:00
// public void runClaws(double input)
// {
// m_leftClaw.setSpeed(input);
// m_rightClaw.setSpeed(input);
// }
2022-03-16 14:49:41 -06:00
2022-03-05 23:47:24 -07:00
/**
* Sets the state of both hooks
* @param open The state of the hooks
*/
2022-03-05 14:21:48 -07:00
public void setOpen(boolean open) {
2022-03-16 22:32:57 -06:00
SmartDashboard.putBoolean("open", open);
2022-03-05 14:21:48 -07:00
if(open) {
2022-03-05 14:38:54 -07:00
// m_leftClaw.getEncoder().setPosition(ClawsConstants.OPEN_POSITION + m_leftOffset);
// m_rightClaw.getEncoder().setPosition(ClawsConstants.OPEN_POSITION + m_rightOffset);
2022-03-16 22:32:57 -06:00
// m_leftClaw.setPosition(.7);
// m_rightClaw.setPosition(.7);
2022-03-18 10:45:08 -06:00
m_leftClaw.setRaw(ClawConstants.BOTTOM_LIMIT - 900);//ClawConstants.OPEN_POSITION);
m_rightClaw.setRaw(ClawConstants.TOP_LIMIT + 100);//ClawConstants.OPEN_POSITION);
2022-03-05 14:21:48 -07:00
} else {
2022-03-05 14:38:54 -07:00
// m_leftClaw.getEncoder().setPosition(ClawsConstants.CLOSE_POSITION + m_leftOffset);
// m_rightClaw.getEncoder().setPosition(ClawsConstants.CLOSE_POSITION + m_rightOffset);
2022-03-16 22:32:57 -06:00
// m_leftClaw.setPosition(.3);
// m_rightClaw.setPosition(.3);
2022-03-18 10:45:08 -06:00
m_leftClaw.setRaw(ClawConstants.TOP_LIMIT - 100);
m_rightClaw.setRaw(ClawConstants.BOTTOM_LIMIT - 700);
2022-03-05 14:21:48 -07:00
}
}
2022-03-16 22:32:57 -06:00
// public double[] getOffsets() {
// return new double[] {m_leftOffset, m_rightOffset};
// }
2022-03-05 14:38:54 -07:00
2022-03-16 22:32:57 -06:00
// public boolean fullyOpen() {
// return Math.abs(m_leftClaw.getPosition() - ClawConstants.OPEN_POSITION) < ClawConstants.THRESHOLD &&
// Math.abs(m_rightClaw.getPosition() - ClawConstants.OPEN_POSITION) < ClawConstants.THRESHOLD; }
2022-03-16 14:41:27 -06:00
2022-03-16 22:32:57 -06:00
// public boolean fullyClosed() {
// return Math.abs(m_leftClaw.getPosition() - ClawConstants.CLOSE_POSITION) < ClawConstants.THRESHOLD &&
// Math.abs(m_rightClaw.getPosition() - ClawConstants.CLOSE_POSITION) < ClawConstants.THRESHOLD;
// }
2022-03-05 14:21:48 -07:00
2022-03-05 14:38:54 -07:00
/**
* Check if a limit switch is pressed or current limit exceeded for a claw.
* @param which Which claw to check.
* @param limit The current limit.
* @return Whether to interrupt the RunClaw command or not.
*/
2022-03-16 14:49:41 -06:00
// public boolean checkSwitchAndCurrent(ClawType which) {
// if (which == ClawType.LEFT) {
// if (m_leftLimitSwitchF.isPressed() || m_leftLimitSwitchR.isPressed() || m_leftClaw.getOutputCurrent() >= ClawConstants.CURRENT_LIMIT) {
// return true;
// }
// }
// else if (which == ClawType.RIGHT) {
// if (m_rightLimitSwitchF.isPressed() || m_rightLimitSwitchR.isPressed() || m_rightClaw.getOutputCurrent() >= ClawConstants.CURRENT_LIMIT) {
// return true;
// }
// }
// return false;
// }
2022-03-05 14:38:54 -07:00
2022-03-16 22:32:57 -06:00
// @Override
2022-03-18 10:45:08 -06:00
public void periodic() {
2022-03-20 17:28:10 -06:00
// SmartDashboard.putNumber("Servo Left Pos", m_leftClaw.getRaw());
// SmartDashboard.putNumber("Servo Right Pos", m_rightClaw.getRaw());
2022-03-16 22:32:57 -06:00
// if (fullyOpen() || fullyClosed()) {
// m_leftClaw.setSpeed(0.0);
// m_rightClaw.setSpeed(0.0);
// }
2022-03-16 14:49:41 -06:00
// if(m_leftLimitSwitchF.isPressed() || m_leftLimitSwitchR.isPressed())
// // m_leftOffset = m_leftClaw.getEncoder().getPosition();
// m_leftOffset = m_leftClaw.getPosition();
2022-03-05 14:21:48 -07:00
2022-03-16 14:49:41 -06:00
// if(m_rightLimitSwitchF.isPressed() || m_rightLimitSwitchR.isPressed())
// // m_rightOffset = m_rightClaw.getEncoder().getPosition();
// m_rightOffset = m_rightClaw.getPosition();
2022-03-18 10:45:08 -06:00
}
2022-03-05 14:38:54 -07:00
}