WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
DigitalOutput.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 <hal/DIO.h>
8#include <hal/Types.h>
9#include <units/time.h>
12
13namespace frc {
14
15/**
16 * Class to write to digital outputs.
17 *
18 * Write values to the digital output channels. Other devices implemented
19 * elsewhere will allocate channels automatically so for those devices it
20 * shouldn't be done here.
21 */
23 public wpi::SendableHelper<DigitalOutput> {
24 public:
25 /**
26 * Create an instance of a digital output.
27 *
28 * Create a digital output given a channel.
29 *
30 * @param channel The digital channel 0-9 are on-board, 10-25 are on the MXP
31 * port
32 */
33 explicit DigitalOutput(int channel);
34
37
38 ~DigitalOutput() override;
39
40 /**
41 * Set the value of a digital output.
42 *
43 * Set the value of a digital output to either one (true) or zero (false).
44 *
45 * @param value 1 (true) for high, 0 (false) for disabled
46 */
47 void Set(bool value);
48
49 /**
50 * Gets the value being output from the Digital Output.
51 *
52 * @return the state of the digital output.
53 */
54 bool Get() const;
55
56 /**
57 * @return The GPIO channel number that this object represents.
58 */
59 int GetChannel() const;
60
61 /**
62 * Output a single pulse on the digital output line.
63 *
64 * Send a single pulse on the digital output line where the pulse duration is
65 * specified in seconds. Maximum of 65535 microseconds.
66 *
67 * @param pulseLength The pulse length in seconds
68 */
69 void Pulse(units::second_t pulseLength);
70
71 /**
72 * Determine if the pulse is still going.
73 *
74 * Determine if a previously started pulse is still going.
75 */
76 bool IsPulsing() const;
77
78 /**
79 * Change the PWM frequency of the PWM output on a Digital Output line.
80 *
81 * The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
82 * logarithmic.
83 *
84 * There is only one PWM frequency for all digital channels.
85 *
86 * @param rate The frequency to output all digital output PWM signals.
87 */
88 void SetPWMRate(double rate);
89
90 /**
91 * Enable a PWM PPS (Pulse Per Second) Output on this line.
92 *
93 * Allocate one of the 6 DO PWM generator resources from this module.
94 *
95 * Supply the duty-cycle to output.
96 *
97 * The resolution of the duty cycle is 8-bit.
98 *
99 * @param dutyCycle The duty-cycle to start generating. [0..1]
100 */
101 void EnablePPS(double dutyCycle);
102
103 /**
104 * Enable a PWM Output on this line.
105 *
106 * Allocate one of the 6 DO PWM generator resources from this module.
107 *
108 * Supply the initial duty-cycle to output so as to avoid a glitch when first
109 * starting.
110 *
111 * The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
112 * less) but is reduced the higher the frequency of the PWM signal is.
113 *
114 * @param initialDutyCycle The duty-cycle to start generating. [0..1]
115 */
116 void EnablePWM(double initialDutyCycle);
117
118 /**
119 * Change this line from a PWM output back to a static Digital Output line.
120 *
121 * Free up one of the 6 DO PWM generator resources that were in use.
122 */
124
125 /**
126 * Change the duty-cycle that is being generated on the line.
127 *
128 * The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
129 * less) but is reduced the higher the frequency of the PWM signal is.
130 *
131 * @param dutyCycle The duty-cycle to change to. [0..1]
132 */
133 void UpdateDutyCycle(double dutyCycle);
134
135 /**
136 * Indicates this output is used by a simulated device.
137 *
138 * @param device simulated device handle
139 */
141
142 void InitSendable(wpi::SendableBuilder& builder) override;
143
144 private:
145 int m_channel;
148};
149
150} // namespace frc
Class to write to digital outputs.
Definition DigitalOutput.h:23
DigitalOutput(int channel)
Create an instance of a digital output.
int GetChannel() const
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this output is used by a simulated device.
void EnablePWM(double initialDutyCycle)
Enable a PWM Output on this line.
DigitalOutput(DigitalOutput &&)=default
bool IsPulsing() const
Determine if the pulse is still going.
void EnablePPS(double dutyCycle)
Enable a PWM PPS (Pulse Per Second) Output on this line.
void DisablePWM()
Change this line from a PWM output back to a static Digital Output line.
~DigitalOutput() override
void SetPWMRate(double rate)
Change the PWM frequency of the PWM output on a Digital Output line.
bool Get() const
Gets the value being output from the Digital Output.
void Set(bool value)
Set the value of a digital output.
void UpdateDutyCycle(double dutyCycle)
Change the duty-cycle that is being generated on the line.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
DigitalOutput & operator=(DigitalOutput &&)=default
void Pulse(units::second_t pulseLength)
Output a single pulse on the digital output line.
A move-only C++ wrapper around a HAL handle.
Definition Types.h:98
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
HAL_Handle HAL_SimDeviceHandle
Definition Types.h:51
Definition SystemServer.h:9