WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
CommandGroup.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2011-2016. 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 #ifndef __COMMAND_GROUP_H__
9 #define __COMMAND_GROUP_H__
10 
11 #include "Commands/Command.h"
12 #include "Commands/CommandGroupEntry.h"
13 #include <list>
14 #include <vector>
15 
37 class CommandGroup : public Command {
38  public:
39  CommandGroup() = default;
40  CommandGroup(const std::string &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 
65  std::vector<CommandGroupEntry> m_commands;
66 
68  std::list<CommandGroupEntry> m_children;
69 
71  int m_currentCommandIndex = -1;
72 };
73 
74 #endif
A CommandGroup is a list of commands which are executed in sequence.
Definition: CommandGroup.h:37
virtual void Initialize()
The initialize method is called the first time this Command is run after being started.
Definition: CommandGroup.cpp:284
void AddParallel(Command *command)
Adds a new child Command to the group.
Definition: CommandGroup.cpp:119
void AddSequential(Command *command)
Adds a new Command to the group.
Definition: CommandGroup.cpp:32
virtual void Interrupted()
Called when the command ends because somebody called cancel() or another command shared the same requ...
Definition: CommandGroup.cpp:293
The Command class is at the very core of the entire command framework.
Definition: Command.h:54
virtual bool IsFinished()
Returns whether this command is finished.
Definition: CommandGroup.cpp:295
virtual void Execute()
The execute method is called repeatedly until this Command either finishes or is canceled.
Definition: CommandGroup.cpp:287
virtual void End()
Called when the command ended peacefully.
Definition: CommandGroup.cpp:290