generated from TitaniumTigers4829/4829-BaseRobotCode
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command factories and triggers examples #53
Draft
aridavidson001
wants to merge
3
commits into
main
Choose a base branch
from
command-factories-and-triggers-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.commands.auto; | ||
|
||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import frc.robot.subsystems.example.ExampleSubsystem; | ||
|
||
// NOTE: Consider using this command inline, rather than writing a subclass. For more | ||
// information, see: | ||
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html | ||
public class ExampleAuto extends SequentialCommandGroup { | ||
|
||
/** Creates a new ExampleAuto. */ | ||
public ExampleAuto(ExampleSubsystem exampleSubsystem) { | ||
// Add your commands in the addCommands() call, e.g. | ||
// addCommands(new FooCommand(), new BarCommand()); | ||
addCommands(exampleSubsystem.setPivotToScore().alongWith(exampleSubsystem.setPivotToScore())); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/frc/robot/subsystems/example/ExampleConstants.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,5 @@ | ||
package frc.robot.subsystems.example; | ||
|
||
public class ExampleConstants { | ||
public static final double SHOOTER_PIVOT_ANGLE = 0 - 9; | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/frc/robot/subsystems/example/ExampleSubsystem.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,103 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.subsystems.example; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.FunctionalCommand; | ||
import edu.wpi.first.wpilibj2.command.StartEndCommand; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import edu.wpi.first.wpilibj2.command.button.Trigger; | ||
import java.util.function.DoubleSupplier; | ||
|
||
public class ExampleSubsystem extends SubsystemBase { | ||
private DoubleSupplier DOUBLELOL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
|
||
/** Creates a new ExampleSubsystem. */ | ||
public ExampleSubsystem() {} | ||
|
||
// this is the interface for the subsystem | ||
// code for motors and such would go here | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
|
||
private void exampleSubsystemFunction() {} | ||
|
||
private void setExamplePivotAngle(double angle) { | ||
// normal subsystem stuff | ||
} | ||
|
||
private double getExamplePivotAngle() { | ||
return 0.0; | ||
} | ||
|
||
private boolean isAngleSet() { | ||
return false; | ||
} | ||
|
||
private boolean isGamepieceinRobot() { | ||
return false; | ||
} | ||
|
||
// Public Command Factory | ||
// create these for everything you would need to access from a command | ||
// so you don't input values or acces the internals of a subsystem in the commands themselves | ||
public Command exampleFunctionalCommand() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dude yk what this is pretty clean |
||
// the command is written here instead of in it's own seperate file. | ||
// this saves space and makes the code more readable | ||
|
||
return new FunctionalCommand( | ||
// does on init | ||
() -> this.setExamplePivotAngle(0), | ||
// does on execute | ||
() -> this.setExamplePivotAngle(1), | ||
// does when command ends | ||
interrupted -> this.setExamplePivotAngle(0), | ||
// ends the command when this is true | ||
() -> getExamplePivotAngle() >= 0, | ||
// requirements for the command | ||
this); | ||
} | ||
|
||
// Shared internal implementation | ||
private Command exampleStartEndCommand() { | ||
// the command is written here instead of in it's own seperate file. | ||
// this saves space and makes the code more readable | ||
|
||
return new StartEndCommand( | ||
// Sets the pivot to 1 while the command is active | ||
() -> this.setExamplePivotAngle(1), | ||
// Sets the pivot to 0 when the command ends | ||
() -> this.setExamplePivotAngle(0), | ||
// requirements for the command | ||
this); | ||
} | ||
|
||
// Shared internal implementation | ||
private Command exampleRunOnceCommand(double angle) { | ||
return this.runOnce(() -> setExamplePivotAngle(angle)); | ||
} | ||
|
||
// Public Command Factory | ||
public Command setPivotToScore() { | ||
return exampleRunOnceCommand(ExampleConstants.SHOOTER_PIVOT_ANGLE); | ||
} | ||
|
||
// Public Command Factory | ||
public Command setPivotToAngle(DoubleSupplier angle) { | ||
// if you need to pass a value in do it this way | ||
return exampleRunOnceCommand(angle.getAsDouble()); | ||
} | ||
|
||
// this is a trigger | ||
// if you need to give information from the subsystem do it like this | ||
// must be a boolean | ||
public final Trigger isAngleInRightSpot = new Trigger(() -> isAngleSet()); | ||
|
||
// another trigger example | ||
public final Trigger hasGamepiece = new Trigger(() -> isGamepieceinRobot()); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is what we've been using for autos 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're rewriting this!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idk tbh. I created another branch that uses auto factories and it's a lot cleaner. I'm not 100% sure it's done yet but if you want to check it out go for it