WPILibC++  2018.4.1-20180821010228-1169-g4a3e43d
 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 
61  void AddSequential(Command* command);
62 
80  void AddSequential(Command* command, double timeout);
81 
101  void AddParallel(Command* command);
102 
127  void AddParallel(Command* command, double timeout);
128 
129  bool IsInterruptible() const;
130 
131  int GetSize() const;
132 
133  protected:
137  virtual void Initialize();
138 
142  virtual void Execute();
143 
147  virtual bool IsFinished();
148 
152  virtual void End();
153 
157  virtual void Interrupted();
158 
159  virtual void _Initialize();
160  virtual void _Execute();
161  virtual void _End();
162  virtual void _Interrupted();
163 
164  private:
165  void CancelConflicts(Command* command);
166 
167  // The commands in this group (stored in entries)
168  std::vector<CommandGroupEntry> m_commands;
169 
170  // The active children in this group (stored in entries)
171  std::vector<CommandGroupEntry*> m_children;
172 
173  // The current command, -1 signifies that none have been run
174  int m_currentCommandIndex = -1;
175 };
176 
177 } // 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