Skip to content

Commit

Permalink
Coral Roller Bar, untested with weird autolog issue. Written by Kayla
Browse files Browse the repository at this point in the history
  • Loading branch information
Pouman1 committed Jan 25, 2025
1 parent ccf01aa commit 7f02be9
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
},
"[java]": {
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
}
},
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
}
50 changes: 50 additions & 0 deletions src/main/java/frc/robot/subsystems/coralrollerbar/CoralRoller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package frc.robot.subsystems.coralrollerbar;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import org.littletonrobotics.junction.Logger;

public class CoralRoller extends SubsystemBase {
private final CoralRollerIO io;
private final CoralRollerIOInputsAutoLogged inputs = new CoralRollerIOInputsAutoLogged();

private double velocity = 0;
private static CoralRoller instance;

public static CoralRoller getInstance() {
return instance;
}

public static CoralRoller init(CoralRollerIO io) {
if (instance == null) {
instance = new CoralRoller(io);
}
return instance;
}

private CoralRoller(CoralRollerIO io) {
this.io = io;
io.updateInputs(inputs);
}

public void setVelocity(double v) {
this.velocity = v;
}

public double getVelocity() {
return inputs.velocityRPM;
}

public double getCurrent() {
return inputs.current;
}

public double getVoltage() {
return inputs.voltage;
}

@Override
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("CoralRoller", inputs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package frc.robot.subsystems.coralrollerbar;

public final class CoralRollerConstants {
public static final int currentLimit = 30;
public static final double CanID = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package frc.robot.subsystems.coralrollerbar;

import org.littletonrobotics.junction.AutoLog;

public interface CoralRollerIO {
@AutoLog
public static class CoralRollerIOInputs {
public double current = 0;
public double voltage = 0;
public double velocityRPM = 0;
}

public default void updateInputs(CoralRollerIOInputs inputs) {}

public default void setDesiredState(double speed) {}

public default void setCoralRollerVoltage(double volts) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package frc.robot.subsystems.coralrollerbar;

import com.revrobotics.spark.SparkLowLevel.MotorType;
import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.config.SparkMaxConfig;

public class CoralRollerIOReal implements CoralRollerIO {
private final SparkMax CoralRollerMotor = new SparkMax(0, MotorType.kBrushless);

public CoralRollerIOReal() {
SparkMaxConfig coralRollerConfig = new SparkMaxConfig();
coralRollerConfig.smartCurrentLimit(CoralRollerConstants.currentLimit);
coralRollerConfig.voltageCompensation(12);
}

@Override
public void setCoralRollerVoltage(double volts) {
CoralRollerMotor.setVoltage(volts);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package frc.robot.subsystems.coralrollerbar;

import edu.wpi.first.wpilibj.simulation.DCMotorSim;

public class CoralRollerIOSim implements CoralRollerIO {
DCMotorSim motor = new DCMotorSim(null, null, null);
private double appliedVolts = 0;

@Override
public void setCoralRollerVoltage(double volts) {
appliedVolts = volts;
motor.setInputVoltage(appliedVolts);
}

@Override
public void updateInputs(CoralRollerIOInputs inputs) {
inputs.velocityRPM = motor.getAngularVelocityRPM();
inputs.voltage = appliedVolts;
inputs.current = motor.getCurrentDrawAmps();
}
}

0 comments on commit 7f02be9

Please sign in to comment.