-
Notifications
You must be signed in to change notification settings - Fork 6
Command based docs updates 2024 #70
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cd4edca
editing pass on CommandBased.md
LewisSeiden 86fcd54
kevin pr feedback
LewisSeiden 0f045bd
fixed examples
LewisSeiden 19f958a
fix kitbot examples\ (who wouldve thought that installing a java synt…
LewisSeiden fc34f75
replace pathplanner reference to choreo reference in wpilib intro
LewisSeiden 49db870
Merge branch '2024' into command-based-2024
spellingcat 2cc4b1e
Merge branch '2024' into command-based-2024. lowkey should've done th…
spellingcat 52b51e7
update projects to 2025 (surely there's a better way to do this :sob:)
spellingcat 9b45078
import basic project also
spellingcat d6dd7bf
update command based articles
spellingcat 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,26 +2,49 @@ | |
|
|
||
| ## Command Based is a way of structuring our code to make it easy to do complicated tasks, and write control logic in a concise way | ||
|
|
||
| Command based programming revolves around two concepts: Subsystems and Commands. | ||
| Command based programming revolves around three concepts: **Subsystems**, **Commands**, and **Triggers**. | ||
|
|
||
| A Subsystem is a set of hardware that forms one system on our robot, like the drivetrain, elevator, arm, or intake. | ||
| Each subsystem contains some associated hardware (motors, pistons, sensors, etc.) They are the "nouns" of our robot, what it is. | ||
| Commands are the "verbs" of the robt, or what our robot does. | ||
| Each Subsystem is generally made to contain a broad set of hardware that will always operate as a unit. | ||
|
|
||
| Commands are the "verbs" of the robot, or what our robot does. | ||
| Each Subsystem can be used by one Command at the same time, but Commands may use many Subsystems. | ||
| Commands can be composed together, so the `Line Up`, `Extend`, and `Outake` Commands might be put together to make a `Score` Command. | ||
| Commands can be composed together, so the `LineUp`, `Extend`, and `Outake` Commands might be put together to make a `Score` Command. | ||
| Because each Subsystem can only be used by one Command at once, we are safe from multiple pieces of code trying to command the same motor to different speeds, for example. | ||
|
|
||
| Subsystems are ways to organize resources that can be used by one Command at a time. | ||
|
|
||
| Some hardware might not be stored in a Subsystem if multiple things can/should use it at the same time safely. | ||
| For example, a vision setup can be read from by many things, and might not need to be locked by Commands. | ||
| Therefore, it might not be stored in a Subsystem. | ||
|
|
||
| On the other hand, a roller that is driven by a motor can only go at one speed at a time. | ||
| Therefore, we would wrap it in a Subsystem so that only one Command can use it at once. | ||
|
|
||
| A Trigger is something which can start a Command. | ||
| The classic form of this is a button on the driver's controller. | ||
| Another common type is one which checks for when the robot enables. | ||
| One non-obvious Trigger we used in 2024 was one which checked when we had detected a game piece in the robot, which we used to flash our LEDs and vibrate the driver controller. | ||
| Triggers can be made of any function that returns a boolean which makes them very powerful. | ||
| Some large Commands are better represented by several Commands and some Triggers! | ||
|
|
||
| # update with superstructure stuff later | ||
|
|
||
| ### Resources | ||
|
|
||
| - [WPILib intro to functional programming](https://docs.wpilib.org/en/stable/docs/software/basic-programming/functions-as-data.html). | ||
| Read through this article on lambda expressions and functional programming if you haven't already. | ||
| - [WPILib docs](https://docs.wpilib.org/en/stable/docs/software/commandbased/index.html). | ||
| Read through these docs until you finish "The Command Scheduler" | ||
| Read through these docs until you finish "Organizing Command-Based Robot Projects" | ||
| OR watch [this video](https://drive.google.com/file/d/1ykFDfXVYk27aHlXYKTAqtj1U2T80Szdj/view?usp=drive_link). | ||
| Presentation notes for the video are [here](CommandBasedPresentationNotes.md) | ||
| The important segment to remember is: | ||
| Presentation notes for the video are [here](CommandBasedPresentationNotes.md). | ||
| If you watch the video, it is recommended to also read the [Subsystems](https://docs.wpilib.org/en/stable/docs/software/commandbased/subsystems.html), [Binding Commands to Triggers](https://docs.wpilib.org/en/stable/docs/software/commandbased/binding-commands-to-triggers.html), and [Organizing Command-Based Robot Projects](https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#) for addition details on using Command-Based. | ||
|
|
||
| The important segment of all of this to remember is: | ||
| > Commands represent actions the robot can take. Commands run when scheduled, until they are interrupted or their end condition is met. Commands are very recursively composable: commands can be composed to accomplish more-complicated tasks. See Commands for more info. | ||
| > | ||
| > Subsystems represent independently-controlled collections of robot hardware (such as motor controllers, sensors, pneumatic actuators, etc.) that operate together. Subsystems back the resource-management system of command-based: only one command can use a given subsystem at the same time. Subsystems allow users to “hide” the internal complexity of their actual hardware from the rest of their code - this both simplifies the rest of the robot code, and allows changes to the internal details of a subsystem’s hardware without also changing the rest of the robot code. | ||
| - [WPILib intro to functional programming](https://docs.wpilib.org/en/stable/docs/software/basic-programming/functions-as-data.html). | ||
| Read through this article on lambda expressions and functional programming. | ||
|
Contributor
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. Is this covered elsewhere?
Collaborator
Author
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. it got moved up in the list |
||
|
|
||
| ### Examples | ||
|
|
||
|
|
@@ -35,11 +58,7 @@ Because each Subsystem can only be used by one Command at once, we are safe from | |
| ### Notes | ||
|
|
||
| - We prefer making simple Commands with Command factories, or methods in a subsystem that return a Command. | ||
| These methods should be simple interactions like `setTargetExtensionInches()` or `extendIntake()`. | ||
| These methods should be simple interactions like `setTargetExtensionMeters()` or `extendIntake()`. | ||
| Then you can use decorators as described [here](https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html) to compose the basic Commands into more complex sequences. | ||
| Generally we make these compositions in `RobotContainer` but you can also make single-Subsystem compositions within that Subsystem. | ||
| Generally we make these compositions in `Robot` and `Superstructure` but you can also make single-Subsystem compositions within that Subsystem. | ||
| See our code from previous years for examples of this pattern, or talk to a software lead. | ||
| - In our 2023 code we started using a pattern called the `SuperstructureSubsystem`. | ||
| This pattern involves creating a Subsystem that has references to most other Subsystems to make Command factory methods with multiple Subsystems. | ||
| This pattern doesn't really make sense on inspection though, since the `SuperstructureSubsystem` doesn't actually lock any hardware from multiple-access and you can just make the composed Commands in `RobotContainer` instead. | ||
| In the future, just make multiple-Subsystem Command factories in `RobotContainer`. | ||
This file contains hidden or 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
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.
not sure if you want to have this as a block quote, do you also want to add a summary for triggers?
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.
these are taken directly from the wpilib docs, hence the block quote. not sure if it still needs to be there since its decently redundant w the intro