-
Notifications
You must be signed in to change notification settings - Fork 0
pivotpivotpivot #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
87e875d
765ae15
d32411d
1e60f4d
8457061
46b2e0c
55bf3d8
81f2cac
c869866
3ad38bf
6c87ebc
2511c97
31e8a8b
66cc170
a70afa4
a4000ff
823fc9f
19207a8
0d39398
646721e
13e4a08
d429052
2e93b16
7e0556f
c8b24d9
4017dc5
7d4886a
fdea006
d477e5f
fe83b74
9ade4f9
6dc7af6
6007363
aa6f386
2a4aa3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package frc.robot.subsystems.pivot; | ||
|
|
||
| import com.ctre.phoenix6.configs.CANcoderConfiguration; | ||
| import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
| import com.ctre.phoenix6.configs.Slot0Configs; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.signals.GravityTypeValue; | ||
| import com.ctre.phoenix6.signals.SensorDirectionValue; | ||
|
|
||
| public class PivotConfigs { | ||
| public static final int pivotMotorID = 1; | ||
| public static final int pivotCANcoderID = 2; | ||
| // values may change as tuning progresses | ||
| public static final CANcoderConfiguration canCoderConfig = | ||
| new CANcoderConfiguration() | ||
| .withMagnetSensor( | ||
| new com.ctre.phoenix6.configs.MagnetSensorConfigs() | ||
| .withSensorDirection( | ||
| SensorDirectionValue.CounterClockwise_Positive) | ||
| .withMagnetOffset(0.0)); | ||
| public static TalonFXConfiguration motorConfig = | ||
| new TalonFXConfiguration() | ||
| .withSlot0( | ||
| new Slot0Configs() | ||
| .withGravityType(GravityTypeValue.Arm_Cosine) | ||
| .withKD(0.0) | ||
| .withKP(0.0) | ||
| .withKI(0.0) | ||
| .withKG(0.0) | ||
| .withKS(0.0) | ||
| .withKV(0.0)) | ||
| .withCurrentLimits( | ||
| new CurrentLimitsConfigs() | ||
| .withStatorCurrentLimit(0.0) | ||
| .withSupplyCurrentLimit(0.0) | ||
| .withStatorCurrentLimitEnable(true) | ||
| .withSupplyCurrentLimitEnable(true)); | ||
| } | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package frc.robot.subsystems.pivot; | ||
|
|
||
| import org.littletonrobotics.junction.AutoLog; | ||
|
|
||
| public interface PivotIO { | ||
| @AutoLog | ||
| class PivotIOinput { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix casing |
||
| public double pos = 0.0; | ||
| public double velocity = 0.0; | ||
| } | ||
|
|
||
| public default void updateInputs(PivotIOinput inputs) {} | ||
|
|
||
| public default void setPosition(double position) {} | ||
|
|
||
| public default void applyPower(double power) {} | ||
|
|
||
| public default void stop() {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package frc.robot.subsystems.pivot; | ||
|
|
||
| import edu.wpi.first.units.Units; | ||
|
|
||
| public enum PivotPos { | ||
| PivotDown(0.0), | ||
| PivotUp(0.0); | ||
|
|
||
| public final double position; | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| PivotPos(double rotation) { | ||
| this.position = Units.Rotations.of(rotation).magnitude(); | ||
| } | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package frc.robot.subsystems.pivot; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import org.littletonrobotics.junction.Logger; | ||
|
|
||
| public class PivotSubsystem extends SubsystemBase { | ||
| private final PivotIO io; | ||
| private final PivotIOinputAutoLogged inputs = new PivotIOinputAutoLogged(); | ||
|
|
||
| public PivotSubsystem(PivotIO io) { | ||
| this.io = io; | ||
| } | ||
|
|
||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| public void periodic() { | ||
| io.updateInputs(inputs); | ||
| Logger.processInputs("Pivot", inputs); | ||
| } | ||
|
|
||
| public void setPosition(PivotPos pivotPos) { | ||
| io.setPosition(pivotPos.position); | ||
| } | ||
|
|
||
| public Command stopCommand() { | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return runOnce(io::stop); | ||
| } | ||
|
|
||
| public Command setPositionCommand(PivotPos pivotPos) { | ||
| return run(() -> setPosition(pivotPos)).finallyDo(io::stop); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be |
||
| } | ||
|
|
||
| public Command applyPowerCommand(double power) { | ||
| return run(() -> io.applyPower(power)).finallyDo(io::stop); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing. You only need to send a control request once. Either |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package frc.robot.subsystems.pivot; | ||
|
|
||
| import com.ctre.phoenix6.configs.*; | ||
| import com.ctre.phoenix6.controls.DutyCycleOut; | ||
| import com.ctre.phoenix6.controls.MotionMagicTorqueCurrentFOC; | ||
| import com.ctre.phoenix6.hardware.CANcoder; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import edu.wpi.first.wpilibj.RobotBase; | ||
| import frc.robot.util.PhysicsSim; | ||
|
|
||
| public class PivotTalonFX implements PivotIO { | ||
| private final MotionMagicTorqueCurrentFOC motionMagicReq = new MotionMagicTorqueCurrentFOC(0); | ||
| private final TalonFX pivotMotor; | ||
| private final CANcoder pivotCan; | ||
|
|
||
| public PivotTalonFX() { | ||
|
|
||
| this.pivotMotor = new TalonFX(PivotConfigs.pivotMotorID); | ||
| this.pivotCan = new CANcoder(PivotConfigs.pivotCANcoderID); | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.pivotMotor.getConfigurator().apply(PivotConfigs.motorConfig); | ||
| this.pivotCan.getConfigurator().apply(PivotConfigs.canCoderConfig); | ||
| if (RobotBase.isSimulation()) { | ||
| PhysicsSim.getInstance().addTalonFX(pivotMotor, pivotCan); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void updateInputs(PivotIOinput inputs) { | ||
| inputs.pos = (double) pivotCan.getAbsolutePosition().getValueAsDouble(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary type casts |
||
| inputs.velocity = (double) pivotMotor.getVelocity().getValueAsDouble(); | ||
gowri-k2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public void setPosition(double positionRad) { | ||
| pivotMotor.setControl(motionMagicReq.withPosition(positionRad)); | ||
| } | ||
|
|
||
| @Override | ||
| public void applyPower(double power) { | ||
| pivotMotor.setControl(new DutyCycleOut(power)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a single instance of |
||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| pivotMotor.stopMotor(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.