WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
Solenoid.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
9#include <hal/Types.h>
10#include <units/time.h>
13
14#include "frc/PneumaticsBase.h"
16
17namespace frc {
18
19/**
20 * Solenoid class for running high voltage Digital Output on a pneumatics
21 * module.
22 *
23 * The Solenoid class is typically used for pneumatics solenoids, but could be
24 * used for any device within the current spec of the module.
25 */
26class Solenoid : public wpi::Sendable, public wpi::SendableHelper<Solenoid> {
27 public:
28 /**
29 * Constructs a solenoid for a specified module and type.
30 *
31 * @param module The module ID to use.
32 * @param moduleType The module type to use.
33 * @param channel The channel the solenoid is on.
34 */
35 Solenoid(int module, PneumaticsModuleType moduleType, int channel);
36
37 /**
38 * Constructs a solenoid for a default module and specified type.
39 *
40 * @param moduleType The module type to use.
41 * @param channel The channel the solenoid is on.
42 */
43 Solenoid(PneumaticsModuleType moduleType, int channel);
44
45 ~Solenoid() override;
46
47 Solenoid(Solenoid&&) = default;
49
50 /**
51 * Set the value of a solenoid.
52 *
53 * @param on Turn the solenoid output off or on.
54 */
55 void Set(bool on);
56
57 /**
58 * Read the current value of the solenoid.
59 *
60 * @return The current value of the solenoid.
61 */
62 bool Get() const;
63
64 /**
65 * Toggle the value of the solenoid.
66 *
67 * If the solenoid is set to on, it'll be turned off. If the solenoid is set
68 * to off, it'll be turned on.
69 */
70 void Toggle();
71
72 /**
73 * Get the channel this solenoid is connected to.
74 */
75 int GetChannel() const;
76
77 /**
78 * Check if solenoid is Disabled.
79 *
80 * If a solenoid is shorted, it is added to the DisabledList and
81 * disabled until power cycle, or until faults are cleared.
82 *
83 * @see ClearAllPCMStickyFaults()
84 *
85 * @return If solenoid is disabled due to short.
86 */
87 bool IsDisabled() const;
88
89 /**
90 * Set the pulse duration in the pneumatics module. This is used in
91 * conjunction with the startPulse method to allow the pneumatics module to
92 * control the timing of a pulse.
93 *
94 * On the PCM, the timing can be controlled in 0.01 second increments, with a
95 * maximum of 2.55 seconds. On the PH, the timing can be controlled in 0.001
96 * second increments, with a maximum of 65.534 seconds.
97 *
98 * @param duration The duration of the pulse.
99 *
100 * @see startPulse()
101 */
102 void SetPulseDuration(units::second_t duration);
103
104 /**
105 * %Trigger the pneumatics module to generate a pulse of the duration set in
106 * setPulseDuration.
107 *
108 * @see setPulseDuration()
109 */
111
112 void InitSendable(wpi::SendableBuilder& builder) override;
113
114 private:
115 std::shared_ptr<PneumaticsBase> m_module;
116 int m_mask;
117 int m_channel;
118};
119
120} // namespace frc
Solenoid class for running high voltage Digital Output on a pneumatics module.
Definition Solenoid.h:26
void Toggle()
Toggle the value of the solenoid.
void SetPulseDuration(units::second_t duration)
Set the pulse duration in the pneumatics module.
Solenoid(Solenoid &&)=default
bool Get() const
Read the current value of the solenoid.
Solenoid(PneumaticsModuleType moduleType, int channel)
Constructs a solenoid for a default module and specified type.
void StartPulse()
Trigger the pneumatics module to generate a pulse of the duration set in setPulseDuration.
bool IsDisabled() const
Check if solenoid is Disabled.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
int GetChannel() const
Get the channel this solenoid is connected to.
Solenoid(int module, PneumaticsModuleType moduleType, int channel)
Constructs a solenoid for a specified module and type.
Solenoid & operator=(Solenoid &&)=default
void Set(bool on)
Set the value of a solenoid.
~Solenoid() override
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.h:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.h:21
Interface for Sendable objects.
Definition Sendable.h:16
Definition CAN.h:11
PneumaticsModuleType
Pneumatics module type.
Definition PneumaticsModuleType.h:11