2017-01-04 23:48:13 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
2017-01-04 23:48:13 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2017-12-01 20:50:35 -08:00
|
|
|
#include <llvm/Twine.h>
|
2017-01-04 23:48:13 -08:00
|
|
|
|
|
|
|
|
#include "Commands/Command.h"
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* A ConditionalCommand is a Command that starts one of two commands.
|
2017-01-04 23:48:13 -08:00
|
|
|
*
|
2018-01-18 20:04:33 -08:00
|
|
|
* A ConditionalCommand uses the Condition method to determine whether it should
|
|
|
|
|
* run onTrue or onFalse.
|
2017-01-04 23:48:13 -08:00
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* A ConditionalCommand adds the proper Command to the Scheduler during
|
|
|
|
|
* Initialize() and then IsFinished() will return true once that Command has
|
|
|
|
|
* finished executing.
|
2017-01-04 23:48:13 -08:00
|
|
|
*
|
2018-01-18 20:04:33 -08:00
|
|
|
* If no Command is specified for onFalse, the occurrence of that condition
|
2017-11-16 00:33:51 -08:00
|
|
|
* will be a no-op.
|
2017-01-04 23:48:13 -08:00
|
|
|
*
|
2018-01-18 20:04:33 -08:00
|
|
|
* A CondtionalCommand will require the superset of subsystems of the onTrue
|
|
|
|
|
* and onFalse commands.
|
|
|
|
|
*
|
2017-01-04 23:48:13 -08:00
|
|
|
* @see Command
|
|
|
|
|
* @see Scheduler
|
|
|
|
|
*/
|
|
|
|
|
class ConditionalCommand : public Command {
|
|
|
|
|
public:
|
2017-06-30 22:01:21 -07:00
|
|
|
explicit ConditionalCommand(Command* onTrue, Command* onFalse = nullptr);
|
2017-12-01 20:50:35 -08:00
|
|
|
ConditionalCommand(const llvm::Twine& name, Command* onTrue,
|
2017-06-30 22:01:21 -07:00
|
|
|
Command* onFalse = nullptr);
|
2017-01-04 23:48:13 -08:00
|
|
|
virtual ~ConditionalCommand() = default;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* The Condition to test to determine which Command to run.
|
|
|
|
|
*
|
|
|
|
|
* @return true if m_onTrue should be run or false if m_onFalse should be run.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool Condition() = 0;
|
|
|
|
|
|
|
|
|
|
void _Initialize() override;
|
|
|
|
|
void _Cancel() override;
|
|
|
|
|
bool IsFinished() override;
|
2018-01-18 20:04:33 -08:00
|
|
|
void _Interrupted() override;
|
2017-01-04 23:48:13 -08:00
|
|
|
|
|
|
|
|
private:
|
2017-11-16 00:33:51 -08:00
|
|
|
// The Command to execute if Condition() returns true
|
2017-01-04 23:48:13 -08:00
|
|
|
Command* m_onTrue;
|
|
|
|
|
|
2017-11-16 00:33:51 -08:00
|
|
|
// The Command to execute if Condition() returns false
|
2017-01-04 23:48:13 -08:00
|
|
|
Command* m_onFalse;
|
|
|
|
|
|
2017-11-16 00:33:51 -08:00
|
|
|
// Stores command chosen by condition
|
2017-01-04 23:48:13 -08:00
|
|
|
Command* m_chosenCommand = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace frc
|