-
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.
The Bad Pivot Code I forgot to Commit
- Loading branch information
1 parent
97cfb9e
commit 3e27841
Showing
5 changed files
with
190 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package frc.robot.subsystems.pivot; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.subsystems.pivot.PivotIO; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
import edu.wpi.first.math.controller.SimpleMotorFeedforward; | ||
import frc.robot.Constants; | ||
|
||
public class Pivot extends SubsystemBase { | ||
|
||
private static Pivot pivotInstance = null; | ||
public final PivotIO io; | ||
private final SimpleMotorFeedforward ffModel; | ||
private final PivotIOInputsAutoLogged inputs = new PivotIOInputsAutoLogged(); | ||
|
||
private Pivot(PivotIO io) { | ||
|
||
this.io = io; | ||
|
||
switch (Constants.currentMode) { | ||
case REAL: | ||
case REPLAY: | ||
ffModel = new SimpleMotorFeedforward(0.0, 0.0); | ||
io.configurePID(1.0, 0.0, 0.0); | ||
break; | ||
case SIM: | ||
ffModel = new SimpleMotorFeedforward(0.0, 0.0); | ||
io.configurePID(1.0, 0.0, 0.0); | ||
break; | ||
default: | ||
ffModel = new SimpleMotorFeedforward(0.0, 0.0); | ||
break; | ||
} | ||
|
||
|
||
} | ||
|
||
public static Pivot getInstance() { | ||
return pivotInstance; | ||
} | ||
|
||
public static Pivot initialize(PivotIO io) { | ||
if (Pivot.pivotInstance == null) { | ||
pivotInstance = new Pivot(io); | ||
} | ||
return pivotInstance; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Pivot", inputs); | ||
} | ||
|
||
public void runVoltage(double volts) { | ||
io.setVoltage(volts); | ||
} | ||
|
||
public void stop() { | ||
io.stop(); | ||
} | ||
|
||
|
||
} |
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,30 @@ | ||
package frc.robot.subsystems.pivot; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface PivotIO { | ||
|
||
@AutoLog | ||
public static class PivotIOInputs { | ||
public double positionRad = 0.0; | ||
public double velocityRadPerSec = 0.0; | ||
public double appliedVolts = 0.0; | ||
public double[] currentAmps = new double[] {}; | ||
} | ||
|
||
/** Updates the set of loggable inputs. */ | ||
public default void updateInputs(PivotIOInputs inputs) {} | ||
|
||
/** Run open loop at the specified voltage. */ | ||
public default void setVoltage(double volts) {} | ||
|
||
/** Run closed loop at the specified velocity. */ | ||
public default void setVelocity(double velocityRadPerSec, double ffVolts) {} | ||
|
||
/** Stop in open loop. */ | ||
public default void stop() {} | ||
|
||
/** Set velocity PID constants. */ | ||
public default void configurePID(double kP, double kI, double kD) {} | ||
|
||
} |
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,38 @@ | ||
// package frc.robot.subsystems.pivot; | ||
|
||
// import edu.wpi.first.math.MathUtil; | ||
// import edu.wpi.first.math.controller.PIDController; | ||
// import edu.wpi.first.math.system.plant.DCMotor; | ||
// import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; | ||
// import frc.robot.subsystems.flywheel.FlywheelIO.FlywheelIOInputs; | ||
|
||
// public class PivotIOReal implements PivotIO { | ||
|
||
|
||
|
||
|
||
// @Override | ||
// public void setVoltage(double volts) { | ||
// closedLoop = false; | ||
// appliedVolts = volts; | ||
// sim.setInputVoltage(volts); | ||
// } | ||
|
||
// @Override | ||
// public void setVelocity(double velocityRadPerSec, double ffVolts) { | ||
// closedLoop = true; | ||
// pid.setSetpoint(velocityRadPerSec); | ||
// this.ffVolts = ffVolts; | ||
// } | ||
|
||
// @Override | ||
// public void stop() { | ||
// setVoltage(0.0); | ||
// } | ||
|
||
// @Override | ||
// public void configurePID(double kP, double kI, double kD) { | ||
// pid.setPID(kP, kI, kD); | ||
// } | ||
|
||
// } |
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,40 @@ | ||
package frc.robot.subsystems.pivot; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; | ||
import frc.robot.subsystems.flywheel.FlywheelIO.FlywheelIOInputs; | ||
|
||
public class PivotIOSim implements PivotIO { | ||
private SingleJointedArmSim sim = new SingleJointedArmSim(DCMotor.getNEO(1), 1.5, | ||
0.004, 0, 0, 0, | ||
false, 0); | ||
private PIDController pid = new PIDController(1.0, 0.0, 0.0); | ||
|
||
private boolean closedLoop = false; | ||
private double ffVolts = 0.0; | ||
private double appliedVolts = 0.0; | ||
|
||
@Override | ||
public void updateInputs(PivotIOInputs inputs) { | ||
if (closedLoop) { | ||
appliedVolts = | ||
MathUtil.clamp(pid.calculate(sim.getVelocityRadPerSec()) + ffVolts, -12.0, 12.0); | ||
sim.setInputVoltage(appliedVolts); | ||
} | ||
} | ||
|
||
@Override | ||
public void rotatePivot(double speed) { | ||
pivotAppliedVolts = MathUtil.clamp(12 * speed, -12, 12); | ||
sim.setInputVoltage(appliedVolts); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
sim.setInputVoltage(volts); | ||
} | ||
|
||
|
||
} |