diff options
| author | BEAST <macbook@Macbooks-MacBook-Pro-2.local> | 2026-11-16 19:23:09 +0530 |
|---|---|---|
| committer | BEAST <macbook@Macbooks-MacBook-Pro-2.local> | 2026-11-16 19:23:09 +0530 |
| commit | 7764125350e66e464dded24ca8cf69a7e1ecef8d (patch) | |
| tree | e01f8b3a15fe905d6e5ccc3da6822df238b49030 /RobotFirmware/lib/HexaNRL/src/examples/ExampleSubsystem.h | |
Add local project files
Diffstat (limited to 'RobotFirmware/lib/HexaNRL/src/examples/ExampleSubsystem.h')
| -rw-r--r-- | RobotFirmware/lib/HexaNRL/src/examples/ExampleSubsystem.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/RobotFirmware/lib/HexaNRL/src/examples/ExampleSubsystem.h b/RobotFirmware/lib/HexaNRL/src/examples/ExampleSubsystem.h new file mode 100644 index 0000000..b85a3c8 --- /dev/null +++ b/RobotFirmware/lib/HexaNRL/src/examples/ExampleSubsystem.h @@ -0,0 +1,41 @@ +#pragma once +#include "NRL.h" + +// ============================================================ +// ExampleSubsystem.h — optional subsystem pattern +// ============================================================ +// You do NOT need to use this. If your code is simple, put +// everything directly in your own opmode file. +// +// Use this pattern when you want to group hardware belonging +// to one mechanism (arm, intake, shooter, etc.) into its own +// class with named states — the same way AG_2026 works. +// +// Pattern: +// 1. Define an enum for the states your mechanism can be in +// 2. Write update() to switch hardware based on the state +// 3. Expose command() to return an Action for use in sequences +// +// Then in your OpMode: +// #include "examples/ExampleSubsystem.h" +// ExampleSubsystem mySub; +// runBlocking(mySub.command(ExampleSubsystem::GRAB)); + +class ExampleSubsystem { +public: + enum State { INIT, GRAB, RELEASE }; + + // Update hardware immediately + void update(State s) { + switch (s) { + case INIT: arm.setPosition(90); break; + case GRAB: arm.setPosition(0); break; + case RELEASE: arm.setPosition(180); break; + } + } + + // Return an Action that can be used in sequential() / parallel() + ActionPtr command(State s) { + return instant([this, s]() { update(s); }); + } +}; |
