WPILibC++  2019.1.1-beta-2-23-g90572a3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
CommandGroup.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <vector>
11 
12 #include <wpi/Twine.h>
13 
14 #include "frc/commands/Command.h"
15 #include "frc/commands/CommandGroupEntry.h"
16 
17 namespace frc {
18 
36 class CommandGroup : public Command {
37  public:
38  CommandGroup() = default;
39 
45  explicit CommandGroup(const wpi::Twine& name);
46 
47  virtual ~CommandGroup() = default;
48 
49  CommandGroup(CommandGroup&&) = default;
50  CommandGroup& operator=(CommandGroup&&) = default;
51 
64  void AddSequential(Command* command);
65 
83  void AddSequential(Command* command, double timeout);
84 
104  void AddParallel(Command* command);
105 
130  void AddParallel(Command* command, double timeout);
131 
132  bool IsInterruptible() const;
133 
134  int GetSize() const;
135 
136  protected:
140  virtual void Initialize();
141 
145  virtual void Execute();
146 
150  virtual bool IsFinished();
151 
155  virtual void End();
156 
160  virtual void Interrupted();
161 
162  virtual void _Initialize();
163  virtual void _Execute();
164  virtual void _End();
165  virtual void _Interrupted();
166 
167  private:
168  void CancelConflicts(Command* command);
169 
170  // The commands in this group (stored in entries)
171  std::vector<CommandGroupEntry> m_commands;
172 
173  // The active children in this group (stored in entries)
174  std::vector<CommandGroupEntry*> m_children;
175 
176  // The current command, -1 signifies that none have been run
177  int m_currentCommandIndex = -1;
178 };
179 
180 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void AddSequential(Command *command)
Adds a new Command to the group.
virtual void End()
Can be overridden by teams.
void AddParallel(Command *command)
Adds a new child Command to the group.
virtual void Execute()
Can be overridden by teams.
virtual void Initialize()
Can be overridden by teams.
virtual void Interrupted()
Can be overridden by teams.
A CommandGroup is a list of commands which are executed in sequence.
Definition: CommandGroup.h:36
virtual bool IsFinished()
Can be overridden by teams.
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79