2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-05-25 22:40:15 -07:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <vector>
|
2016-09-05 13:55:31 -07:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/Twine.h>
|
2017-12-01 20:50:35 -08:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "Commands/Command.h"
|
|
|
|
|
#include "Commands/CommandGroupEntry.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* A CommandGroup is a list of commands which are executed in sequence.
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* Commands in a CommandGroup are added using the AddSequential() method and are
|
|
|
|
|
* called sequentially. CommandGroups are themselves Commands and can be given
|
|
|
|
|
* to other CommandGroups.
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* CommandGroups will carry all of the requirements of their Command
|
|
|
|
|
* subcommands. Additional requirements can be specified by calling Requires()
|
|
|
|
|
* normally in the constructor.
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* CommandGroups can also execute commands in parallel, simply by adding them
|
|
|
|
|
* using AddParallel().
|
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;
|
2018-04-29 23:33:19 -07:00
|
|
|
explicit CommandGroup(const wpi::Twine& name);
|
2015-06-24 01:06:29 -07:00
|
|
|
virtual ~CommandGroup() = default;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
void AddSequential(Command* command);
|
|
|
|
|
void AddSequential(Command* command, double timeout);
|
|
|
|
|
void AddParallel(Command* command);
|
|
|
|
|
void AddParallel(Command* command, double timeout);
|
2015-06-25 15:07:55 -04:00
|
|
|
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:
|
2016-05-20 17:30:37 -07:00
|
|
|
void CancelConflicts(Command* command);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-11-16 00:33:51 -08:00
|
|
|
// The commands in this group (stored in entries)
|
2015-06-24 01:06:29 -07:00
|
|
|
std::vector<CommandGroupEntry> m_commands;
|
|
|
|
|
|
2017-11-16 00:33:51 -08:00
|
|
|
// The active children in this group (stored in entries)
|
2015-06-24 01:06:29 -07:00
|
|
|
std::list<CommandGroupEntry> m_children;
|
|
|
|
|
|
2017-11-16 00:33:51 -08: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
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|