WPILibC++
2025.2.1
Loading...
Searching...
No Matches
RepeatCommand.h
Go to the documentation of this file.
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
#pragma once
6
7
#ifdef _WIN32
8
#pragma warning(push)
9
#pragma warning(disable : 4521)
10
#endif
11
12
#include <concepts>
13
#include <memory>
14
#include <utility>
15
16
#include "
frc2/command/Command.h
"
17
#include "
frc2/command/CommandHelper.h
"
18
19
namespace
frc2
{
20
/**
21
* A command that runs another command repeatedly, restarting it when it ends,
22
* until this command is interrupted. Command instances that are passed to it
23
* cannot be added to any other groups, or scheduled individually.
24
*
25
* <p>The rules for command compositions apply: command instances that are
26
* passed to it are owned by the composition and cannot be added to any other
27
* composition or scheduled individually, and the composition requires all
28
* subsystems its components require.
29
*
30
* <p>This class is provided by the NewCommands VendorDep
31
*/
32
class
RepeatCommand
:
public
CommandHelper
<Command, RepeatCommand> {
33
public
:
34
/**
35
* Creates a new RepeatCommand. Will run another command repeatedly,
36
* restarting it whenever it ends, until this command is interrupted.
37
*
38
* @param command the command to run repeatedly
39
*/
40
explicit
RepeatCommand
(std::unique_ptr<Command>&& command);
41
42
/**
43
* Creates a new RepeatCommand. Will run another command repeatedly,
44
* restarting it whenever it ends, until this command is interrupted.
45
*
46
* @param command the command to run repeatedly
47
*/
48
template
<std::derived_from<Command> T>
49
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
50
explicit
RepeatCommand
(T&& command)
51
:
RepeatCommand
(
52
std
::make_unique<
std
::
decay_t
<T>>(
std
::forward<T>(command))) {}
53
54
RepeatCommand
(
RepeatCommand
&& other) =
default
;
55
56
// No copy constructors for command groups
57
RepeatCommand
(
const
RepeatCommand
& other) =
delete
;
58
59
// Prevent template expansion from emulating copy ctor
60
RepeatCommand
(
RepeatCommand
&) =
delete
;
61
62
void
Initialize
()
override
;
63
64
void
Execute
()
override
;
65
66
bool
IsFinished
()
override
;
67
68
void
End
(
bool
interrupted)
override
;
69
70
bool
RunsWhenDisabled
()
const override
;
71
72
Command::InterruptionBehavior
GetInterruptionBehavior
()
const override
;
73
74
void
InitSendable
(
wpi::SendableBuilder
& builder)
override
;
75
76
private
:
77
std::unique_ptr<Command> m_command;
78
bool
m_ended;
79
};
80
}
// namespace frc2
81
82
#ifdef _WIN32
83
#pragma warning(pop)
84
#endif
Command.h
CommandHelper.h
frc2::CommandHelper
CRTP implementation to allow polymorphic decorator functions in Command.
Definition
CommandHelper.h:25
frc2::Command::InterruptionBehavior
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition
Command.h:173
frc2::RepeatCommand
A command that runs another command repeatedly, restarting it when it ends, until this command is int...
Definition
RepeatCommand.h:32
frc2::RepeatCommand::RepeatCommand
RepeatCommand(RepeatCommand &&other)=default
frc2::RepeatCommand::End
void End(bool interrupted) override
frc2::RepeatCommand::InitSendable
void InitSendable(wpi::SendableBuilder &builder) override
frc2::RepeatCommand::Execute
void Execute() override
frc2::RepeatCommand::RunsWhenDisabled
bool RunsWhenDisabled() const override
frc2::RepeatCommand::RepeatCommand
RepeatCommand(T &&command)
Creates a new RepeatCommand.
Definition
RepeatCommand.h:50
frc2::RepeatCommand::Initialize
void Initialize() override
frc2::RepeatCommand::GetInterruptionBehavior
Command::InterruptionBehavior GetInterruptionBehavior() const override
frc2::RepeatCommand::RepeatCommand
RepeatCommand(const RepeatCommand &other)=delete
frc2::RepeatCommand::RepeatCommand
RepeatCommand(RepeatCommand &)=delete
frc2::RepeatCommand::RepeatCommand
RepeatCommand(std::unique_ptr< Command > &&command)
Creates a new RepeatCommand.
frc2::RepeatCommand::IsFinished
bool IsFinished() override
wpi::SendableBuilder
Helper class for building Sendable dashboard representations.
Definition
SendableBuilder.h:21
frc2
Definition
FunctionalCommand.h:13
std
Implement std::hash so that hash_code can be used in STL containers.
Definition
PointerIntPair.h:280
decay_t
typename std::decay< T >::type decay_t
Definition
base.h:311
frc2
command
RepeatCommand.h
Generated on Fri Jan 10 2025 07:37:19 for WPILibC++ by
1.12.0