-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coral Roller Bar, untested with weird autolog issue. Written by Kayla
- Loading branch information
Showing
6 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/frc/robot/subsystems/coralrollerbar/CoralRoller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/frc/robot/subsystems/coralrollerbar/CoralRollerConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/frc/robot/subsystems/coralrollerbar/CoralRollerIO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/frc/robot/subsystems/coralrollerbar/CoralRollerIOReal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/frc/robot/subsystems/coralrollerbar/CoralRollerIOSim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |