WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
SequentialCommandGroup.hpp
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 <limits>
13#include <memory>
14#include <type_traits>
15#include <utility>
16#include <vector>
17
20
21namespace wpi::cmd {
22
23const size_t invalid_index = std::numeric_limits<size_t>::max();
24
25/**
26 * A command composition that runs a list of commands in sequence.
27 *
28 * <p>The rules for command compositions apply: command instances that are
29 * passed to it are owned by the composition and cannot be added to any other
30 * composition or scheduled individually, and the composition requires all
31 * subsystems its components require.
32 *
33 * This class is provided by the NewCommands VendorDep
34 */
36 : public CommandHelper<Command, SequentialCommandGroup> {
37 public:
38 /**
39 * Creates a new SequentialCommandGroup. The given commands will be run
40 * sequentially, with the composition finishing when the last command
41 * finishes.
42 *
43 * @param commands the commands to include in this composition.
44 */
46 std::vector<std::unique_ptr<Command>>&& commands);
47
48 /**
49 * Creates a new SequentialCommandGroup. The given commands will be run
50 * sequentially, with the composition finishing when the last command
51 * finishes.
52 *
53 * @param commands the commands to include in this composition.
54 */
55 template <wpi::util::DecayedDerivedFrom<Command>... Commands>
56 explicit SequentialCommandGroup(Commands&&... commands) {
57 AddCommands(std::forward<Commands>(commands)...);
58 }
59
61
62 // No copy constructors for command groups
64
65 // Prevent template expansion from emulating copy ctor
67
68 /**
69 * Adds the given commands to the group.
70 *
71 * @param commands Commands to add, in order of execution.
72 */
73 template <wpi::util::DecayedDerivedFrom<Command>... Commands>
74 void AddCommands(Commands&&... commands) {
75 std::vector<std::unique_ptr<Command>> foo;
76 ((void)foo.emplace_back(std::make_unique<std::decay_t<Commands>>(
77 std::forward<Commands>(commands))),
78 ...);
79 AddCommands(std::move(foo));
80 }
81
82 void Initialize() final;
83
84 void Execute() final;
85
86 void End(bool interrupted) final;
87
88 bool IsFinished() final;
89
90 bool RunsWhenDisabled() const override;
91
92 Command::InterruptionBehavior GetInterruptionBehavior() const override;
93
94 void InitSendable(wpi::util::SendableBuilder& builder) override;
95
96 private:
97 void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
98
99 wpi::util::SmallVector<std::unique_ptr<Command>, 4> m_commands;
100 size_t m_currentCommandIndex{invalid_index};
101 bool m_runWhenDisabled{true};
102 Command::InterruptionBehavior m_interruptBehavior{
104};
105} // namespace wpi::cmd
106
107#ifdef _WIN32
108#pragma warning(pop)
109#endif
A state machine representing a complete action to be performed by the robot.
Definition Command.hpp:41
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition Command.hpp:173
@ kCancelIncoming
This command continues, and the incoming command is not scheduled.
Definition Command.hpp:182
SequentialCommandGroup(SequentialCommandGroup &)=delete
Command::InterruptionBehavior GetInterruptionBehavior() const override
void InitSendable(wpi::util::SendableBuilder &builder) override
void End(bool interrupted) final
SequentialCommandGroup(const SequentialCommandGroup &)=delete
SequentialCommandGroup(Commands &&... commands)
Creates a new SequentialCommandGroup.
Definition SequentialCommandGroup.hpp:56
bool RunsWhenDisabled() const override
SequentialCommandGroup(std::vector< std::unique_ptr< Command > > &&commands)
Creates a new SequentialCommandGroup.
SequentialCommandGroup(SequentialCommandGroup &&other)=default
void AddCommands(Commands &&... commands)
Adds the given commands to the group.
Definition SequentialCommandGroup.hpp:74
Definition StringMap.hpp:773
Definition CommandNiDsStadiaController.hpp:15
const size_t invalid_index
Definition SequentialCommandGroup.hpp:23
Definition raw_os_ostream.hpp:19
Definition CvSource.hpp:15