2017-01-04 23:48:13 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-09-29 20:35:41 -07:00
|
|
|
/* Copyright (c) 2017-2019 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
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/Twine.h>
|
2017-01-04 23:48:13 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/commands/Command.h"
|
2017-01-04 23:48:13 -08:00
|
|
|
|
|
|
|
|
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
|
|
|
*
|
2019-09-29 20:35:41 -07:00
|
|
|
* A ConditionalCommand will require the superset of subsystems of the onTrue
|
2018-01-18 20:04:33 -08:00
|
|
|
* and onFalse commands.
|
|
|
|
|
*
|
2017-01-04 23:48:13 -08:00
|
|
|
* @see Command
|
|
|
|
|
* @see Scheduler
|
|
|
|
|
*/
|
|
|
|
|
class ConditionalCommand : public Command {
|
|
|
|
|
public:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Creates a new ConditionalCommand with given onTrue and onFalse Commands.
|
|
|
|
|
*
|
|
|
|
|
* @param onTrue The Command to execute if Condition() returns true
|
|
|
|
|
* @param onFalse The Command to execute if Condition() returns false
|
|
|
|
|
*/
|
2017-06-30 22:01:21 -07:00
|
|
|
explicit ConditionalCommand(Command* onTrue, Command* onFalse = nullptr);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new ConditionalCommand with given onTrue and onFalse Commands.
|
|
|
|
|
*
|
|
|
|
|
* @param name The name for this command group
|
|
|
|
|
* @param onTrue The Command to execute if Condition() returns true
|
|
|
|
|
* @param onFalse The Command to execute if Condition() returns false
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
ConditionalCommand(const wpi::Twine& name, Command* onTrue,
|
2017-06-30 22:01:21 -07:00
|
|
|
Command* onFalse = nullptr);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2017-01-04 23:48:13 -08:00
|
|
|
virtual ~ConditionalCommand() = default;
|
|
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
ConditionalCommand(ConditionalCommand&&) = default;
|
|
|
|
|
ConditionalCommand& operator=(ConditionalCommand&&) = default;
|
|
|
|
|
|
2017-01-04 23:48:13 -08:00
|
|
|
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
|