summaryrefslogtreecommitdiff
path: root/RobotFirmware/lib/HexaNRL/src/examples/ExampleSeq.h
blob: f1124970ce7433270818db40cc5ed315193db51f (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include "NRL.h"
#include "ExampleSubsystem.h"

// ============================================================
//  ExampleSeq.h — ADVANCED: the named-sequence pattern
// ============================================================
//  You do NOT need this to write a working OpMode, and you should not
//  start here. Write your sequences inline first:
//
//    if (gamepad1.justPressed(BTN_X)) {
//        runAction(sequential({
//            instant([]{ arm.setPosition(0);      }),
//            sleep_ms(400),
//            instant([]{ gripper.setPosition(90); }),
//        }));
//    }
//
//  That is the right shape for most robots, and it reads top to bottom.
//  GRADUATE TO THIS FILE when one of those becomes true:
//    - loop() has grown long enough that the buttons are hard to find
//    - you use the same sequence from more than one place
//    - two people are editing the same OpMode and colliding
//
//  Pattern:
//    Collect related sequences in a namespace.
//    Each function takes subsystem references and returns an ActionPtr.
//    Same idea as INITSeq / ShooterSeq / ServoSeq in AG_2026.
//
//  Then in your OpMode:
//    #include "examples/ExampleSeq.h"
//    static ExampleSubsystem sub;
//
//    void start() override {                       // AUTO: queue once
//        runAction(ExampleSeq::initAll(sub));
//    }
//
//    void loop() override {                        // TELEOP: on a button edge
//        if (gamepad1.justPressed(BTN_X)) runAction(ExampleSeq::pickUp(sub));
//    }

namespace ExampleSeq {

    // Move all subsystems to their safe starting position
    inline ActionPtr initAll(ExampleSubsystem& sub) {
        return parallel({
            sub.command(ExampleSubsystem::INIT),
            // add more subsystems here
        });
    }

    // Grab sequence: lower arm, wait, close gripper
    inline ActionPtr pickUp(ExampleSubsystem& sub) {
        return sequential({
            sub.command(ExampleSubsystem::GRAB),
            sleep_ms(400),
            instant([]{ gripper.setPosition(0); }),
        });
    }

    // Release sequence: open gripper, raise arm
    inline ActionPtr release(ExampleSubsystem& sub) {
        return sequential({
            instant([]{ gripper.setPosition(180); }),
            sleep_ms(200),
            sub.command(ExampleSubsystem::RELEASE),
        });
    }
}