WPILibC++ 2024.3.2
NotifierCommand.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 <functional>
8
9#include <frc/Notifier.h>
10#include <units/time.h>
11
15
16namespace frc2 {
17/**
18 * A command that starts a notifier to run the given runnable periodically in a
19 * separate thread. Has no end condition as-is; either subclass it or use
20 * Command::WithTimeout(double) or Command::Until(BooleanSupplier) to
21 * give it one.
22 *
23 * <p>WARNING: Do not use this class unless you are confident in your ability to
24 * make the executed code thread-safe. If you do not know what "thread-safe"
25 * means, that is a good sign that you should not use this class.
26 *
27 * This class is provided by the NewCommands VendorDep
28 */
29class NotifierCommand : public CommandHelper<Command, NotifierCommand> {
30 public:
31 /**
32 * Creates a new NotifierCommand.
33 *
34 * @param toRun the runnable for the notifier to run
35 * @param period the period at which the notifier should run
36 * @param requirements the subsystems required by this command
37 */
38 NotifierCommand(std::function<void()> toRun, units::second_t period,
39 Requirements requirements = {});
40
42
44
45 void Initialize() override;
46
47 void End(bool interrupted) override;
48
49 private:
50 std::function<void()> m_toRun;
51 frc::Notifier m_notifier;
52 units::second_t m_period;
53};
54} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:27
A command that starts a notifier to run the given runnable periodically in a separate thread.
Definition: NotifierCommand.h:29
NotifierCommand(NotifierCommand &&other)
NotifierCommand(std::function< void()> toRun, units::second_t period, Requirements requirements={})
Creates a new NotifierCommand.
NotifierCommand(const NotifierCommand &other)
void Initialize() override
void End(bool interrupted) override
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition: Requirements.h:20
Notifiers run a user-provided callback function on a separate thread.
Definition: Notifier.h:29
Definition: TrapezoidProfileSubsystem.h:12