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 <llvm/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  explicit CommandGroup(const llvm::Twine& name);
41  virtual ~CommandGroup() = default;
42 
43  void AddSequential(Command* command);
44  void AddSequential(Command* command, double timeout);
45  void AddParallel(Command* command);
46  void AddParallel(Command* command, double timeout);
47  bool IsInterruptible() const;
48  int GetSize() const;
49 
50  protected:
51  virtual void Initialize();
52  virtual void Execute();
53  virtual bool IsFinished();
54  virtual void End();
55  virtual void Interrupted();
56  virtual void _Initialize();
57  virtual void _Interrupted();
58  virtual void _Execute();
59  virtual void _End();
60 
61  private:
62  void CancelConflicts(Command* command);
63 
64  // The commands in this group (stored in entries)
65  std::vector<CommandGroupEntry> m_commands;
66 
67  // The active children in this group (stored in entries)
68  std::list<CommandGroupEntry> m_children;
69 
70  // The current command, -1 signifies that none have been run
71  int m_currentCommandIndex = -1;
72 };
73 
74 } // namespace frc
void AddParallel(Command *command)
Adds a new child Command to the group.
Definition: CommandGroup.cpp:108
Definition: RobotController.cpp:14
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
virtual void Initialize()
The initialize method is called the first time this Command is run after being started.
Definition: CommandGroup.cpp:262
void AddSequential(Command *command)
Adds a new Command to the group.
Definition: CommandGroup.cpp:33
virtual void End()
Called when the command ended peacefully.
Definition: CommandGroup.cpp:268
A CommandGroup is a list of commands which are executed in sequence.
Definition: CommandGroup.h:37
virtual void Execute()
The execute method is called repeatedly until this Command either finishes or is canceled.
Definition: CommandGroup.cpp:265
virtual bool IsFinished()
Returns whether this command is finished.
Definition: CommandGroup.cpp:273
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
virtual void Interrupted()
Called when the command ends because somebody called Cancel() or another command shared the same requ...
Definition: CommandGroup.cpp:271