-
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.
- Loading branch information
1 parent
0898df5
commit d98c2cf
Showing
4 changed files
with
102 additions
and
4 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,64 @@ | ||
package frc.robot.commands.gizmo; | ||
|
||
import edu.wpi.first.wpilibj.RobotController; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.gizmo.GizmoSimple; | ||
import java.util.function.BooleanSupplier; | ||
|
||
public class GizmoCommand extends Command { | ||
private GizmoSimple gizmo; | ||
private BooleanSupplier decreaseSpeed; | ||
private BooleanSupplier increaseSpeed; | ||
private BooleanSupplier runBackward; | ||
private BooleanSupplier runForward; | ||
private double currentSpeed = 0.0; | ||
private double minSpeed = 0.0; | ||
private double maxSpeed = 1.0; | ||
private double speedIncrement = 0.01; | ||
|
||
public GizmoCommand( | ||
GizmoSimple gizmo, | ||
BooleanSupplier decreaseSpeed, | ||
BooleanSupplier increaseSpeed, | ||
BooleanSupplier runBackward, | ||
BooleanSupplier runForward) { | ||
this.gizmo = gizmo; | ||
this.decreaseSpeed = decreaseSpeed; | ||
this.increaseSpeed = increaseSpeed; | ||
this.runBackward = runBackward; | ||
this.runForward = runForward; | ||
|
||
addRequirements(gizmo); | ||
} | ||
|
||
public void execute() { | ||
|
||
/* Check if speed needs to be changed */ | ||
if (decreaseSpeed.getAsBoolean()) { | ||
if (currentSpeed >= speedIncrement) { | ||
currentSpeed -= speedIncrement; | ||
} else { | ||
currentSpeed = minSpeed; | ||
} | ||
} else if (increaseSpeed.getAsBoolean()) { | ||
if (currentSpeed <= (maxSpeed - speedIncrement)) { | ||
currentSpeed += speedIncrement; | ||
} else { | ||
currentSpeed = maxSpeed; | ||
} | ||
} | ||
|
||
/* Check if motor needs to be turned on */ | ||
if (runForward.getAsBoolean()) { | ||
gizmo.setVoltage(currentSpeed * RobotController.getBatteryVoltage()); | ||
} else if (runBackward.getAsBoolean()) { | ||
gizmo.setVoltage(-currentSpeed * RobotController.getBatteryVoltage()); | ||
} else { | ||
gizmo.setVoltage(0); | ||
} | ||
} | ||
|
||
public void end(boolean interrupted) { | ||
gizmo.setVoltage(0); | ||
} | ||
} |
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,11 @@ | ||
package frc.robot.subsystems.gizmo; | ||
|
||
public interface Gizmo { | ||
/* Open Loop Controls */ | ||
/** | ||
* Sets open loop voltage to send to motor | ||
* | ||
* @param volts voltage to send to the motor Typically in the range [-12.0..12.0] | ||
*/ | ||
public void setVoltage(double volts); | ||
} |
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,8 +1,17 @@ | ||
package frc.robot.subsystems.gizmo; | ||
|
||
import edu.wpi.first.wpilibj.motorcontrol.Spark; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.AutoLogOutput; | ||
|
||
public class GizmoSimple extends SubsystemBase { | ||
|
||
|
||
public class GizmoSimple extends SubsystemBase implements Gizmo { | ||
/** Spark PWM Motor is connected to RIO PWM Port 0 */ | ||
private static final Spark motor = new Spark(0); | ||
@AutoLogOutput private double volts = 0; | ||
|
||
/* Control */ | ||
public void setVoltage(double volts) { | ||
this.volts = volts; | ||
motor.setVoltage(volts); | ||
} | ||
} |