2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2011. All Rights Reserved.
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#ifndef __COMMAND_GROUP_H__
|
|
|
|
|
#define __COMMAND_GROUP_H__
|
|
|
|
|
|
|
|
|
|
#include "Commands/Command.h"
|
|
|
|
|
#include "Commands/CommandGroupEntry.h"
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A {@link CommandGroup} is a list of commands which are executed in sequence.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* <p>Commands in a {@link CommandGroup} are added using the {@link
|
|
|
|
|
* CommandGroup#AddSequential(Command) AddSequential(...)} method
|
2013-12-15 18:30:16 -05:00
|
|
|
* and are called sequentially.
|
|
|
|
|
* {@link CommandGroup CommandGroups} are themselves {@link Command Commands}
|
|
|
|
|
* and can be given to other {@link CommandGroup CommandGroups}.</p>
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* <p>{@link CommandGroup CommandGroups} will carry all of the requirements of
|
|
|
|
|
* their {@link Command subcommands}. Additional
|
|
|
|
|
* requirements can be specified by calling {@link
|
|
|
|
|
*CommandGroup#Requires(Subsystem) Requires(...)}
|
2013-12-15 18:30:16 -05:00
|
|
|
* normally in the constructor.</P>
|
|
|
|
|
*
|
|
|
|
|
* <p>CommandGroups can also execute commands in parallel, simply by adding them
|
|
|
|
|
* using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.</p>
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @see Command
|
|
|
|
|
* @see Subsystem
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class CommandGroup : public Command {
|
|
|
|
|
public:
|
2015-06-24 01:06:29 -07:00
|
|
|
CommandGroup() = default;
|
2015-06-30 15:01:20 -04:00
|
|
|
CommandGroup(const std::string &name);
|
2015-06-24 01:06:29 -07:00
|
|
|
virtual ~CommandGroup() = default;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
void AddSequential(Command *command);
|
|
|
|
|
void AddSequential(Command *command, double timeout);
|
|
|
|
|
void AddParallel(Command *command);
|
|
|
|
|
void AddParallel(Command *command, double timeout);
|
|
|
|
|
bool IsInterruptible() const;
|
|
|
|
|
int GetSize() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
|
|
|
|
virtual void Initialize();
|
|
|
|
|
virtual void Execute();
|
|
|
|
|
virtual bool IsFinished();
|
|
|
|
|
virtual void End();
|
|
|
|
|
virtual void Interrupted();
|
|
|
|
|
virtual void _Initialize();
|
|
|
|
|
virtual void _Interrupted();
|
|
|
|
|
virtual void _Execute();
|
|
|
|
|
virtual void _End();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
|
|
|
|
void CancelConflicts(Command *command);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/** The commands in this group (stored in entries) */
|
2015-06-24 01:06:29 -07:00
|
|
|
std::vector<CommandGroupEntry> m_commands;
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/** The active children in this group (stored in entries) */
|
2015-06-24 01:06:29 -07:00
|
|
|
std::list<CommandGroupEntry> m_children;
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/** The current command, -1 signifies that none have been run */
|
2015-06-24 01:06:29 -07:00
|
|
|
int m_currentCommandIndex = -1;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|