WPILibC++ 2023.4.3
CommandBase.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#include <initializer_list>
8#include <span>
9#include <string>
10#include <string_view>
11
12#include <wpi/SmallSet.h>
15
17
18namespace frc2 {
19/**
20 * A Sendable base class for Commands.
21 *
22 * This class is provided by the NewCommands VendorDep
23 */
24class CommandBase : public Command,
25 public wpi::Sendable,
26 public wpi::SendableHelper<CommandBase> {
27 public:
28 /**
29 * Adds the specified Subsystem requirements to the command.
30 *
31 * The scheduler will prevent two commands that require the same subsystem
32 * from being scheduled simultaneously.
33 *
34 * Note that the scheduler determines the requirements of a command when it
35 * is scheduled, so this method should normally be called from the command's
36 * constructor.
37 *
38 * @param requirements the Subsystem requirements to add
39 */
40 void AddRequirements(std::initializer_list<Subsystem*> requirements);
41
42 /**
43 * Adds the specified Subsystem requirements to the command.
44 *
45 * The scheduler will prevent two commands that require the same subsystem
46 * from being scheduled simultaneously.
47 *
48 * Note that the scheduler determines the requirements of a command when it
49 * is scheduled, so this method should normally be called from the command's
50 * constructor.
51 *
52 * @param requirements the Subsystem requirements to add
53 */
54 void AddRequirements(std::span<Subsystem* const> requirements);
55
56 /**
57 * Adds the specified Subsystem requirements to the command.
58 *
59 * The scheduler will prevent two commands that require the same subsystem
60 * from being scheduled simultaneously.
61 *
62 * Note that the scheduler determines the requirements of a command when it
63 * is scheduled, so this method should normally be called from the command's
64 * constructor.
65 *
66 * @param requirements the Subsystem requirements to add
67 */
69
70 /**
71 * Adds the specified Subsystem requirement to the command.
72 *
73 * The scheduler will prevent two commands that require the same subsystem
74 * from being scheduled simultaneously.
75 *
76 * Note that the scheduler determines the requirements of a command when it
77 * is scheduled, so this method should normally be called from the command's
78 * constructor.
79 *
80 * @param requirement the Subsystem requirement to add
81 */
82 void AddRequirements(Subsystem* requirement);
83
84 /**
85 * Gets the Subsystem requirements of the command.
86 *
87 * @return the Command's Subsystem requirements
88 */
90
91 /**
92 * Sets the name of this Command.
93 *
94 * @param name name
95 */
96 void SetName(std::string_view name) override;
97
98 /**
99 * Gets the name of this Command.
100 *
101 * @return Name
102 */
103 std::string GetName() const override;
104
105 /**
106 * Gets the subsystem name of this Command.
107 *
108 * @return Subsystem name
109 */
110 std::string GetSubsystem() const;
111
112 /**
113 * Sets the subsystem name of this Command.
114 *
115 * @param subsystem subsystem name
116 */
118
119 void InitSendable(wpi::SendableBuilder& builder) override;
120
121 protected:
124};
125} // namespace frc2
This file defines the SmallSet class.
A Sendable base class for Commands.
Definition: CommandBase.h:26
void SetName(std::string_view name) override
Sets the name of this Command.
wpi::SmallSet< Subsystem *, 4 > m_requirements
Definition: CommandBase.h:123
wpi::SmallSet< Subsystem *, 4 > GetRequirements() const override
Gets the Subsystem requirements of the command.
void AddRequirements(wpi::SmallSet< Subsystem *, 4 > requirements)
Adds the specified Subsystem requirements to the command.
void AddRequirements(std::initializer_list< Subsystem * > requirements)
Adds the specified Subsystem requirements to the command.
void AddRequirements(std::span< Subsystem *const > requirements)
Adds the specified Subsystem requirements to the command.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
void AddRequirements(Subsystem *requirement)
Adds the specified Subsystem requirement to the command.
std::string GetName() const override
Gets the name of this Command.
std::string GetSubsystem() const
Gets the subsystem name of this Command.
void SetSubsystem(std::string_view subsystem)
Sets the subsystem name of this Command.
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:47
A robot subsystem.
Definition: Subsystem.h:39
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
basic_string_view< char > string_view
Definition: core.h:520
Definition: InstantCommand.h:14