WPILibC++ 2024.3.2
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]]
44 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
45 NotifyCallback callback, bool initialNotify);
46
47 /**
48 * Check whether the PowerDistribution has been initialized.
49 *
50 * @return true if initialized
51 */
52 bool GetInitialized() const;
53
54 /**
55 * Define whether the PowerDistribution has been initialized.
56 *
57 * @param initialized whether this object is initialized
58 */
59 void SetInitialized(bool initialized);
60
61 /**
62 * Register a callback to be run whenever the PowerDistribution temperature
63 * changes.
64 *
65 * @param callback the callback
66 * @param initialNotify whether to call the callback with the initial state
67 * @return the CallbackStore object associated with this callback
68 */
69 [[nodiscard]]
70 std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
71 NotifyCallback callback, bool initialNotify);
72
73 /**
74 * Check the temperature of the PowerDistribution.
75 *
76 * @return the PowerDistribution temperature
77 */
78 double GetTemperature() const;
79
80 /**
81 * Define the PowerDistribution temperature.
82 *
83 * @param temperature the new PowerDistribution temperature
84 */
85 void SetTemperature(double temperature);
86
87 /**
88 * Register a callback to be run whenever the PowerDistribution voltage
89 * changes.
90 *
91 * @param callback the callback
92 * @param initialNotify whether to call the callback with the initial state
93 * @return the CallbackStore object associated with this callback
94 */
95 [[nodiscard]]
96 std::unique_ptr<CallbackStore> RegisterVoltageCallback(
97 NotifyCallback callback, bool initialNotify);
98
99 /**
100 * Check the PowerDistribution voltage.
101 *
102 * @return the PowerDistribution voltage.
103 */
104 double GetVoltage() const;
105
106 /**
107 * Set the PowerDistribution voltage.
108 *
109 * @param voltage the new PowerDistribution voltage
110 */
111 void SetVoltage(double voltage);
112
113 /**
114 * Register a callback to be run whenever the current of a specific channel
115 * changes.
116 *
117 * @param channel the channel
118 * @param callback the callback
119 * @param initialNotify whether to call the callback with the initial state
120 * @return the CallbackStore object associated with this callback
121 */
122 [[nodiscard]]
123 std::unique_ptr<CallbackStore> RegisterCurrentCallback(
124 int channel, NotifyCallback callback, bool initialNotify);
125
126 /**
127 * Read the current in one of the PowerDistribution channels.
128 *
129 * @param channel the channel to check
130 * @return the current in the given channel
131 */
132 double GetCurrent(int channel) const;
133
134 /**
135 * Change the current in the given channel.
136 *
137 * @param channel the channel to edit
138 * @param current the new current for the channel
139 */
140 void SetCurrent(int channel, double current);
141
142 /**
143 * Read the current of all of the PowerDistribution channels.
144 *
145 * @param currents output array; set to the current in each channel. The
146 * array must be big enough to hold all the PowerDistribution
147 * channels
148 * @param length length of output array
149 */
150 void GetAllCurrents(double* currents, int length) const;
151
152 /**
153 * Change the current in all of the PowerDistribution channels.
154 *
155 * @param currents array containing the current values for each channel. The
156 * array must be big enough to hold all the PowerDistribution
157 * channels
158 * @param length length of array
159 */
160 void SetAllCurrents(const double* currents, int length);
161
162 /**
163 * Reset all PowerDistribution simulation data.
164 */
165 void ResetData();
166
167 private:
168 int m_index;
169};
170} // namespace sim
171} // 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: AprilTagPoseEstimator.h:15