WPILibC++ 2024.3.2
SequentialCommandGroup.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#ifdef _WIN32
8#pragma warning(push)
9#pragma warning(disable : 4521)
10#endif
11
12#include <concepts>
13#include <limits>
14#include <memory>
15#include <type_traits>
16#include <utility>
17#include <vector>
18
20
23
24namespace frc2 {
25
27
28/**
29 * A command composition that runs a list of commands in sequence.
30 *
31 * <p>The rules for command compositions apply: command instances that are
32 * passed to it are owned by the composition and cannot be added to any other
33 * composition or scheduled individually, and the composition requires all
34 * subsystems its components require.
35 *
36 * This class is provided by the NewCommands VendorDep
37 */
39 : public CommandHelper<Command, SequentialCommandGroup> {
40 public:
41 /**
42 * Creates a new SequentialCommandGroup. The given commands will be run
43 * sequentially, with the composition finishing when the last command
44 * finishes.
45 *
46 * @param commands the commands to include in this composition.
47 */
49 std::vector<std::unique_ptr<Command>>&& commands);
50
51 /**
52 * Creates a new SequentialCommandGroup. The given commands will be run
53 * sequentially, with the composition finishing when the last command
54 * finishes.
55 *
56 * @param commands the commands to include in this composition.
57 */
58 template <wpi::DecayedDerivedFrom<Command>... Commands>
59 explicit SequentialCommandGroup(Commands&&... commands) {
60 AddCommands(std::forward<Commands>(commands)...);
61 }
62
64
65 // No copy constructors for command groups
67
68 // Prevent template expansion from emulating copy ctor
70
71 /**
72 * Adds the given commands to the group.
73 *
74 * @param commands Commands to add, in order of execution.
75 */
76 template <wpi::DecayedDerivedFrom<Command>... Commands>
77 void AddCommands(Commands&&... commands) {
78 std::vector<std::unique_ptr<Command>> foo;
79 ((void)foo.emplace_back(std::make_unique<std::decay_t<Commands>>(
80 std::forward<Commands>(commands))),
81 ...);
82 AddCommands(std::move(foo));
83 }
84
85 void Initialize() final;
86
87 void Execute() final;
88
89 void End(bool interrupted) final;
90
91 bool IsFinished() final;
92
93 bool RunsWhenDisabled() const override;
94
95 Command::InterruptionBehavior GetInterruptionBehavior() const override;
96
97 void InitSendable(wpi::SendableBuilder& builder) override;
98
99 private:
100 void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
101
102 wpi::SmallVector<std::unique_ptr<Command>, 4> m_commands;
103 size_t m_currentCommandIndex{invalid_index};
104 bool m_runWhenDisabled{true};
105 Command::InterruptionBehavior m_interruptBehavior{
107};
108} // namespace frc2
109
110#ifdef _WIN32
111#pragma warning(pop)
112#endif
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:27
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:41
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition: Command.h:173
@ kCancelIncoming
This command continues, and the incoming command is not scheduled.
A command composition that runs a list of commands in sequence.
Definition: SequentialCommandGroup.h:39
bool RunsWhenDisabled() const override
SequentialCommandGroup(SequentialCommandGroup &&other)=default
SequentialCommandGroup(std::vector< std::unique_ptr< Command > > &&commands)
Creates a new SequentialCommandGroup.
void AddCommands(Commands &&... commands)
Adds the given commands to the group.
Definition: SequentialCommandGroup.h:77
void End(bool interrupted) final
Command::InterruptionBehavior GetInterruptionBehavior() const override
void InitSendable(wpi::SendableBuilder &builder) override
SequentialCommandGroup(SequentialCommandGroup &)=delete
SequentialCommandGroup(Commands &&... commands)
Creates a new SequentialCommandGroup.
Definition: SequentialCommandGroup.h:59
SequentialCommandGroup(const SequentialCommandGroup &)=delete
Definition: TrapezoidProfileSubsystem.h:12
const size_t invalid_index
Definition: SequentialCommandGroup.h:26
Definition: array.h:89
UnitTypeLhs() max(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3417
Definition: ntcore_cpp.h:26