WPILibC++  unspecified
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 <list>
11 #include <vector>
12 
13 #include <wpi/Twine.h>
14 
15 #include "Commands/Command.h"
16 #include "Commands/CommandGroupEntry.h"
17 
18 namespace frc {
19 
37 class CommandGroup : public Command {
38  public:
39  CommandGroup() = default;
40 
46  explicit CommandGroup(const wpi::Twine& name);
47 
48  virtual ~CommandGroup() = default;
49 
62  void AddSequential(Command* command);
63 
81  void AddSequential(Command* command, double timeout);
82 
102  void AddParallel(Command* command);
103 
128  void AddParallel(Command* command, double timeout);
129 
130  bool IsInterruptible() const;
131 
132  int GetSize() const;
133 
134  protected:
138  virtual void Initialize();
139 
143  virtual void Execute();
144 
148  virtual bool IsFinished();
149 
153  virtual void End();
154 
158  virtual void Interrupted();
159 
160  virtual void _Initialize();
161  virtual void _Execute();
162  virtual void _End();
163  virtual void _Interrupted();
164 
165  private:
166  void CancelConflicts(Command* command);
167 
168  // The commands in this group (stored in entries)
169  std::vector<CommandGroupEntry> m_commands;
170 
171  // The active children in this group (stored in entries)
172  std::list<CommandGroupEntry> m_children;
173 
174  // The current command, -1 signifies that none have been run
175  int m_currentCommandIndex = -1;
176 };
177 
178 } // namespace frc
void AddParallel(Command *command)
Adds a new child Command to the group.
Definition: CommandGroup.cpp:56
Definition: Utility.cpp:119
virtual void Initialize()
Can be overridden by teams.
Definition: CommandGroup.cpp:114
void AddSequential(Command *command)
Adds a new Command to the group.
Definition: CommandGroup.cpp:16
virtual void End()
Can be overridden by teams.
Definition: CommandGroup.cpp:123
A CommandGroup is a list of commands which are executed in sequence.
Definition: CommandGroup.h:37
virtual void Execute()
Can be overridden by teams.
Definition: CommandGroup.cpp:116
virtual bool IsFinished()
Can be overridden by teams.
Definition: CommandGroup.cpp:118
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
virtual void Interrupted()
Can be overridden by teams.
Definition: CommandGroup.cpp:125