Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjcoderman committed Aug 26, 2023
2 parents a443146 + ac4722b commit f0dff8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/frc/robot/intake/IntakeSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
package frc.robot.intake;

import com.revrobotics.*;

import edu.wpi.first.math.filter.LinearFilter;
import frc.robot.util.scheduling.LifecycleSubsystem;
import frc.robot.util.scheduling.SubsystemPriority;
import org.littletonrobotics.junction.Logger;

/** Add your docs here. */
public class IntakeSubsystem extends LifecycleSubsystem {
private CANSparkMax motor;
private final LinearFilter voltageFilter = LinearFilter.movingAverage(7);
private final LinearFilter velocityFilter = LinearFilter.movingAverage(7);
//7 is a placeholder not tuned
private final CANSparkMax motor;
private final RelativeEncoder encoder;
private IntakeState goalState;
private HeldGamePiece gamePiece = HeldGamePiece.NOTHING;

public IntakeSubsystem(CANSparkMax motor) {
super(SubsystemPriority.INTAKE);
this.motor = motor;
encoder = motor.getEncoder();
}

public void setGoalState(IntakeState intakeState) {
Expand All @@ -42,26 +49,34 @@ public void robotPeriodic() {
public void enabledPeriodic() {
if (goalState == IntakeState.OUTTAKE_CONE) {
motor.set(0.4);
// gamePiece = HeldGamePiece.NOTHING;
} else if (goalState == IntakeState.OUTTAKE_CUBE) {
motor.set(-0.3);
// gamePiece = HeldGamePiece.NOTHING;
} else if (gamePiece == HeldGamePiece.CUBE) {
motor.set(0.15);
} else if (gamePiece == HeldGamePiece.CONE) {
motor.set(-0.1);
} else if (goalState == IntakeState.INTAKE_CUBE) {
motor.set(0.5);
// gamePiece = HeldGamePiece.CUBE;
} else if (goalState == IntakeState.INTAKE_CONE) {
motor.set(-1);
// gamePiece = HeldGamePiece.CONE;
} else {
motor.disable();
}

// Game piece detection
double motorVelocity = velocityFilter.calculate(encoder.getVelocity());
double intakeVoltage = voltageFilter.calculate(motor.getAppliedOutput()) * 12.0;
double theoreticalSpeed = intakeVoltage * (5700.0/12.0); //Neo Max is 5700
double threshold = theoreticalSpeed * 0.5;
if (motorVelocity < threshold && goalState == IntakeState.INTAKE_CONE) {
gamePiece = HeldGamePiece.CONE;
} else if (motorVelocity < threshold && goalState == IntakeState.INTAKE_CUBE) {
gamePiece = HeldGamePiece.CUBE;
} else if (motorVelocity > threshold && (goalState == IntakeState.OUTTAKE_CONE || goalState == IntakeState.OUTTAKE_CUBE)) {
gamePiece = HeldGamePiece.NOTHING;
}
}

// create an atGoal(IntakeMode mode) method
public boolean atGoal(IntakeState state) {
if (goalState != state) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/shoulder/ShoulderSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public ShoulderSubsystem(CANSparkMax motor, CANSparkMax motorFollower) {
motorFollower.follow(motor);
encoder = motor.getEncoder();
pid = motor.getPIDController();
motor.setSmartCurrentLimit(35);
motorFollower.setSmartCurrentLimit(35);

pid.setP(5);
pid.setI(0);
Expand Down

0 comments on commit f0dff8d

Please sign in to comment.