WPILibC++ 2024.3.2
AnalogOutputSim.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 <memory>
8
10
11namespace frc {
12
13class AnalogOutput;
14
15namespace sim {
16
17/**
18 * Class to control a simulated analog output.
19 */
21 public:
22 /**
23 * Constructs from an AnalogOutput object.
24 *
25 * @param analogOutput AnalogOutput to simulate
26 */
27 explicit AnalogOutputSim(const AnalogOutput& analogOutput);
28
29 /**
30 * Constructs from an analog output channel number.
31 *
32 * @param channel Channel number
33 */
34 explicit AnalogOutputSim(int channel);
35
36 /**
37 * Register a callback to be run whenever the voltage changes.
38 *
39 * @param callback the callback
40 * @param initialNotify whether to call the callback with the initial state
41 * @return the CallbackStore object associated with this callback
42 */
43 [[nodiscard]]
44 std::unique_ptr<CallbackStore> RegisterVoltageCallback(
45 NotifyCallback callback, bool initialNotify);
46
47 /**
48 * Read the analog output voltage.
49 *
50 * @return the voltage on this analog output
51 */
52 double GetVoltage() const;
53
54 /**
55 * Set the analog output voltage.
56 *
57 * @param voltage the new voltage on this analog output
58 */
59 void SetVoltage(double voltage);
60
61 /**
62 * Register a callback to be run when this analog output is initialized.
63 *
64 * @param callback the callback
65 * @param initialNotify whether to run the callback with the initial state
66 * @return the CallbackStore object associated with this callback
67 */
68 [[nodiscard]]
69 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
70 NotifyCallback callback, bool initialNotify);
71
72 /**
73 * Check whether this analog output has been initialized.
74 *
75 * @return true if initialized
76 */
77 bool GetInitialized() const;
78
79 /**
80 * Define whether this analog output has been initialized.
81 *
82 * @param initialized whether this object is initialized
83 */
84 void SetInitialized(bool initialized);
85
86 /**
87 * Reset all simulation data on this object.
88 */
89 void ResetData();
90
91 private:
92 int m_index;
93};
94} // namespace sim
95} // namespace frc
MXP analog output class.
Definition: AnalogOutput.h:17
Class to control a simulated analog output.
Definition: AnalogOutputSim.h:20
void SetVoltage(double voltage)
Set the analog output voltage.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when this analog output is initialized.
void ResetData()
Reset all simulation data on this object.
double GetVoltage() const
Read the analog output voltage.
void SetInitialized(bool initialized)
Define whether this analog output has been initialized.
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the voltage changes.
AnalogOutputSim(int channel)
Constructs from an analog output channel number.
bool GetInitialized() const
Check whether this analog output has been initialized.
AnalogOutputSim(const AnalogOutput &analogOutput)
Constructs from an AnalogOutput object.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagPoseEstimator.h:15