WPILibC++  2020.3.2
DutyCycle.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 
12 #include <hal/Types.h>
13 
14 #include "frc/ErrorBase.h"
15 #include "frc/smartdashboard/Sendable.h"
16 #include "frc/smartdashboard/SendableHelper.h"
17 
18 namespace frc {
19 class DigitalSource;
20 class AnalogTrigger;
21 class DMA;
22 class DMASample;
23 
35 class DutyCycle : public ErrorBase,
36  public Sendable,
37  public SendableHelper<DutyCycle> {
38  friend class AnalogTrigger;
39  friend class DMA;
40  friend class DMASample;
41 
42  public:
50  explicit DutyCycle(DigitalSource& source);
58  explicit DutyCycle(DigitalSource* source);
66  explicit DutyCycle(std::shared_ptr<DigitalSource> source);
67 
71  ~DutyCycle() override;
72 
73  DutyCycle(DutyCycle&&) = default;
74  DutyCycle& operator=(DutyCycle&&) = default;
75 
81  int GetFrequency() const;
82 
90  double GetOutput() const;
91 
100  unsigned int GetOutputRaw() const;
101 
111  unsigned int GetOutputScaleFactor() const;
112 
118  int GetFPGAIndex() const;
119 
125  int GetSourceChannel() const;
126 
127  protected:
128  void InitSendable(SendableBuilder& builder) override;
129 
130  private:
131  void InitDutyCycle();
132  std::shared_ptr<DigitalSource> m_source;
133  hal::Handle<HAL_DutyCycleHandle> m_handle;
134 };
135 } // namespace frc
frc::DutyCycle::GetOutputRaw
unsigned int GetOutputRaw() const
Get the raw output ratio of the duty cycle signal.
frc::DMA
Definition: DMA.h:22
frc::DutyCycle::GetOutputScaleFactor
unsigned int GetOutputScaleFactor() const
Get the scale factor of the output.
frc::DMASample
Definition: DMASample.h:23
frc::DutyCycle::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::DutyCycle::GetFPGAIndex
int GetFPGAIndex() const
Get the FPGA index for the DutyCycle.
frc::DutyCycle::~DutyCycle
~DutyCycle() override
Close the DutyCycle and free all resources.
frc::AnalogTrigger
Definition: AnalogTrigger.h:25
frc::DutyCycle::DutyCycle
DutyCycle(DigitalSource &source)
Constructs a DutyCycle input from a DigitalSource input.
frc::DutyCycle
Class to read a duty cycle PWM input.
Definition: DutyCycle.h:35
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::DutyCycle::GetFrequency
int GetFrequency() const
Get the frequency of the duty cycle signal.
frc::DutyCycle::GetSourceChannel
int GetSourceChannel() const
Get the channel of the source.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::DutyCycle::GetOutput
double GetOutput() const
Get the output ratio of the duty cycle signal.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::DigitalSource
DigitalSource Interface.
Definition: DigitalSource.h:25
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23