Command::IsFinished() must be overriden by subclasses again (#353)

Documentation was added for InstantCommand and TimedCommand.
This commit is contained in:
Tyler Veness
2016-11-19 00:26:22 -08:00
committed by Peter Johnson
parent 140c365e4b
commit b25a7cb370
8 changed files with 55 additions and 27 deletions

View File

@@ -84,7 +84,25 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener {
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
/**
* Returns whether this command is finished.
* If it is, then the command will be removed and {@link Command#end() end()}
* will be called.
*
* <p>It may be useful for a team to reference the {@link Command#isTimedOut()
* isTimedOut()} method for time-sensitive commands.</p>
*
* <p>Returning false will result in the command never ending automatically.
* It may still be cancelled manually or interrupted by another command.
* Returning true will result in the command executing once and finishing
* immediately. We recommend using {@link InstantCommand} for this.</p>
*
* @return whether this command is finished.
* @see Command#isTimedOut() isTimedOut()
*/
virtual bool IsFinished() = 0;
virtual void End();
virtual void Interrupted();

View File

@@ -13,6 +13,12 @@
namespace frc {
/**
* This command will execute once, then finish immediately afterward.
*
* <p>Subclassing {@link InstantCommand} is shorthand for returning true from
* {@link Command isFinished}.
*/
class InstantCommand : public Command {
public:
explicit InstantCommand(const std::string& name);
@@ -20,7 +26,7 @@ class InstantCommand : public Command {
virtual ~InstantCommand() = default;
protected:
virtual bool IsFinished();
bool IsFinished() override;
};
} // namespace frc

View File

@@ -13,6 +13,10 @@
namespace frc {
/**
* A {@link TimedCommand} will wait for a timeout before finishing.
* {@link TimedCommand} is used to execute a command for a given amount of time.
*/
class TimedCommand : public Command {
public:
TimedCommand(const std::string& name, double timeout);
@@ -20,7 +24,7 @@ class TimedCommand : public Command {
virtual ~TimedCommand() = default;
protected:
virtual bool IsFinished();
bool IsFinished() override;
};
} // namespace frc