WPILibC++  2019.3.1
 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 #include <wpi/raw_ostream.h>
14 
15 #include "frc/MotorSafety.h"
16 #include "frc/smartdashboard/SendableBase.h"
17 
18 namespace frc {
19 
37 class PWM : public MotorSafety, public SendableBase {
38  public:
55  };
56 
67  explicit PWM(int channel);
68 
74  ~PWM() override;
75 
76  PWM(PWM&& rhs);
77  PWM& operator=(PWM&& rhs);
78 
79  // MotorSafety interface
80  void StopMotor() override;
81  void GetDescription(wpi::raw_ostream& desc) const override;
82 
90  virtual void SetRaw(uint16_t value);
91 
99  virtual uint16_t GetRaw() const;
100 
111  virtual void SetPosition(double pos);
112 
123  virtual double GetPosition() const;
124 
138  virtual void SetSpeed(double speed);
139 
152  virtual double GetSpeed() const;
153 
158  virtual void SetDisabled();
159 
166 
167  void SetZeroLatch();
168 
177  void EnableDeadbandElimination(bool eliminateDeadband);
178 
192  void SetBounds(double max, double deadbandMax, double center,
193  double deadbandMin, double min);
194 
208  void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
209  int min);
210 
224  void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
225  int32_t* deadbandMin, int32_t* min);
226 
227  int GetChannel() const;
228 
229  protected:
230  void InitSendable(SendableBuilder& builder) override;
231 
232  private:
233  int m_channel;
234  HAL_DigitalHandle m_handle = HAL_kInvalidHandle;
235 };
236 
237 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
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:42
Skip every other pulse.
Definition: PWM.h:50
Skip three out of four pulses.
Definition: PWM.h:54
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:46
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
This base class runs a watchdog timer and calls the subclass's StopMotor() function if the timeout ex...
Definition: MotorSafety.h:24
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.
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:37