2019-08-25 23:55:59 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-01-01 20:09:17 -08:00
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
2019-08-25 23:55:59 -04: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
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include <functional>
|
|
|
|
|
#include <initializer_list>
|
|
|
|
|
|
2020-01-01 20:09:17 -08:00
|
|
|
#include <wpi/ArrayRef.h>
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include "frc2/command/CommandBase.h"
|
|
|
|
|
#include "frc2/command/CommandHelper.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
/**
|
2020-08-31 00:33:11 -07:00
|
|
|
* A command that runs a given runnable when it is initialized, and another
|
2019-08-25 23:55:59 -04:00
|
|
|
* runnable when it ends. Useful for running and then stopping a motor, or
|
|
|
|
|
* extending and then retracting a solenoid. Has no end condition as-is; either
|
2019-10-19 11:13:33 -04:00
|
|
|
* subclass it or use Command.WithTimeout() or Command.WithInterrupt() to give
|
|
|
|
|
* it one.
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
|
|
|
|
class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new StartEndCommand. Will run the given runnables when the
|
|
|
|
|
* command starts and when it ends.
|
|
|
|
|
*
|
|
|
|
|
* @param onInit the Runnable to run on command init
|
|
|
|
|
* @param onEnd the Runnable to run on command end
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
|
|
|
|
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
|
2020-01-01 20:09:17 -08:00
|
|
|
std::initializer_list<Subsystem*> requirements);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new StartEndCommand. Will run the given runnables when the
|
|
|
|
|
* command starts and when it ends.
|
|
|
|
|
*
|
|
|
|
|
* @param onInit the Runnable to run on command init
|
|
|
|
|
* @param onEnd the Runnable to run on command end
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
|
|
|
|
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
|
|
|
|
|
wpi::ArrayRef<Subsystem*> requirements = {});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
StartEndCommand(StartEndCommand&& other) = default;
|
|
|
|
|
|
|
|
|
|
StartEndCommand(const StartEndCommand& other);
|
|
|
|
|
|
|
|
|
|
void Initialize() override;
|
|
|
|
|
|
|
|
|
|
void End(bool interrupted) override;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
std::function<void()> m_onInit;
|
|
|
|
|
std::function<void()> m_onEnd;
|
|
|
|
|
};
|
|
|
|
|
} // namespace frc2
|