WPILibC++  2020.3.2-60-g3011ebe
PWM.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-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 <stdint.h>
11 
12 #include <hal/Types.h>
13 #include <wpi/raw_ostream.h>
14 
15 #include "frc/MotorSafety.h"
16 #include "frc/smartdashboard/Sendable.h"
17 #include "frc/smartdashboard/SendableHelper.h"
18 
19 namespace frc {
20 class AddressableLED;
21 class SendableBuilder;
22 
40 class PWM : public MotorSafety, public Sendable, public SendableHelper<PWM> {
41  public:
42  friend class AddressableLED;
59  };
60 
71  explicit PWM(int channel);
72 
78  ~PWM() override;
79 
80  PWM(PWM&&) = default;
81  PWM& operator=(PWM&&) = default;
82 
83  // MotorSafety interface
84  void StopMotor() override;
85  void GetDescription(wpi::raw_ostream& desc) const override;
86 
94  virtual void SetRaw(uint16_t value);
95 
103  virtual uint16_t GetRaw() const;
104 
115  virtual void SetPosition(double pos);
116 
127  virtual double GetPosition() const;
128 
142  virtual void SetSpeed(double speed);
143 
156  virtual double GetSpeed() const;
157 
162  virtual void SetDisabled();
163 
170 
171  void SetZeroLatch();
172 
181  void EnableDeadbandElimination(bool eliminateDeadband);
182 
196  void SetBounds(double max, double deadbandMax, double center,
197  double deadbandMin, double min);
198 
212  void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
213  int min);
214 
228  void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
229  int32_t* deadbandMin, int32_t* min);
230 
231  int GetChannel() const;
232 
233  protected:
234  void InitSendable(SendableBuilder& builder) override;
235 
236  private:
237  int m_channel;
238  hal::Handle<HAL_DigitalHandle> m_handle;
239 };
240 
241 } // namespace frc
frc::PWM
Class implements the PWM generation in the FPGA.
Definition: PWM.h:40
frc::PWM::EnableDeadbandElimination
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a speed controller.
frc::PWM::SetBounds
void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min)
Set the bounds on the PWM pulse widths.
frc::PWM::kPeriodMultiplier_1X
Don't skip pulses.
Definition: PWM.h:50
frc::PWM::GetRaw
virtual uint16_t GetRaw() const
Get the PWM value directly from the hardware.
frc::PWM::kPeriodMultiplier_2X
Skip every other pulse.
Definition: PWM.h:54
frc::PWM::SetSpeed
virtual void SetSpeed(double speed)
Set the PWM value based on a speed.
frc::MotorSafety
This base class runs a watchdog timer and calls the subclass's StopMotor() function if the timeout ex...
Definition: MotorSafety.h:24
frc::PWM::PWM
PWM(int channel)
Allocate a PWM given a channel number.
frc::PWM::GetSpeed
virtual double GetSpeed() const
Get the PWM value in terms of speed.
frc::PWM::SetPosition
virtual void SetPosition(double pos)
Set the PWM value based on a position.
frc::PWM::PeriodMultiplier
PeriodMultiplier
Represents the amount to multiply the minimum servo-pulse pwm period by.
Definition: PWM.h:46
frc::PWM::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::PWM::SetPeriodMultiplier
void SetPeriodMultiplier(PeriodMultiplier mult)
Slow down the PWM signal for old devices.
frc::PWM::~PWM
~PWM() override
Free the PWM channel.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::PWM::GetRawBounds
void GetRawBounds(int32_t *max, int32_t *deadbandMax, int32_t *center, int32_t *deadbandMin, int32_t *min)
Get the bounds on the PWM values.
frc::PWM::SetDisabled
virtual void SetDisabled()
Temporarily disables the PWM output.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::PWM::SetRaw
virtual void SetRaw(uint16_t value)
Set the PWM value directly to the hardware.
wpi::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:47
frc::AddressableLED
A class for driving addressable LEDs, such as WS2812s and NeoPixels.
Definition: AddressableLED.h:28
frc::PWM::GetPosition
virtual double GetPosition() const
Get the PWM value in terms of a position.
frc::PWM::SetRawBounds
void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, int min)
Set the bounds on the PWM values.
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23
frc::PWM::kPeriodMultiplier_4X
Skip three out of four pulses.
Definition: PWM.h:58