2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-09-14 04:33:19 +03:00
|
|
|
#include <memory>
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <span>
|
2022-09-14 04:33:19 +03:00
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <wpi/SmallVector.h>
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include "frc2/command/CommandBase.h"
|
|
|
|
|
#include "frc2/command/CommandHelper.h"
|
|
|
|
|
#include "frc2/command/SetUtilities.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
/**
|
|
|
|
|
* Schedules the given commands when this command is initialized, and ends when
|
|
|
|
|
* all the commands are no longer scheduled. Useful for forking off from
|
|
|
|
|
* CommandGroups. If this command is interrupted, it will cancel all of the
|
|
|
|
|
* commands.
|
2022-01-08 11:11:34 -08:00
|
|
|
*
|
|
|
|
|
* This class is provided by the NewCommands VendorDep
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
|
|
|
|
class ProxyScheduleCommand
|
|
|
|
|
: public CommandHelper<CommandBase, ProxyScheduleCommand> {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new ProxyScheduleCommand that schedules the given commands when
|
|
|
|
|
* initialized, and ends when they are all no longer scheduled.
|
|
|
|
|
*
|
|
|
|
|
* @param toSchedule the commands to schedule
|
|
|
|
|
*/
|
2022-10-15 16:33:14 -07:00
|
|
|
explicit ProxyScheduleCommand(std::span<Command* const> toSchedule);
|
2021-06-06 19:51:14 -07:00
|
|
|
|
|
|
|
|
explicit ProxyScheduleCommand(Command* toSchedule);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2022-09-14 04:33:19 +03:00
|
|
|
/**
|
|
|
|
|
* Creates a new ProxyScheduleCommand that schedules the given command when
|
|
|
|
|
* initialized, and ends when it is no longer scheduled.
|
|
|
|
|
*
|
|
|
|
|
* <p>Note that this constructor passes ownership of the given command to the
|
|
|
|
|
* returned ProxyScheduleCommand.
|
|
|
|
|
*
|
|
|
|
|
* @param toSchedule the command to schedule
|
|
|
|
|
*/
|
|
|
|
|
explicit ProxyScheduleCommand(std::unique_ptr<Command>&& toSchedule);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2022-09-14 04:33:19 +03:00
|
|
|
ProxyScheduleCommand(ProxyScheduleCommand&& other) = default;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
void Initialize() override;
|
|
|
|
|
|
|
|
|
|
void End(bool interrupted) override;
|
|
|
|
|
|
|
|
|
|
void Execute() override;
|
|
|
|
|
|
|
|
|
|
bool IsFinished() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
wpi::SmallVector<Command*, 4> m_toSchedule;
|
2022-09-14 04:33:19 +03:00
|
|
|
std::unique_ptr<Command> m_owning;
|
2019-08-25 23:55:59 -04:00
|
|
|
bool m_finished{false};
|
|
|
|
|
};
|
|
|
|
|
} // namespace frc2
|