-
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.
added basic PID functionality to shooter subsystem
- Loading branch information
Showing
3 changed files
with
45 additions
and
11 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
37 changes: 28 additions & 9 deletions
37
...main/java/org/jmhsrobotics/frc2024/subsystems/shooter/shooterCommands/ShooterCommand.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,23 +1,42 @@ | ||
package org.jmhsrobotics.frc2024.subsystems.shooter.shooterCommands; | ||
|
||
import org.jmhsrobotics.frc2024.subsystems.shooter.ShooterSubsystem; | ||
import org.jmhsrobotics.frc2024.controlBoard.ControlBoard; | ||
|
||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class ShooterCommand extends Command { | ||
private ShooterSubsystem shooterSubsystem; | ||
private ControlBoard control; | ||
private ShooterSubsystem shooter; | ||
private double targetRPM; | ||
private PIDController pid; | ||
|
||
public ShooterCommand(double targetRPM, ShooterSubsystem shooterSubsystem) { | ||
this.shooter = shooterSubsystem; | ||
this.targetRPM = targetRPM; | ||
pid = new PIDController(.1, 0, 0); | ||
|
||
addRequirements(this.shooter); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
pid.reset(); | ||
pid.setSetpoint(targetRPM); | ||
} | ||
|
||
public ShooterCommand(ShooterSubsystem shooterSubsystem, ControlBoard control) { | ||
this.shooterSubsystem = shooterSubsystem; | ||
this.control = control; | ||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
|
||
addRequirements(this.shooterSubsystem); | ||
@Override | ||
public void end(boolean interrupted) { | ||
shooter.setSpeed(0); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
double motorSpeed = control.shooterInput(); | ||
shooterSubsystem.setSpeed(motorSpeed); | ||
double motorSpeed = pid.calculate(shooter.getRPM(), targetRPM); | ||
shooter.setSpeed(motorSpeed); | ||
} | ||
} |