Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intake subsystem #50

Merged
merged 11 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
sub sandwich or sub marine or sub par or sub lime
  • Loading branch information
Fyrefyte committed Mar 30, 2024
commit 1e0224d9e911d5d8b24b68f35c9c131bf5aa29fa
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,10 @@ public static final class LimelightConstants {
public static final double kCamHeight = 0; // Height of the limelight from the ground
public static final double kCamAngle = 0; // Pitch angle of direction the limelight is pointed in
}

public static final class IntakeConstants {
public static final int kFlippyCanId = 1;
public static final int kGroundIntakeCanId = 2;
public static final int kIntakeMaxCurrent = 10;
}
}
66 changes: 66 additions & 0 deletions src/main/java/frc/robot/subsystems/IntakeSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package frc.robot.subsystems;

import com.revrobotics.CANSparkBase.IdleMode;
import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.SparkRelativeEncoder.Type;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.IntakeConstants;

public class IntakeSubsystem extends SubsystemBase {

public final CANSparkMax m_flippyMotor;
public final CANSparkMax m_intakeMotor;
public final RelativeEncoder m_flippyEncoder;

public IntakeSubsystem() {

//Intake mechanism motors
m_flippyMotor = new CANSparkMax(IntakeConstants.kFlippyCanId, MotorType.kBrushless);
m_intakeMotor = new CANSparkMax(IntakeConstants.kGroundIntakeCanId, MotorType.kBrushed);
m_flippyEncoder = m_flippyMotor.getEncoder(Type.kHallSensor, 42);

m_flippyMotor.setIdleMode(IdleMode.kBrake);
m_intakeMotor.setIdleMode(IdleMode.kCoast);
}

//Intake
public void intake(double power) {m_intakeMotor.set(power);}
public void stopIntake() {m_intakeMotor.stopMotor();}
public void intakeCurrentSensitive(double power) {
if (m_intakeMotor.getOutputCurrent() < IntakeConstants.kIntakeMaxCurrent) intake(power);
else stopIntake();
}

//Flipper
public void flip(double power) {m_flippyMotor.set(power);}
public void stopFlipper() {m_flippyMotor.stopMotor();}
public void flipToPosition(double pos) {
// Moves to the goal encoder angle
flip(MathUtil.clamp(pos - m_flippyEncoder.getPosition(), -1, 1));
}

//Combo
public void intakeFromGround() {
if (m_flippyEncoder.getPosition() < 1 /* To be changed */) {
flip(.5);
}
else {
intake(1);
}
}
public void retractIntake() {
flip(-.5);
}
public void expelRing() {
intake(-1);
}
public void feedShooter() {
retractIntake();
expelRing();
}

}