blob: b85a3c82be1bcbc65a3760325a5be1feb9e30323 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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); });
}
};
|