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 #pragma once
9 
10 #include <list>
11 #include <string>
12 #include <vector>
13 
14 #include "Commands/Command.h"
15 #include "Commands/CommandGroupEntry.h"
16 
17 namespace frc {
18 
39 class CommandGroup : public Command {
40  public:
41  CommandGroup() = default;
42  explicit CommandGroup(const std::string& name);
43  virtual ~CommandGroup() = default;
44 
45  void AddSequential(Command* command);
46  void AddSequential(Command* command, double timeout);
47  void AddParallel(Command* command);
48  void AddParallel(Command* command, double timeout);
49  bool IsInterruptible() const;
50  int GetSize() const;
51 
52  protected:
53  virtual void Initialize();
54  virtual void Execute();
55  virtual bool IsFinished();
56  virtual void End();
57  virtual void Interrupted();
58  virtual void _Initialize();
59  virtual void _Interrupted();
60  virtual void _Execute();
61  virtual void _End();
62 
63  private:
64  void CancelConflicts(Command* command);
65 
67  std::vector<CommandGroupEntry> m_commands;
68 
70  std::list<CommandGroupEntry> m_children;
71 
73  int m_currentCommandIndex = -1;
74 };
75 
76 } // namespace frc
void AddParallel(Command *command)
Adds a new child Command to the group.
Definition: CommandGroup.cpp:109
virtual void Initialize()
The initialize method is called the first time this Command is run after being started.
Definition: CommandGroup.cpp:267
void AddSequential(Command *command)
Adds a new Command to the group.
Definition: CommandGroup.cpp:32
virtual void End()
Called when the command ended peacefully.
Definition: CommandGroup.cpp:273
A CommandGroup is a list of commands which are executed in sequence.
Definition: CommandGroup.h:39
virtual void Execute()
The execute method is called repeatedly until this Command either finishes or is canceled.
Definition: CommandGroup.cpp:270
virtual bool IsFinished()
Returns whether this command is finished.
Definition: CommandGroup.cpp:278
The Command class is at the very core of the entire command framework.
Definition: Command.h:52
virtual void Interrupted()
Called when the command ends because somebody called cancel() or another command shared the same requ...
Definition: CommandGroup.cpp:276