-
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.
Created ShooterBase subsystem and command using right trigger
- Loading branch information
1 parent
b85507f
commit 6a5ee36
Showing
4 changed files
with
123 additions
and
1 deletion.
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,52 @@ | ||
package frc.robot.commands; | ||
|
||
|
||
|
||
import java.util.Map; | ||
import java.util.function.DoubleSupplier; | ||
|
||
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; | ||
|
||
public class ShooterBaseCommand extends Command { | ||
ShooterBase shooter; | ||
DoubleSupplier rightTriggerAxis; | ||
ShuffleboardTab tab; | ||
GenericEntry speedEntry; | ||
|
||
public ShooterBaseCommand(ShooterBase shooter, DoubleSupplier rightTriggerAxis) { | ||
this.shooter = shooter; | ||
this.rightTriggerAxis = rightTriggerAxis; | ||
|
||
//create shooter tab on ShuffleBoard | ||
tab = Shuffleboard.getTab("Shooter"); | ||
|
||
addRequirements(shooter); | ||
} | ||
@Override | ||
public void initialize() { | ||
// create speed entry under Shooter tab as a number sider with min = -1 and max = 1 | ||
speedEntry = tab.add("speed", 0).withWidget(BuiltInWidgets.kNumberSlider) | ||
.withProperties(Map.of("min", -1, "max", 1)).getEntry(); | ||
|
||
//sets default value to 0.0 | ||
speedEntry.setValue(0.0); | ||
} | ||
|
||
|
||
@Override | ||
public void execute() { | ||
//turns on motors if right trigger is fully pressed. else the motors turn off. | ||
if (rightTriggerAxis.getAsDouble() == 1.0) { | ||
shooter.setSpeed(speedEntry.getDouble(0.0)); | ||
shooter.enable(); | ||
} else { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package frc.robot.subsystems.shooter; | ||
|
||
public interface Shooter { | ||
// Disable the shooter | ||
public default void disable() {} | ||
|
||
// Enable the shooter with the . | ||
public default void enable() {} | ||
|
||
// Set the speed of the motors. | ||
public default void setSpeed(double speed) {} | ||
} |
36 changes: 36 additions & 0 deletions
36
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package frc.robot.subsystems.shooter; | ||
|
||
import edu.wpi.first.wpilibj.motorcontrol.Spark; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class ShooterBase extends SubsystemBase implements Shooter { | ||
private final Spark ShooterMotorLeft; | ||
private final Spark ShooterMotorRight; | ||
private double voltage; | ||
|
||
public ShooterBase() { | ||
ShooterMotorLeft = new Spark(0); | ||
ShooterMotorRight = new Spark(1); | ||
voltage = 0; | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
voltage = 0; | ||
ShooterMotorLeft.stopMotor(); | ||
ShooterMotorRight.stopMotor(); | ||
//System.out.println(voltage); | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
ShooterMotorLeft.setVoltage(voltage); | ||
System.out.println(voltage); | ||
} | ||
|
||
@Override | ||
public void setSpeed(double speed) { | ||
//Sets the voltage to 5.0 times speed. the speed value is -1 1 | ||
this.voltage = 5.0 * speed; | ||
} | ||
} |