-
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.
Amp scoring action and Mechanism2d (#51)
* Adds HoodIOs and integrates into ScoringSubsystem * Adds mechanism2d for scoring subsystem * Flips hood to correct side * Tunes hood to be reasonable and visible * Fixes minor intake bugs * Fixes aiming latency * Reformats scoring constants
- Loading branch information
1 parent
3159c2e
commit fa9ac99
Showing
12 changed files
with
277 additions
and
30 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package frc.robot.subsystems.scoring; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface HoodIO { | ||
@AutoLog | ||
public static class HoodIOInputs { | ||
public double hoodAngleRad = 0.0; | ||
public double hoodGoalAngleRad = 0.0; | ||
public double hoodAppliedVolts = 0.0; | ||
public double hoodCurrentAmps = 0.0; | ||
} | ||
|
||
public default void updateInputs(HoodIOInputs inputs) {} | ||
|
||
public default void setHoodAngleRad(double angle) {} | ||
} |
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,45 @@ | ||
package frc.robot.subsystems.scoring; | ||
|
||
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.Constants; | ||
import frc.robot.Constants.ScoringConstants; | ||
|
||
public class HoodIOSim implements HoodIO { | ||
private final SingleJointedArmSim sim = | ||
new SingleJointedArmSim( | ||
DCMotor.getNeoVortex(1), | ||
0.2, | ||
SingleJointedArmSim.estimateMOI(0.1, 2), | ||
0.1, | ||
0.0, | ||
Math.PI, | ||
false, | ||
0.0); | ||
private final PIDController controller = | ||
new PIDController( | ||
ScoringConstants.aimerkP, ScoringConstants.aimerkI, ScoringConstants.aimerkD); | ||
|
||
double goalAngleRad = 0.0; | ||
double appliedVolts = 0.0; | ||
|
||
@Override | ||
public void setHoodAngleRad(double angle) { | ||
goalAngleRad = angle; | ||
} | ||
|
||
@Override | ||
public void updateInputs(HoodIOInputs inputs) { | ||
sim.update(Constants.loopTime); | ||
|
||
appliedVolts = controller.calculate(sim.getAngleRads(), goalAngleRad); | ||
sim.setInputVoltage(appliedVolts); | ||
|
||
inputs.hoodAngleRad = sim.getAngleRads(); | ||
inputs.hoodGoalAngleRad = goalAngleRad; | ||
|
||
inputs.hoodAppliedVolts = appliedVolts; | ||
inputs.hoodCurrentAmps = sim.getCurrentDrawAmps(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/frc/robot/subsystems/scoring/HoodIOVortex.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,39 @@ | ||
// FIXME: Fix once we get the real robot | ||
package frc.robot.subsystems.scoring; | ||
|
||
import com.revrobotics.CANSparkFlex; | ||
import frc.robot.Constants.ScoringConstants; | ||
|
||
public class HoodIOVortex implements HoodIO { | ||
private final CANSparkFlex hoodMotor = | ||
new CANSparkFlex(ScoringConstants.hoodId, CANSparkFlex.MotorType.kBrushless); | ||
|
||
double goalAngleRad = 0.0; | ||
|
||
public HoodIOVortex() { | ||
hoodMotor.setSmartCurrentLimit(10); | ||
|
||
hoodMotor.getPIDController().setP(ScoringConstants.hoodkP); | ||
hoodMotor.getPIDController().setI(ScoringConstants.hoodkI); | ||
hoodMotor.getPIDController().setD(ScoringConstants.hoodkD); | ||
|
||
hoodMotor.getEncoder().setPosition(0); | ||
|
||
// TODO: Get position later | ||
// hoodMotor.getEncoder().setPositionConversionFactor() | ||
} | ||
|
||
@Override | ||
public void setHoodAngleRad(double angle) { | ||
goalAngleRad = angle; | ||
} | ||
|
||
@Override | ||
public void updateInputs(HoodIOInputs inputs) { | ||
inputs.hoodAngleRad = hoodMotor.getEncoder().getPosition(); | ||
inputs.hoodGoalAngleRad = goalAngleRad; | ||
|
||
inputs.hoodAppliedVolts = hoodMotor.getAppliedOutput(); | ||
inputs.hoodCurrentAmps = hoodMotor.getOutputCurrent(); | ||
} | ||
} |
Oops, something went wrong.