WPILibC++ 2027.0.0-alpha-2
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 busId The bus ID.
32 * @param module The module ID to use.
33 * @param moduleType The module type to use.
34 * @param channel The channel the solenoid is on.
35 */
36 Solenoid(int busId, int module, PneumaticsModuleType moduleType, int channel);
37
38 /**
39 * Constructs a solenoid for a default module and specified type.
40 *
41 * @param busId The bus ID.
42 * @param moduleType The module type to use.
43 * @param channel The channel the solenoid is on.
44 */
45 Solenoid(int busId, PneumaticsModuleType moduleType, int channel);
46
47 ~Solenoid() override;
48
49 Solenoid(Solenoid&&) = default;
51
52 /**
53 * Set the value of a solenoid.
54 *
55 * @param on Turn the solenoid output off or on.
56 */
57 void Set(bool on);
58
59 /**
60 * Read the current value of the solenoid.
61 *
62 * @return The current value of the solenoid.
63 */
64 bool Get() const;
65
66 /**
67 * Toggle the value of the solenoid.
68 *
69 * If the solenoid is set to on, it'll be turned off. If the solenoid is set
70 * to off, it'll be turned on.
71 */
72 void Toggle();
73
74 /**
75 * Get the channel this solenoid is connected to.
76 */
77 int GetChannel() const;
78
79 /**
80 * Check if solenoid is Disabled.
81 *
82 * If a solenoid is shorted, it is added to the DisabledList and
83 * disabled until power cycle, or until faults are cleared.
84 *
85 * @see ClearAllPCMStickyFaults()
86 *
87 * @return If solenoid is disabled due to short.
88 */
89 bool IsDisabled() const;
90
91 /**
92 * Set the pulse duration in the pneumatics module. This is used in
93 * conjunction with the startPulse method to allow the pneumatics module to
94 * control the timing of a pulse.
95 *
96 * On the PCM, the timing can be controlled in 0.01 second increments, with a
97 * maximum of 2.55 seconds. On the PH, the timing can be controlled in 0.001
98 * second increments, with a maximum of 65.534 seconds.
99 *
100 * @param duration The duration of the pulse.
101 *
102 * @see startPulse()
103 */
104 void SetPulseDuration(units::second_t duration);
105
106 /**
107 * %Trigger the pneumatics module to generate a pulse of the duration set in
108 * setPulseDuration.
109 *
110 * @see setPulseDuration()
111 */
113
114 void InitSendable(wpi::SendableBuilder& builder) override;
115
116 private:
117 std::shared_ptr<PneumaticsBase> m_module;
118 int m_mask;
119 int m_channel;
120};
121
122} // 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.
void StartPulse()
Trigger the pneumatics module to generate a pulse of the duration set in setPulseDuration.
Solenoid(int busId, PneumaticsModuleType moduleType, int channel)
Constructs a solenoid for a default module and specified type.
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 & operator=(Solenoid &&)=default
Solenoid(int busId, int module, PneumaticsModuleType moduleType, int channel)
Constructs a solenoid for a specified module and type.
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 SystemServer.h:9
PneumaticsModuleType
Pneumatics module type.
Definition PneumaticsModuleType.h:11