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

Commit

Permalink
refactor(intake): Use velocity controller for intake rollers.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenheroux committed Apr 8, 2024
1 parent c6b7b87 commit 503f188
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 13 deletions.
21 changes: 21 additions & 0 deletions src/main/java/frc/lib/controller/VelocityControllerIOSim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package frc.lib.controller;

/** Simulated velocity controller. */
public class VelocityControllerIOSim implements VelocityControllerIO {

private double velocityRotationsPerSecond = 0.0;

@Override
public void configure(VelocityControllerIOConstants constants) {}

@Override
public void update(VelocityControllerIOValues values) {
values.velocityRotationsPerSecond = velocityRotationsPerSecond;
}

@Override
public void setSetpoint(double velocityRotationsPerSecond) {
this.velocityRotationsPerSecond = velocityRotationsPerSecond;
}

}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/intake/Intake.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void addToShuffleboard(ShuffleboardTab tab) {
}

public void initializeRollerShuffleboard(ShuffleboardTab tab, String name, VelocityControllerIOValues values) {
ShuffleboardLayout roller = Telemetry.addColumn(tab, "Front Roller");
ShuffleboardLayout roller = Telemetry.addColumn(tab, name);

roller.addDouble("Velocity (rps)", () -> values.velocityRotationsPerSecond);
roller.addDouble("Voltage (V)", () -> values.motorVolts);
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/frc/robot/intake/IntakeConstants.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
package frc.robot.intake;

import frc.lib.CAN;
import frc.lib.PIDFConstants;

/** Constants for the intake subsystem. */
public class IntakeConstants {
/** Constants for the front roller. */
public static class FrontRollerConstants {
/** Front roller's CAN. */
public static final CAN CAN = new CAN(50);

/** Front roller's PIDF constants. */
public static final PIDFConstants PIDF = new PIDFConstants();
static {
PIDF.kS = 0.13;
PIDF.kV = 0.1683;
}
}

/** Constants for the back roller. */
public static class BackRollerConstants {
/** Back roller's CAN. */
public static final CAN CAN = new CAN(50);

/** Back roller's PIDF constants. */
public static final PIDFConstants PIDF = new PIDFConstants();
static {
PIDF.kS = 0.13;
PIDF.kV = 0.1759;
}
}

/** Constants for the roller motor. */
public static class RollerConstants {
/** Velocity to apply when intaking in rotations per second. */
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/frc/robot/intake/IntakeFactory.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package frc.robot.intake;

import frc.lib.CAN;
import frc.lib.PIDFConstants;
import frc.lib.controller.VelocityControllerIO;
import frc.lib.controller.VelocityControllerIOSim;
import frc.lib.controller.VelocityControllerIOTalonFXPIDF;
import frc.robot.Robot;
import frc.robot.RobotConstants;
import frc.robot.RobotConstants.Subsystem;
import frc.robot.intake.IntakeConstants.BackRollerConstants;
import frc.robot.intake.IntakeConstants.FrontRollerConstants;

/** Helper class for creating hardware for the intake subsystem. */
public class IntakeFactory {

public static VelocityControllerIO createFrontRoller() {
PIDFConstants pidf = new PIDFConstants();
if (Robot.isReal() && RobotConstants.REAL_SUBSYSTEMS.contains(Subsystem.INTAKE)) {
return new VelocityControllerIOTalonFXPIDF(FrontRollerConstants.CAN, FrontRollerConstants.PIDF);
}

pidf.kS = 0.13;
pidf.kV = 0.1683;

return new VelocityControllerIOTalonFXPIDF(new CAN(50), pidf);
return new VelocityControllerIOSim();
}

public static VelocityControllerIO createBackRoller() {
PIDFConstants pidf = new PIDFConstants();

pidf.kS = 0.13;
pidf.kV = 0.1759;
if (Robot.isReal() && RobotConstants.REAL_SUBSYSTEMS.contains(Subsystem.INTAKE)) {
return new VelocityControllerIOTalonFXPIDF(BackRollerConstants.CAN, BackRollerConstants.PIDF);
}

return new VelocityControllerIOTalonFXPIDF(new CAN(40), pidf);
return new VelocityControllerIOSim();
}
}

0 comments on commit 503f188

Please sign in to comment.