-
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.
- Loading branch information
Showing
8 changed files
with
195 additions
and
6 deletions.
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/org/team1540/robot2024/commands/TrampCommand.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,33 @@ | ||
package org.team1540.robot2024.commands; | ||
|
||
import org.team1540.robot2024.subsystems.tramp.Tramp; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class TrampCommand extends Command { | ||
|
||
private final Tramp tramp; | ||
|
||
public TrampCommand(Tramp tramp) { | ||
this.tramp = tramp; | ||
addRequirements(tramp); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
tramp.setPercent(0.5); | ||
} | ||
|
||
@Override | ||
public void execute() {} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return tramp.isBeamBreakBlocked(); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
tramp.stopTramp(); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/org/team1540/robot2024/subsystems/tramp/Tramp.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,33 @@ | ||
package org.team1540.robot2024.subsystems.tramp; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Tramp extends SubsystemBase { | ||
private final TrampIO io; | ||
private final TrampIOInputsAutoLogged inputs = new TrampIOInputsAutoLogged(); | ||
|
||
public Tramp(TrampIO io) { | ||
this.io = io; | ||
} | ||
|
||
public void setPercent(double percentage) { | ||
io.setVoltage(12.0 * percentage); | ||
} | ||
|
||
public boolean isBeamBreakBlocked() { | ||
return inputs.breamBreakTripped; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Tramp", inputs); | ||
} | ||
|
||
public void stopTramp() { | ||
io.setVoltage(0); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/team1540/robot2024/subsystems/tramp/TrampIO.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,16 @@ | ||
package org.team1540.robot2024.subsystems.tramp; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
|
||
public interface TrampIO { | ||
@AutoLog | ||
class TrampIOInputs { | ||
public boolean breamBreakTripped = false; | ||
public double velocityRPM = 0.0; | ||
public double appliedVolts = 0.0; | ||
public double currentAmps = 0.0; | ||
} | ||
default void setVoltage(double volts) {} | ||
default void updateInputs(TrampIOInputs inputs) {} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/team1540/robot2024/subsystems/tramp/TrampIOSim.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,27 @@ | ||
package org.team1540.robot2024.subsystems.tramp; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.DCMotorSim; | ||
import org.team1540.robot2024.Constants; | ||
|
||
import static org.team1540.robot2024.Constants.Tramp.GEAR_RATIO; | ||
|
||
public class TrampIOSim implements TrampIO{ | ||
private final DCMotorSim sim = new DCMotorSim(DCMotor.getNEO(1), GEAR_RATIO,0.025); //TODO: Fix MOI its probably wrong :D | ||
|
||
private double appliedVolts = 0.0; | ||
@Override | ||
public void updateInputs(TrampIOInputs inputs) { | ||
sim.update(Constants.LOOP_PERIOD_SECS); | ||
inputs.velocityRPM = sim.getAngularVelocityRPM(); | ||
inputs.appliedVolts = appliedVolts; | ||
inputs.currentAmps = sim.getCurrentDrawAmps(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
appliedVolts = MathUtil.clamp(volts, -12, 12); | ||
sim.setInputVoltage(appliedVolts); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/team1540/robot2024/subsystems/tramp/TrampIOSparkMax.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,31 @@ | ||
package org.team1540.robot2024.subsystems.tramp; | ||
|
||
import com.revrobotics.CANSparkLowLevel.MotorType; | ||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.RelativeEncoder; | ||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import org.team1540.robot2024.Constants.Tramp; | ||
|
||
public class TrampIOSparkMax implements TrampIO { | ||
private final DigitalInput beamBreak = new DigitalInput(0); | ||
//TODO: Potentially change name :D | ||
private final CANSparkMax motor = new CANSparkMax(Tramp.TRAMP_MOTOR_ID, MotorType.kBrushless); | ||
private final RelativeEncoder motorEncoder = motor.getEncoder(); | ||
public TrampIOSparkMax() { | ||
motor.setIdleMode(CANSparkMax.IdleMode.kBrake); | ||
//Potentially invert motor | ||
motor.setSmartCurrentLimit(40); | ||
motor.enableVoltageCompensation(12); | ||
} | ||
@Override | ||
public void setVoltage(double volts) { | ||
motor.setVoltage(volts); | ||
} | ||
|
||
public void updateInputs(TrampIOInputs inputs) { | ||
inputs.breamBreakTripped = !(beamBreak.get()); //I think returns false when broken... Returns true when broken now. | ||
inputs.velocityRPM = motorEncoder.getVelocity(); | ||
inputs.appliedVolts = motor.getAppliedOutput() * motor.getBusVoltage(); | ||
inputs.currentAmps = motor.getOutputCurrent(); | ||
} | ||
} |