-
Notifications
You must be signed in to change notification settings - Fork 6
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
3de3c3e
commit 12d7af9
Showing
8 changed files
with
134 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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,27 @@ | ||
package frc.robot; | ||
|
||
import edu.wpi.first.wpilibj2.command.button.CommandXboxController; | ||
import frc.robot.commands.example.ExampleSetSpeedCommand; | ||
|
||
public class Controls { | ||
public static final boolean EXAMPLE_ENABLED = false; | ||
public static final int DRIVE_CONTROLLER_PORT = 0; | ||
|
||
private final CommandXboxController driverController; | ||
|
||
// Normally, more descriptive names are better, but in this case, we care | ||
// about making the subsystem access easy | ||
private final Subsystems s; | ||
|
||
public Controls(Subsystems s) { | ||
driverController = new CommandXboxController(DRIVE_CONTROLLER_PORT); | ||
this.s = s; | ||
if (EXAMPLE_ENABLED) { | ||
bindExampleControls(); | ||
} | ||
} | ||
|
||
private void bindExampleControls() { | ||
driverController.a().onTrue(new ExampleSetSpeedCommand(s.exampleSubsystem, 0.1)); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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; | ||
|
||
import frc.robot.subsystems.ExampleSubsystem; | ||
|
||
public class Subsystems { | ||
public static final boolean EXAMPLE_ENABLED = false; | ||
|
||
public final ExampleSubsystem exampleSubsystem; | ||
|
||
public Subsystems() { | ||
if (EXAMPLE_ENABLED) { | ||
this.exampleSubsystem = new ExampleSubsystem(); | ||
} else { | ||
this.exampleSubsystem = null; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/frc/robot/commands/example/ExampleSetSpeedCommand.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,25 @@ | ||
package frc.robot.commands.example; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.ExampleSubsystem; | ||
|
||
public class ExampleSetSpeedCommand extends Command { | ||
private final ExampleSubsystem exampleSubsystem; | ||
private final double speed; | ||
|
||
public ExampleSetSpeedCommand(ExampleSubsystem exampleSubsystem, double speed) { | ||
this.exampleSubsystem = exampleSubsystem; | ||
this.speed = speed; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
exampleSubsystem.setSpeed(speed); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return MathUtil.isNear(speed, exampleSubsystem.getSpeed(), 0.5); | ||
} | ||
} |
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,15 @@ | ||
package frc.robot.dummy; | ||
|
||
public class Motor { | ||
private double speed = 0; | ||
|
||
public Motor(int id) {} | ||
|
||
public void set(double value) { | ||
this.speed = 0; | ||
} | ||
|
||
public double get() { | ||
return this.speed; | ||
} | ||
} |
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,41 @@ | ||
package frc.robot.subsystems; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.dummy.Motor; | ||
|
||
public class ExampleSubsystem extends SubsystemBase { | ||
// Constants | ||
public static final double MAX_SPEED = 7; | ||
public static final double GEAR_RATIO = 10; | ||
|
||
// Member variables | ||
private final Motor motor; | ||
|
||
// Constructor | ||
public ExampleSubsystem() { | ||
this.motor = new Motor(1); | ||
} | ||
|
||
// Methods | ||
public void setSpeed(double speed) { | ||
motor.set(speed / GEAR_RATIO); | ||
} | ||
|
||
public void fullSpeed() { | ||
motor.set(MAX_SPEED); | ||
} | ||
|
||
public void fullReverse() { | ||
motor.set(-MAX_SPEED); | ||
} | ||
|
||
public double getSpeed() { | ||
return motor.get() * GEAR_RATIO; | ||
} | ||
|
||
// Factories | ||
public Command setSpeedCmd(double speed) { | ||
return runOnce(() -> setSpeed(speed)); | ||
} | ||
} |