-
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.
Merge branch 'intake' into pathplanner
# Conflicts: # .gitignore # build.gradle # src/main/java/frc/robot/BuildConstants.java # src/main/java/frc/robot/RobotContainer.java
- Loading branch information
Showing
14 changed files
with
464 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
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
9 changes: 9 additions & 0 deletions
9
src/main/java/frc/robot/subsystems/climber/ClimberConstants.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,9 @@ | ||
package frc.robot.subsystems.climber; | ||
|
||
public class ClimberConstants { | ||
public static final int CLIMBER_ID = 0; | ||
public static final double CLIMBER_KP = 0.0; | ||
public static final double CLIMBER_KI = 0.0; | ||
public static final double CLIMBER_KD = 0.0; | ||
public static final double CLIMBER_OFFSET = 0.0; | ||
} |
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.climber; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface ClimberIO { | ||
@AutoLog | ||
class ClimberIOInputs{ | ||
public double position = 0.0; | ||
public double currentDraw = 0.0; | ||
public double setpoint = 0.0; | ||
public double appliedOutput = 0.0; | ||
} | ||
default void setMotorVoltage(double voltage) {} | ||
default void setPosititon(double degrees) {} | ||
default void updateInputs(ClimberIOInputsAutoLogged inputs) {} | ||
default void stop() {} | ||
default void resetPosition() {} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/frc/robot/subsystems/climber/ClimberIOKraken.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,85 @@ | ||
package frc.robot.subsystems.climber; | ||
|
||
import com.ctre.phoenix6.BaseStatusSignal; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.Slot0Configs; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.controls.NeutralOut; | ||
import com.ctre.phoenix6.controls.PositionVoltage; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.InvertedValue; | ||
import com.ctre.phoenix6.signals.NeutralModeValue; | ||
import edu.wpi.first.units.measure.Angle; | ||
import edu.wpi.first.units.measure.Current; | ||
|
||
public class ClimberIOKraken implements ClimberIO{ | ||
private final TalonFX climber; | ||
private final PositionVoltage posRequest; | ||
private final StatusSignal<Angle> positionSignal; | ||
private final StatusSignal<Current> currentDrawSignal; | ||
private final StatusSignal<Double> setpointSignal; | ||
private final StatusSignal<Double> appliedOutputSignal; | ||
private final NeutralOut stopRequest; | ||
public ClimberIOKraken() { | ||
climber = new TalonFX(ClimberConstants.CLIMBER_ID); | ||
TalonFXConfiguration climberConfig = new TalonFXConfiguration(); | ||
climberConfig.MotorOutput.NeutralMode = NeutralModeValue.Brake; | ||
climberConfig.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive; | ||
climber.getConfigurator().apply(climberConfig); | ||
|
||
var climberConfigs = new Slot0Configs(); | ||
climberConfigs.kP = 2.4; | ||
climberConfigs.kI = 0; | ||
climberConfigs.kD = 0.1; | ||
climber.getConfigurator().apply(climberConfigs); | ||
final PositionVoltage climberRequest = new PositionVoltage(0).withSlot(0); | ||
climber.setControl(climberRequest.withPosition(10)); | ||
|
||
positionSignal = climber.getPosition(); | ||
currentDrawSignal = climber.getSupplyCurrent(); | ||
setpointSignal = climber.getClosedLoopReference(); | ||
appliedOutputSignal = climber.getDutyCycle(); | ||
|
||
posRequest = new PositionVoltage(0).withSlot(0) | ||
.withEnableFOC(climber.getIsProLicensed().getValue()); | ||
stopRequest = new NeutralOut(); | ||
|
||
BaseStatusSignal.setUpdateFrequencyForAll(50.0, | ||
positionSignal, | ||
currentDrawSignal, | ||
setpointSignal, | ||
appliedOutputSignal); | ||
|
||
climber.optimizeBusUtilization(); | ||
} | ||
@Override | ||
public void updateInputs(ClimberIOInputsAutoLogged inputs) { | ||
BaseStatusSignal.refreshAll( | ||
positionSignal, | ||
currentDrawSignal, | ||
setpointSignal, | ||
appliedOutputSignal | ||
); | ||
inputs.position = positionSignal.refresh().getValueAsDouble(); | ||
inputs.currentDraw = currentDrawSignal.refresh().getValueAsDouble(); | ||
inputs.setpoint = setpointSignal.refresh().getValueAsDouble(); | ||
inputs.appliedOutput = appliedOutputSignal.refresh().getValueAsDouble(); | ||
|
||
} | ||
@Override | ||
public void setMotorVoltage(double voltage) { | ||
climber.setVoltage(voltage); | ||
} | ||
@Override | ||
public void setPosititon(double degrees) { | ||
climber.setControl(posRequest.withPosition(degrees / 360)); | ||
} | ||
@Override | ||
public void resetPosition() { | ||
climber.setPosition(0); | ||
} | ||
@Override | ||
public void stop() { | ||
climber.setControl(stopRequest); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/frc/robot/subsystems/climber/ClimberSubsystem.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,44 @@ | ||
package frc.robot.subsystems.climber; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class ClimberSubsystem extends SubsystemBase { | ||
private final ClimberIO io; | ||
private final ClimberIOInputsAutoLogged inputs; | ||
private boolean climberLock = false; | ||
public ClimberSubsystem(ClimberIO io) { | ||
this.io = io; | ||
inputs = new ClimberIOInputsAutoLogged(); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Climber", inputs); | ||
} | ||
public void setClimberPower(double power) { | ||
io.setMotorVoltage(power); | ||
} | ||
public boolean getClimberLock() { | ||
return climberLock; | ||
} | ||
public Command resetClimberLock() { | ||
return runOnce(() -> climberLock = false).ignoringDisable(true); | ||
} | ||
public Command setClimberPowerFactory(double power) { | ||
climberLock = true; | ||
return run(() -> setClimberPower(power)); | ||
} | ||
public Command setClimberPosition(double degrees) { | ||
climberLock = true; | ||
return runEnd(() -> { | ||
io.setPosititon(degrees); | ||
}, | ||
() -> setClimberPower(0.0)); | ||
} | ||
public Command resetClimber() { | ||
return runOnce(io::resetPosition); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,4 @@ public void updateInputs(ModuleIOInputsAutoLogged inputs) { | |
|
||
} | ||
|
||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/frc/robot/subsystems/intake/IntakeConstants.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.intake; | ||
|
||
public class IntakeConstants { | ||
public static final int INTAKE_ID = 0; | ||
public static final int PIVOT_ID = 0; | ||
public static final double INTAKE_KP = 0.0; | ||
public static final double INTAKE_KI = 0.0; | ||
public static final double INTAKE_KD = 0.0; | ||
public static final double PIVOT_KP = 0.0; | ||
public static final double PIVOT_KI = 0.0; | ||
public static final double PIVOT_KD = 0.0; | ||
public static final double INTAKE_OFFSET = 0.0; | ||
public static final double PIVOT_OFFSET = 0.0; | ||
public static final double LOOP_PERIOD_SECS = 10.0; | ||
public static final double INTAKE_GEAR_RATIO = 10.0; | ||
public static final double PIVOT_GEAR_RATIO = 10.0; | ||
|
||
} |
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,24 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface IntakeIO { | ||
@AutoLog | ||
class IntakeIOInputs { | ||
//position, voltage, current draw, and any other important logging data | ||
public Rotation2d pivotPosititon = new Rotation2d(); | ||
public double pivotVoltage = 0.0; | ||
public double intakeVoltage = 0.0; | ||
public double pivotCurrentDraw = 0.0; | ||
public double intakeCurrentDraw = 0.0; | ||
public double pivotAppliedVolts = 0.0; | ||
public double intakeAppliedVolts = 0.0; | ||
public double pivotTemperature = 0.0; | ||
public double intakeTemperature = 0.0; | ||
} | ||
default void setMotorVoltageIntake(double voltage) {} | ||
default void setMotorVoltagePivot(double voltage) {} | ||
default void updateInputs(IntakeIOInputsAutoLogged inputs) {} | ||
default void stop() {} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/frc/robot/subsystems/intake/IntakeIOProto.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,29 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.NeutralModeValue; | ||
|
||
public class IntakeIOProto implements IntakeIO { | ||
private final TalonFX intake; | ||
|
||
public IntakeIOProto() { | ||
intake = new TalonFX(17); | ||
|
||
var config = new TalonFXConfiguration(); | ||
config.MotorOutput.NeutralMode = NeutralModeValue.Brake; | ||
|
||
intake.getConfigurator().apply(config); | ||
} | ||
|
||
@Override | ||
public void updateInputs(IntakeIOInputsAutoLogged inputs) { | ||
inputs.intakeAppliedVolts = intake.getMotorVoltage().getValueAsDouble(); | ||
inputs.intakeCurrentDraw = intake.getSupplyCurrent().getValueAsDouble(); | ||
} | ||
|
||
@Override | ||
public void setMotorVoltageIntake(double voltage) { | ||
intake.setVoltage(voltage); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/frc/robot/subsystems/intake/IntakeIOSimulation.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,48 @@ | ||
package frc.robot.subsystems.intake; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.sim.TalonFXSimState; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.math.system.plant.LinearSystemId; | ||
import edu.wpi.first.wpilibj.simulation.DCMotorSim; | ||
|
||
public class IntakeIOSimulation implements IntakeIO { | ||
private final TalonFX intake = new TalonFX(IntakeConstants.INTAKE_ID); | ||
private final TalonFX pivot = new TalonFX(IntakeConstants.PIVOT_ID); | ||
private final TalonFXSimState intakeSim = intake.getSimState(); | ||
private final TalonFXSimState pivotSim = pivot.getSimState(); | ||
private final DCMotorSim intakeMotorSim = new DCMotorSim( | ||
LinearSystemId.createDCMotorSystem( | ||
DCMotor.getKrakenX60Foc(1), 0.001, IntakeConstants.INTAKE_GEAR_RATIO | ||
), | ||
DCMotor.getKrakenX60Foc(1) | ||
); | ||
private final DCMotorSim pivotMotorSim = new DCMotorSim( | ||
LinearSystemId.createDCMotorSystem( | ||
DCMotor.getKrakenX60Foc(1), 0.001, IntakeConstants.PIVOT_GEAR_RATIO | ||
), | ||
DCMotor.getKrakenX60Foc(1) | ||
); | ||
|
||
@Override | ||
public void updateInputs(IntakeIOInputsAutoLogged inputs) { | ||
// update simulation | ||
intakeMotorSim.update(IntakeConstants.LOOP_PERIOD_SECS); | ||
pivotMotorSim.update(IntakeConstants.LOOP_PERIOD_SECS); | ||
|
||
// update inputs | ||
intakeSim.setSupplyVoltage(intake.getMotorVoltage().getValueAsDouble()); | ||
pivotSim.setSupplyVoltage(pivot.getMotorVoltage().getValueAsDouble()); | ||
intakeMotorSim.setInputVoltage(intakeSim.getMotorVoltage()); | ||
pivotMotorSim.setInputVoltage(pivotSim.getMotorVoltage()); | ||
|
||
//inputs.intakeVoltage = in | ||
inputs.pivotPosititon = Rotation2d.fromRadians(pivot.getPosition().refresh().getValueAsDouble()); | ||
inputs.intakeVoltage = intake.getMotorVoltage().refresh().getValueAsDouble(); | ||
inputs.pivotVoltage = pivot.getMotorVoltage().refresh().getValueAsDouble(); | ||
inputs.intakeCurrentDraw = intake.getSupplyCurrent().refresh().getValueAsDouble(); | ||
inputs.pivotCurrentDraw = pivot.getSupplyCurrent().refresh().getValueAsDouble(); | ||
inputs.intakeTemperature = intake.getDeviceTemp().refresh().getValueAsDouble(); | ||
inputs.pivotTemperature = pivot.getDeviceTemp().refresh().getValueAsDouble(); | ||
} | ||
} |
Oops, something went wrong.