-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ShooterFinish
- Loading branch information
Showing
14 changed files
with
447 additions
and
255 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
102 changes: 100 additions & 2 deletions
102
src/main/java/frc/robot/subsystems/climber/ClimberIO.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 |
---|---|---|
@@ -1,7 +1,105 @@ | ||
package frc.robot.subsystems.climber; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface ClimberIO { | ||
@AutoLog | ||
class ClimberIOInputs { | ||
protected double leftClimberPosition = 0.0; | ||
protected double rightClimberPosition = 0.0; | ||
protected double leftClimberVelocity = 0.0; | ||
protected double rightClimberVelocity = 0.0; | ||
protected double leftClimberCurrentDraw = 0.0; | ||
protected double rightClimberCurrentDraw = 0.0; | ||
protected double leftClimberCurrentSetpoint = 0.0; | ||
protected double rightClimberCurrentSetpoint = 0.0; | ||
protected double leftClimberAppliedOutput = 0.0; | ||
protected double rightClimberAppliedOutput = 0.0; | ||
|
||
public double getLeftClimberPosition() { | ||
return leftClimberPosition; | ||
} | ||
|
||
public void setLeftClimberPosition(double leftClimberPosition) { | ||
this.leftClimberPosition = leftClimberPosition; | ||
} | ||
|
||
public double getRightClimberPosition() { | ||
return rightClimberPosition; | ||
} | ||
|
||
public void setRightClimberPosition(double rightClimberPosition) { | ||
this.rightClimberPosition = rightClimberPosition; | ||
} | ||
|
||
public double getLeftClimberVelocity() { | ||
return leftClimberVelocity; | ||
} | ||
|
||
public void setLeftClimberVelocity(double leftClimberVelocity) { | ||
this.leftClimberVelocity = leftClimberVelocity; | ||
} | ||
|
||
public double getRightClimberVelocity() { | ||
return rightClimberVelocity; | ||
} | ||
|
||
public void setRightClimberVelocity(double rightClimberVelocity) { | ||
this.rightClimberVelocity = rightClimberVelocity; | ||
} | ||
|
||
public double getLeftClimberCurrentDraw() { | ||
return leftClimberCurrentDraw; | ||
} | ||
|
||
public void setLeftClimberCurrentDraw(double leftClimberCurrentDraw) { | ||
this.leftClimberCurrentDraw = leftClimberCurrentDraw; | ||
} | ||
|
||
public double getRightClimberCurrentDraw() { | ||
return rightClimberCurrentDraw; | ||
} | ||
|
||
public void setRightClimberCurrentDraw(double rightClimberCurrentDraw) { | ||
this.rightClimberCurrentDraw = rightClimberCurrentDraw; | ||
} | ||
|
||
public double getLeftClimberCurrentSetpoint() { | ||
return leftClimberCurrentSetpoint; | ||
} | ||
|
||
public void setLeftClimberCurrentSetpoint(double leftClimberCurrentSetpoint) { | ||
this.leftClimberCurrentSetpoint = leftClimberCurrentSetpoint; | ||
} | ||
|
||
public double getRightClimberCurrentSetpoint() { | ||
return rightClimberCurrentSetpoint; | ||
} | ||
|
||
public void setRightClimberCurrentSetpoint(double rightClimberCurrentSetpoint) { | ||
this.rightClimberCurrentSetpoint = rightClimberCurrentSetpoint; | ||
} | ||
|
||
public double getLeftClimberAppliedOutput() { | ||
return leftClimberAppliedOutput; | ||
} | ||
|
||
public void setLeftClimberAppliedOutput(double leftClimberAppliedOutput) { | ||
this.leftClimberAppliedOutput = leftClimberAppliedOutput; | ||
} | ||
|
||
public double getRightClimberAppliedOutput() { | ||
return rightClimberAppliedOutput; | ||
} | ||
|
||
public void setRightClimberAppliedOutput(double rightClimberAppliedOutput) { | ||
this.rightClimberAppliedOutput = rightClimberAppliedOutput; | ||
} | ||
} | ||
|
||
default void setLeftVoltage(double voltage) {} | ||
default void setRightVoltage(double voltage) {} | ||
default void setRightVoltage(double volts) {} | ||
default void setLeftVoltage(double volts) {} | ||
default void setRightPosition(double degrees) {} | ||
default void setLeftPosition(double degrees) {} | ||
default void updateInputs(ClimberIOInputsAutoLogged inputs) {} | ||
} |
108 changes: 80 additions & 28 deletions
108
src/main/java/frc/robot/subsystems/climber/ClimberIOPrototype.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 |
---|---|---|
@@ -1,36 +1,88 @@ | ||
package frc.robot.subsystems.climber; | ||
|
||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.controls.VoltageOut; | ||
import com.ctre.phoenix6.controls.PositionVoltage; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.InvertedValue; | ||
import edu.wpi.first.math.MathUtil; | ||
import frc.robot.Constants.ClimberConstants; | ||
import lib.properties.phoenix6.Phoenix6PidPropertyBuilder; | ||
import lib.properties.phoenix6.PidPropertyPublic; | ||
|
||
public class ClimberIOPrototype implements ClimberIO { | ||
private final TalonFX m_leftTalon; | ||
private final TalonFX m_rightTalon; | ||
|
||
public ClimberIOPrototype() { | ||
m_leftTalon = new TalonFX(18); | ||
m_rightTalon = new TalonFX(19); | ||
|
||
var rightTalonConfig = new TalonFXConfiguration(); | ||
rightTalonConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
m_rightTalon.getConfigurator().apply(rightTalonConfig); | ||
|
||
var leftTalonConfig = new TalonFXConfiguration(); | ||
m_leftTalon.getConfigurator().apply(leftTalonConfig); | ||
} | ||
|
||
@Override | ||
public void setRightVoltage(double voltage) { | ||
double clampedVoltage = MathUtil.clamp(voltage, -12, 12); | ||
m_rightTalon.setVoltage(clampedVoltage); | ||
} | ||
|
||
@Override | ||
public void setLeftVoltage(double voltage) { | ||
double clampedVoltage = MathUtil.clamp(voltage, -12, 12); | ||
m_leftTalon.setVoltage(clampedVoltage); | ||
} | ||
private final TalonFX m_leftTalon; | ||
private final TalonFX m_rightTalon; | ||
private final PidPropertyPublic m_leftClimberPid; | ||
private final PidPropertyPublic m_rightClimberPid; | ||
|
||
public ClimberIOPrototype() { | ||
m_leftTalon = new TalonFX(ClimberConstants.LEFT_CLIMBER_ID); | ||
m_rightTalon = new TalonFX(ClimberConstants.RIGHT_CLIMBER_ID); | ||
|
||
var rightTalonConfig = new TalonFXConfiguration(); | ||
rightTalonConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
m_rightTalon.getConfigurator().apply(rightTalonConfig); | ||
|
||
var leftTalonConfig = new TalonFXConfiguration(); | ||
m_leftTalon.getConfigurator().apply(leftTalonConfig); | ||
|
||
m_leftClimberPid = new Phoenix6PidPropertyBuilder( | ||
"Climber/Left PID", | ||
false, m_leftTalon, 0) | ||
.addP(ClimberConstants.CLIMBER_KP) | ||
.addI(ClimberConstants.CLIMBER_KI) | ||
.addD(ClimberConstants.CLIMBER_KD) | ||
.build(); | ||
|
||
m_rightClimberPid = new Phoenix6PidPropertyBuilder( | ||
"Climber/Right PID", | ||
false, m_rightTalon, 0) | ||
.addP(ClimberConstants.CLIMBER_KP) | ||
.addI(ClimberConstants.CLIMBER_KI) | ||
.addD(ClimberConstants.CLIMBER_KD) | ||
.build(); | ||
|
||
} | ||
|
||
@Override | ||
public void setLeftVoltage(double volts) { | ||
m_leftTalon.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void setRightVoltage(double volts) { | ||
m_rightTalon.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void setLeftPosition(double degrees) { | ||
final PositionVoltage request = new PositionVoltage(0).withSlot(0); | ||
m_leftTalon.setControl(request.withPosition(degrees / 360.0)); | ||
} | ||
|
||
@Override | ||
public void setRightPosition(double degrees) { | ||
final PositionVoltage request = new PositionVoltage(0).withSlot(0); | ||
m_rightTalon.setControl(request.withPosition(degrees / 360.0)); | ||
} | ||
|
||
@Override | ||
public void updateInputs(ClimberIOInputsAutoLogged inputs) { | ||
m_leftClimberPid.updateIfChanged(); | ||
m_rightClimberPid.updateIfChanged(); | ||
|
||
inputs.setLeftClimberPosition(m_leftTalon.getPosition().getValueAsDouble()); | ||
inputs.setRightClimberPosition(m_rightTalon.getPosition().getValueAsDouble()); | ||
|
||
inputs.setLeftClimberVelocity(m_leftTalon.getVelocity().getValueAsDouble()); | ||
inputs.setRightClimberVelocity(m_rightTalon.getVelocity().getValueAsDouble()); | ||
|
||
inputs.setLeftClimberCurrentDraw(m_leftTalon.getSupplyCurrent().getValueAsDouble()); | ||
inputs.setRightClimberCurrentDraw(m_rightTalon.getSupplyCurrent().getValueAsDouble()); | ||
|
||
inputs.setLeftClimberCurrentSetpoint(m_leftTalon.getClosedLoopReference().getValueAsDouble()); | ||
inputs.setRightClimberCurrentSetpoint(m_rightTalon.getClosedLoopReference().getValueAsDouble()); | ||
|
||
inputs.setLeftClimberAppliedOutput(m_leftTalon.getBridgeOutput().getValueAsDouble()); | ||
inputs.setRightClimberAppliedOutput(m_rightTalon.getBridgeOutput().getValueAsDouble()); | ||
} | ||
} |
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
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
Oops, something went wrong.