WPILibC++ 2024.1.1-beta-4
DutyCycle.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
14namespace frc {
15class DigitalSource;
16class AnalogTrigger;
17class DMA;
18class DMASample;
19
20/**
21 * Class to read a duty cycle PWM input.
22 *
23 * <p>PWM input signals are specified with a frequency and a ratio of high to
24 * low in that frequency. There are 8 of these in the roboRIO, and they can be
25 * attached to any DigitalSource.
26 *
27 * <p>These can be combined as the input of an AnalogTrigger to a Counter in
28 * order to implement rollover checking.
29 *
30 */
31class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
32 friend class AnalogTrigger;
33 friend class DMA;
34 friend class DMASample;
35
36 public:
37 /**
38 * Constructs a DutyCycle input from a DigitalSource input.
39 *
40 * <p> This class does not own the inputted source.
41 *
42 * @param source The DigitalSource to use.
43 */
45 /**
46 * Constructs a DutyCycle input from a DigitalSource input.
47 *
48 * <p> This class does not own the inputted source.
49 *
50 * @param source The DigitalSource to use.
51 */
53 /**
54 * Constructs a DutyCycle input from a DigitalSource input.
55 *
56 * <p> This class does not own the inputted source.
57 *
58 * @param source The DigitalSource to use.
59 */
60 explicit DutyCycle(std::shared_ptr<DigitalSource> source);
61
62 /**
63 * Close the DutyCycle and free all resources.
64 */
65 ~DutyCycle() override;
66
67 DutyCycle(DutyCycle&&) = default;
69
70 /**
71 * Get the frequency of the duty cycle signal.
72 *
73 * @return frequency in Hertz
74 */
75 int GetFrequency() const;
76
77 /**
78 * Get the output ratio of the duty cycle signal.
79 *
80 * <p> 0 means always low, 1 means always high.
81 *
82 * @return output ratio between 0 and 1
83 */
84 double GetOutput() const;
85
86 /**
87 * Get the raw high time of the duty cycle signal.
88 *
89 * @return high time of last pulse
90 */
91 units::second_t GetHighTime() const;
92
93 /**
94 * Get the scale factor of the output.
95 *
96 * <p> An output equal to this value is always high, and then linearly scales
97 * down to 0. Divide a raw result by this in order to get the
98 * percentage between 0 and 1. Used by DMA.
99 *
100 * @return the output scale factor
101 */
102 unsigned int GetOutputScaleFactor() const;
103
104 /**
105 * Get the FPGA index for the DutyCycle.
106 *
107 * @return the FPGA index
108 */
109 int GetFPGAIndex() const;
110
111 /**
112 * Get the channel of the source.
113 *
114 * @return the source channel
115 */
116 int GetSourceChannel() const;
117
118 protected:
119 void InitSendable(wpi::SendableBuilder& builder) override;
120
121 private:
122 void InitDutyCycle();
123 std::shared_ptr<DigitalSource> m_source;
125};
126} // namespace frc
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition: ThirdPartyNotices.txt:111
Definition: AnalogTrigger.h:21
Definition: DMA.h:20
Definition: DMASample.h:20
DigitalSource Interface.
Definition: DigitalSource.h:22
Class to read a duty cycle PWM input.
Definition: DutyCycle.h:31
~DutyCycle() override
Close the DutyCycle and free all resources.
int GetFrequency() const
Get the frequency of the duty cycle signal.
DutyCycle(DutyCycle &&)=default
DutyCycle(DigitalSource &source)
Constructs a DutyCycle input from a DigitalSource input.
DutyCycle(std::shared_ptr< DigitalSource > source)
Constructs a DutyCycle input from a DigitalSource input.
int GetFPGAIndex() const
Get the FPGA index for the DutyCycle.
double GetOutput() const
Get the output ratio of the duty cycle signal.
int GetSourceChannel() const
Get the channel of the source.
unsigned int GetOutputScaleFactor() const
Get the scale factor of the output.
DutyCycle(DigitalSource *source)
Constructs a DutyCycle input from a DigitalSource input.
units::second_t GetHighTime() const
Get the raw high time of the duty cycle signal.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
DutyCycle & operator=(DutyCycle &&)=default
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
Definition: AprilTagPoseEstimator.h:15