WPILibC++ 2023.4.3-108-ge5452e3
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 <span>
16#include <type_traits>
17#include <utility>
18#include <vector>
19
21
24
25namespace frc2 {
26
28
29/**
30 * A command composition that runs a list of commands in sequence.
31 *
32 * <p>The rules for command compositions apply: command instances that are
33 * passed to it are owned by the composition and cannot be added to any other
34 * composition or scheduled individually, and the composition requires all
35 * subsystems its components require.
36 *
37 * This class is provided by the NewCommands VendorDep
38 */
40 : public CommandHelper<CommandBase, SequentialCommandGroup> {
41 public:
42 /**
43 * Creates a new SequentialCommandGroup. The given commands will be run
44 * sequentially, with the composition finishing when the last command
45 * finishes.
46 *
47 * @param commands the commands to include in this composition.
48 */
50 std::vector<std::unique_ptr<Command>>&& commands);
51
52 /**
53 * Creates a new SequentialCommandGroup. The given commands will be run
54 * sequentially, with the composition finishing when the last command
55 * finishes.
56 *
57 * @param commands the commands to include in this composition.
58 */
59 template <wpi::DecayedDerivedFrom<Command>... Commands>
60 explicit SequentialCommandGroup(Commands&&... commands) {
61 AddCommands(std::forward<Commands>(commands)...);
62 }
63
65
66 // No copy constructors for command groups
68
69 // Prevent template expansion from emulating copy ctor
71
72 /**
73 * Adds the given commands to the group.
74 *
75 * @param commands Commands to add, in order of execution.
76 */
77 template <wpi::DecayedDerivedFrom<Command>... Commands>
78 void AddCommands(Commands&&... commands) {
79 std::vector<std::unique_ptr<Command>> foo;
80 ((void)foo.emplace_back(std::make_unique<std::decay_t<Commands>>(
81 std::forward<Commands>(commands))),
82 ...);
83 AddCommands(std::move(foo));
84 }
85
86 void Initialize() final;
87
88 void Execute() final;
89
90 void End(bool interrupted) final;
91
92 bool IsFinished() final;
93
94 bool RunsWhenDisabled() const override;
95
96 Command::InterruptionBehavior GetInterruptionBehavior() const override;
97
98 void InitSendable(wpi::SendableBuilder& builder) override;
99
100 private:
101 void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
102
103 wpi::SmallVector<std::unique_ptr<Command>, 4> m_commands;
104 size_t m_currentCommandIndex{invalid_index};
105 bool m_runWhenDisabled{true};
106 Command::InterruptionBehavior m_interruptBehavior{
108};
109} // namespace frc2
110
111#ifdef _WIN32
112#pragma warning(pop)
113#endif
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:25
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:44
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition: Command.h:101
@ 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:40
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:78
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:60
SequentialCommandGroup(const SequentialCommandGroup &)=delete
constexpr common_t< T1, T2 > max(const T1 x, const T2 y) noexcept
Compile-time pairwise maximum function.
Definition: max.hpp:35
Definition: ProfiledPIDCommand.h:18
const size_t invalid_index
Definition: SequentialCommandGroup.h:27
Definition: BFloat16.h:88
Definition: AprilTagFieldLayout.h:18
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Definition: SmallVector.h:1112