WPILibC++  2018.4.1-1217-gf0ac048
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
PWM.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 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 
14 #include "frc/ErrorBase.h"
15 #include "frc/smartdashboard/SendableBase.h"
16 
17 namespace frc {
18 
36 class PWM : public ErrorBase, public SendableBase {
37  public:
54  };
55 
66  explicit PWM(int channel);
67 
73  ~PWM() override;
74 
75  PWM(PWM&& rhs);
76  PWM& operator=(PWM&& rhs);
77 
85  virtual void SetRaw(uint16_t value);
86 
94  virtual uint16_t GetRaw() const;
95 
106  virtual void SetPosition(double pos);
107 
118  virtual double GetPosition() const;
119 
133  virtual void SetSpeed(double speed);
134 
147  virtual double GetSpeed() const;
148 
153  virtual void SetDisabled();
154 
161 
162  void SetZeroLatch();
163 
172  void EnableDeadbandElimination(bool eliminateDeadband);
173 
187  void SetBounds(double max, double deadbandMax, double center,
188  double deadbandMin, double min);
189 
203  void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
204  int min);
205 
219  void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
220  int32_t* deadbandMin, int32_t* min);
221 
222  int GetChannel() const;
223 
224  protected:
225  void InitSendable(SendableBuilder& builder) override;
226 
227  private:
228  int m_channel;
229  HAL_DigitalHandle m_handle = HAL_kInvalidHandle;
230 };
231 
232 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min)
Set the bounds on the PWM pulse widths.
virtual void SetPosition(double pos)
Set the PWM value based on a position.
PeriodMultiplier
Represents the amount to multiply the minimum servo-pulse pwm period by.
Definition: PWM.h:41
Skip every other pulse.
Definition: PWM.h:49
Skip three out of four pulses.
Definition: PWM.h:53
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a speed controller.
virtual void SetSpeed(double speed)
Set the PWM value based on a speed.
Don't skip pulses.
Definition: PWM.h:45
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
void GetRawBounds(int32_t *max, int32_t *deadbandMax, int32_t *center, int32_t *deadbandMin, int32_t *min)
Get the bounds on the PWM values.
void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, int min)
Set the bounds on the PWM values.
PWM(int channel)
Allocate a PWM given a channel number.
void SetPeriodMultiplier(PeriodMultiplier mult)
Slow down the PWM signal for old devices.
virtual void SetDisabled()
Temporarily disables the PWM output.
Base class for most objects.
Definition: ErrorBase.h:74
virtual void SetRaw(uint16_t value)
Set the PWM value directly to the hardware.
Definition: SendableBase.h:19
virtual double GetSpeed() const
Get the PWM value in terms of speed.
virtual uint16_t GetRaw() const
Get the PWM value directly from the hardware.
virtual double GetPosition() const
Get the PWM value in terms of a position.
Definition: SendableBuilder.h:23
~PWM() override
Free the PWM channel.
Class implements the PWM generation in the FPGA.
Definition: PWM.h:36