-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a66a8f0
commit 5ae8534
Showing
6 changed files
with
95 additions
and
104 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
101 changes: 50 additions & 51 deletions
101
src/main/java/frc/robot/commands/ShooterBaseCommand.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,64 +1,63 @@ | ||
package frc.robot.commands; | ||
|
||
|
||
|
||
import java.util.Map; | ||
import java.util.function.BooleanSupplier; | ||
|
||
import edu.wpi.first.networktables.GenericEntry; | ||
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets; | ||
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; | ||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.shooter.ShooterBase; | ||
import java.util.Map; | ||
import java.util.function.BooleanSupplier; | ||
|
||
public class ShooterBaseCommand extends Command { | ||
ShooterBase shooter; | ||
BooleanSupplier enable; | ||
ShuffleboardTab tab; | ||
GenericEntry voltsEntry; | ||
|
||
public ShooterBaseCommand(ShooterBase shooter, BooleanSupplier enable) { | ||
this.shooter = shooter; | ||
this.enable = enable; | ||
|
||
//create shooter tab on ShuffleBoard | ||
tab = Shuffleboard.getTab("Shooter"); | ||
// Create volt entry under Shooter tab as a number sider with min = -1 and max = 1 | ||
voltsEntry = tab.add("Volts", 0).withWidget(BuiltInWidgets.kNumberSlider) | ||
.withProperties(Map.of("min", -12, "max", 12)).getEntry(); | ||
|
||
// Sets default value to 0.0 | ||
voltsEntry.setValue(0.0); | ||
|
||
addRequirements(shooter); | ||
ShooterBase shooter; | ||
BooleanSupplier enable; | ||
ShuffleboardTab tab; | ||
GenericEntry voltsEntry; | ||
|
||
public ShooterBaseCommand(ShooterBase shooter, BooleanSupplier enable) { | ||
this.shooter = shooter; | ||
this.enable = enable; | ||
|
||
// create shooter tab on ShuffleBoard | ||
tab = Shuffleboard.getTab("Shooter"); | ||
// Create volt entry under Shooter tab as a number sider with min = -1 and max = 1 | ||
voltsEntry = | ||
tab.add("Volts", 0) | ||
.withWidget(BuiltInWidgets.kNumberSlider) | ||
.withProperties(Map.of("min", -12, "max", 12)) | ||
.getEntry(); | ||
|
||
// Sets default value to 0.0 | ||
voltsEntry.setValue(0.0); | ||
|
||
addRequirements(shooter); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
// disable shooter when initialize | ||
shooter.disable(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
// Turns on motors if right trigger is fully pressed. else the motors turn off. | ||
if (enable.getAsBoolean() == true) { | ||
// Checks the volt Entry for the volt and sets the voltage of motors | ||
shooter.setVoltage(voltsEntry.getDouble(0.0)); | ||
|
||
// Enable motors, It has to be called regularly for voltage compensation to work properly | ||
shooter.enable(); | ||
} else { | ||
// Disable the shooters | ||
shooter.disable(); | ||
} | ||
@Override | ||
public void initialize() { | ||
// disable shooter when initialize | ||
shooter.disable(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void execute() { | ||
// Turns on motors if right trigger is fully pressed. else the motors turn off. | ||
if (enable.getAsBoolean() == true) { | ||
// Checks the volt Entry for the volt and sets the voltage of motors | ||
shooter.setVoltage(voltsEntry.getDouble(0.0)); | ||
|
||
// Enable motors, It has to be called regularly for voltage compensation to work properly | ||
shooter.enable(); | ||
} else { | ||
// Disable the shooters | ||
shooter.disable(); | ||
} | ||
} | ||
|
||
@Override | ||
//disable shooter when it ends. | ||
public void end(boolean interrupted) { | ||
shooter.disable(); | ||
} | ||
@Override | ||
// disable shooter when it ends. | ||
public void end(boolean interrupted) { | ||
shooter.disable(); | ||
} | ||
} |
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
82 changes: 40 additions & 42 deletions
82
src/main/java/frc/robot/subsystems/shooter/ShooterBase.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,48 +1,46 @@ | ||
package frc.robot.subsystems.shooter; | ||
|
||
|
||
import org.littletonrobotics.junction.Logger; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class ShooterBase extends SubsystemBase implements Shooter { | ||
ShooterIO io; | ||
private final ShooterIOInputsAutoLogged inputs = new ShooterIOInputsAutoLogged(); | ||
private double voltage; | ||
|
||
public ShooterBase(ShooterIO io) { | ||
this.io = io; | ||
voltage = 0; | ||
} | ||
|
||
@Override | ||
//Disable the shooter | ||
public void disable() { | ||
voltage = 0; | ||
io.setVoltage(voltage); | ||
} | ||
|
||
@Override | ||
//Enable the shooter | ||
public void enable() { | ||
io.setVoltage(voltage); | ||
} | ||
|
||
@Override | ||
//Sets the voltage to volts. the volts value is -12 to 12 | ||
public void setVoltage(double volts) { | ||
voltage = volts; | ||
} | ||
|
||
@Override | ||
public double getCurrentSpeed() { | ||
return inputs.velocityRadPerSec; | ||
} | ||
@Override | ||
public void periodic() { | ||
//Updates the inputs | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Shooter", inputs); | ||
} | ||
ShooterIO io; | ||
private final ShooterIOInputsAutoLogged inputs = new ShooterIOInputsAutoLogged(); | ||
private double voltage; | ||
|
||
public ShooterBase(ShooterIO io) { | ||
this.io = io; | ||
voltage = 0; | ||
} | ||
|
||
@Override | ||
// Disable the shooter | ||
public void disable() { | ||
voltage = 0; | ||
io.setVoltage(voltage); | ||
} | ||
|
||
@Override | ||
// Enable the shooter | ||
public void enable() { | ||
io.setVoltage(voltage); | ||
} | ||
|
||
@Override | ||
// Sets the voltage to volts. the volts value is -12 to 12 | ||
public void setVoltage(double volts) { | ||
voltage = volts; | ||
} | ||
|
||
@Override | ||
public double getCurrentSpeed() { | ||
return inputs.velocityRadPerSec; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// Updates the inputs | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Shooter", inputs); | ||
} | ||
} |
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