WPILibC++ 2023.4.3
PowerDistributionSim.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 PowerDistribution;
14
15namespace sim {
16
17/**
18 * Class to control a simulated Power Distribution Panel (PowerDistribution).
19 */
21 public:
22 /**
23 * Constructs from a PowerDistribution module number (CAN ID).
24 *
25 * @param module module number
26 */
27 explicit PowerDistributionSim(int module = 0);
28
29 /**
30 * Constructs from a PowerDistribution object.
31 *
32 * @param pdp PowerDistribution to simulate
33 */
35
36 /**
37 * Register a callback to be run when the PowerDistribution is initialized.
38 *
39 * @param callback the callback
40 * @param initialNotify whether to run the callback with the initial state
41 * @return the CallbackStore object associated with this callback
42 */
43 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
44 NotifyCallback callback, bool initialNotify);
45
46 /**
47 * Check whether the PowerDistribution has been initialized.
48 *
49 * @return true if initialized
50 */
51 bool GetInitialized() const;
52
53 /**
54 * Define whether the PowerDistribution has been initialized.
55 *
56 * @param initialized whether this object is initialized
57 */
58 void SetInitialized(bool initialized);
59
60 /**
61 * Register a callback to be run whenever the PowerDistribution temperature
62 * changes.
63 *
64 * @param callback the callback
65 * @param initialNotify whether to call the callback with the initial state
66 * @return the CallbackStore object associated with this callback
67 */
68 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
69 NotifyCallback callback, bool initialNotify);
70
71 /**
72 * Check the temperature of the PowerDistribution.
73 *
74 * @return the PowerDistribution temperature
75 */
76 double GetTemperature() const;
77
78 /**
79 * Define the PowerDistribution temperature.
80 *
81 * @param temperature the new PowerDistribution temperature
82 */
83 void SetTemperature(double temperature);
84
85 /**
86 * Register a callback to be run whenever the PowerDistribution voltage
87 * changes.
88 *
89 * @param callback the callback
90 * @param initialNotify whether to call the callback with the initial state
91 * @return the CallbackStore object associated with this callback
92 */
93 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterVoltageCallback(
94 NotifyCallback callback, bool initialNotify);
95
96 /**
97 * Check the PowerDistribution voltage.
98 *
99 * @return the PowerDistribution voltage.
100 */
101 double GetVoltage() const;
102
103 /**
104 * Set the PowerDistribution voltage.
105 *
106 * @param voltage the new PowerDistribution voltage
107 */
108 void SetVoltage(double voltage);
109
110 /**
111 * Register a callback to be run whenever the current of a specific channel
112 * changes.
113 *
114 * @param channel the channel
115 * @param callback the callback
116 * @param initialNotify whether to call the callback with the initial state
117 * @return the CallbackStore object associated with this callback
118 */
119 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterCurrentCallback(
120 int channel, NotifyCallback callback, bool initialNotify);
121
122 /**
123 * Read the current in one of the PowerDistribution channels.
124 *
125 * @param channel the channel to check
126 * @return the current in the given channel
127 */
128 double GetCurrent(int channel) const;
129
130 /**
131 * Change the current in the given channel.
132 *
133 * @param channel the channel to edit
134 * @param current the new current for the channel
135 */
136 void SetCurrent(int channel, double current);
137
138 /**
139 * Read the current of all of the PowerDistribution channels.
140 *
141 * @param currents output array; set to the current in each channel. The
142 * array must be big enough to hold all the PowerDistribution
143 * channels
144 * @param length length of output array
145 */
146 void GetAllCurrents(double* currents, int length) const;
147
148 /**
149 * Change the current in all of the PowerDistribution channels.
150 *
151 * @param currents array containing the current values for each channel. The
152 * array must be big enough to hold all the PowerDistribution
153 * channels
154 * @param length length of array
155 */
156 void SetAllCurrents(const double* currents, int length);
157
158 /**
159 * Reset all PowerDistribution simulation data.
160 */
161 void ResetData();
162
163 private:
164 int m_index;
165};
166} // namespace sim
167} // namespace frc
Class for getting voltage, current, temperature, power and energy from the CTRE Power Distribution Pa...
Definition: PowerDistribution.h:18
Class to control a simulated Power Distribution Panel (PowerDistribution).
Definition: PowerDistributionSim.h:20
bool GetInitialized() const
Check whether the PowerDistribution has been initialized.
void ResetData()
Reset all PowerDistribution simulation data.
std::unique_ptr< CallbackStore > RegisterCurrentCallback(int channel, NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the current of a specific channel changes.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the PowerDistribution is initialized.
void SetVoltage(double voltage)
Set the PowerDistribution voltage.
void SetAllCurrents(const double *currents, int length)
Change the current in all of the PowerDistribution channels.
void SetInitialized(bool initialized)
Define whether the PowerDistribution has been initialized.
void SetTemperature(double temperature)
Define the PowerDistribution temperature.
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the PowerDistribution voltage changes.
double GetVoltage() const
Check the PowerDistribution voltage.
std::unique_ptr< CallbackStore > RegisterTemperatureCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the PowerDistribution temperature changes.
PowerDistributionSim(int module=0)
Constructs from a PowerDistribution module number (CAN ID).
void GetAllCurrents(double *currents, int length) const
Read the current of all of the PowerDistribution channels.
double GetTemperature() const
Check the temperature of the PowerDistribution.
void SetCurrent(int channel, double current)
Change the current in the given channel.
PowerDistributionSim(const PowerDistribution &pdp)
Constructs from a PowerDistribution object.
double GetCurrent(int channel) const
Read the current in one of the PowerDistribution channels.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagFieldLayout.h:22