WPILibC++ 2025.0.0-alpha-1-9-ga2beb75
CTREPCMSim.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
12
13namespace frc::sim {
14
15/**
16 * Class to control a simulated Pneumatic Control Module (PCM).
17 */
19 public:
20 /**
21 * Constructs with the default PCM module number (CAN ID).
22 */
24
25 /**
26 * Constructs from a PCM module number (CAN ID).
27 *
28 * @param module module number
29 */
30 explicit CTREPCMSim(int module);
31
32 explicit CTREPCMSim(const PneumaticsBase& pneumatics);
33
34 ~CTREPCMSim() override = default;
35
36 [[nodiscard]]
37 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
38 NotifyCallback callback, bool initialNotify) override;
39
40 bool GetInitialized() const override;
41
42 void SetInitialized(bool initialized) override;
43
44 [[nodiscard]]
45 std::unique_ptr<CallbackStore> RegisterSolenoidOutputCallback(
46 int channel, NotifyCallback callback, bool initialNotify) override;
47
48 bool GetSolenoidOutput(int channel) const override;
49
50 void SetSolenoidOutput(int channel, bool solenoidOutput) override;
51
52 [[nodiscard]]
53 std::unique_ptr<CallbackStore> RegisterCompressorOnCallback(
54 NotifyCallback callback, bool initialNotify) override;
55
56 bool GetCompressorOn() const override;
57
58 void SetCompressorOn(bool compressorOn) override;
59
60 /**
61 * Register a callback to be run whenever the closed loop state changes.
62 *
63 * @param callback the callback
64 * @param initialNotify whether the callback should be called with the
65 * initial value
66 * @return the CallbackStore object associated with this callback
67 */
68 [[nodiscard]]
69 std::unique_ptr<CallbackStore> RegisterClosedLoopEnabledCallback(
70 NotifyCallback callback, bool initialNotify);
71
72 /**
73 * Check whether the closed loop compressor control is active.
74 *
75 * @return true if active
76 */
78
79 /**
80 * Turn on/off the closed loop control of the compressor.
81 *
82 * @param closedLoopEnabled whether the control loop is active
83 */
84 void SetClosedLoopEnabled(bool closedLoopEnabled);
85
86 /**
87 * Register a callback to be run whenever the pressure switch value changes.
88 *
89 * @param callback the callback
90 * @param initialNotify whether the callback should be called with the
91 * initial value
92 * @return the CallbackStore object associated with this callback
93 */
94 [[nodiscard]]
95 std::unique_ptr<CallbackStore> RegisterPressureSwitchCallback(
96 NotifyCallback callback, bool initialNotify) override;
97
98 /**
99 * Check the value of the pressure switch.
100 *
101 * @return the pressure switch value
102 */
103 bool GetPressureSwitch() const override;
104
105 /**
106 * Set the value of the pressure switch.
107 *
108 * @param pressureSwitch the new value
109 */
110 void SetPressureSwitch(bool pressureSwitch) override;
111
112 /**
113 * Register a callback to be run whenever the compressor current changes.
114 *
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]]
120 std::unique_ptr<CallbackStore> RegisterCompressorCurrentCallback(
121 NotifyCallback callback, bool initialNotify) override;
122
123 /**
124 * Read the compressor current.
125 *
126 * @return the current of the compressor connected to this module
127 */
128 double GetCompressorCurrent() const override;
129
130 /**
131 * Set the compressor current.
132 *
133 * @param compressorCurrent the new compressor current
134 */
135 void SetCompressorCurrent(double compressorCurrent) override;
136
137 uint8_t GetAllSolenoidOutputs() const override;
138
139 void SetAllSolenoidOutputs(uint8_t outputs) override;
140
141 void ResetData() override;
142};
143} // namespace frc::sim
Base class for pneumatics devices.
Definition: PneumaticsBase.h:25
Class to control a simulated Pneumatic Control Module (PCM).
Definition: CTREPCMSim.h:18
std::unique_ptr< CallbackStore > RegisterSolenoidOutputCallback(int channel, NotifyCallback callback, bool initialNotify) override
Register a callback to be run when the solenoid output on a channel changes.
uint8_t GetAllSolenoidOutputs() const override
Get the current value of all solenoid outputs.
void SetSolenoidOutput(int channel, bool solenoidOutput) override
Change the solenoid output on a specific channel.
double GetCompressorCurrent() const override
Read the compressor current.
void SetClosedLoopEnabled(bool closedLoopEnabled)
Turn on/off the closed loop control of the compressor.
void SetAllSolenoidOutputs(uint8_t outputs) override
Change all of the solenoid outputs.
void SetCompressorOn(bool compressorOn) override
Set whether the compressor is active.
std::unique_ptr< CallbackStore > RegisterPressureSwitchCallback(NotifyCallback callback, bool initialNotify) override
Register a callback to be run whenever the pressure switch value changes.
~CTREPCMSim() override=default
bool GetClosedLoopEnabled() const
Check whether the closed loop compressor control is active.
CTREPCMSim(const PneumaticsBase &pneumatics)
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify) override
Register a callback to be run when the PCM/PH is initialized.
void SetPressureSwitch(bool pressureSwitch) override
Set the value of the pressure switch.
std::unique_ptr< CallbackStore > RegisterCompressorCurrentCallback(NotifyCallback callback, bool initialNotify) override
Register a callback to be run whenever the compressor current changes.
bool GetInitialized() const override
Check whether the PCM/PH has been initialized.
bool GetPressureSwitch() const override
Check the value of the pressure switch.
std::unique_ptr< CallbackStore > RegisterCompressorOnCallback(NotifyCallback callback, bool initialNotify) override
Register a callback to be run when the compressor activates.
CTREPCMSim(int module)
Constructs from a PCM module number (CAN ID).
void SetInitialized(bool initialized) override
Define whether the PCM/PH has been initialized.
bool GetSolenoidOutput(int channel) const override
Check the solenoid output on a specific channel.
void SetCompressorCurrent(double compressorCurrent) override
Set the compressor current.
CTREPCMSim()
Constructs with the default PCM module number (CAN ID).
bool GetCompressorOn() const override
Check if the compressor is on.
void ResetData() override
Reset all simulation data for this object.
std::unique_ptr< CallbackStore > RegisterClosedLoopEnabledCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the closed loop state changes.
Definition: PneumaticsBaseSim.h:15
Definition: ADXL345Sim.h:14
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14