WPILibC++  unspecified
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 "ErrorBase.h"
15 #include "SmartDashboard/SendableBase.h"
16 
17 namespace frc {
18 
36 class PWM : public ErrorBase, public SendableBase {
37  public:
54  };
55 
56  explicit PWM(int channel);
57  ~PWM() override;
58  virtual void SetRaw(uint16_t value);
59  virtual uint16_t GetRaw() const;
60  virtual void SetPosition(double pos);
61  virtual double GetPosition() const;
62  virtual void SetSpeed(double speed);
63  virtual double GetSpeed() const;
64  virtual void SetDisabled();
66  void SetZeroLatch();
67  void EnableDeadbandElimination(bool eliminateDeadband);
68  void SetBounds(double max, double deadbandMax, double center,
69  double deadbandMin, double min);
70  void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
71  int min);
72  void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
73  int32_t* deadbandMin, int32_t* min);
74  int GetChannel() const { return m_channel; }
75 
76  protected:
77  void InitSendable(SendableBuilder& builder) override;
78 
79  private:
80  int m_channel;
81  HAL_DigitalHandle m_handle;
82 };
83 
84 } // namespace frc
Definition: RobotController.cpp:14
void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min)
Set the bounds on the PWM pulse widths.
Definition: PWM.cpp:103
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 GetRawBounds(int32_t *max, int32_t *deadbandMax, int32_t *center, int32_t *deadbandMin, int32_t *min)
Get the bounds on the PWM values.
Definition: PWM.cpp:147
virtual void SetSpeed(double speed)
Set the PWM value based on a speed.
Definition: PWM.cpp:203
virtual double GetSpeed() const
Get the PWM value in terms of speed.
Definition: PWM.cpp:222
Don&#39;t skip pulses.
Definition: PWM.h:45
PWM(int channel)
Allocate a PWM given a channel number.
Definition: PWM.cpp:31
void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, int min)
Set the bounds on the PWM values.
Definition: PWM.cpp:125
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a speed controller.
Definition: PWM.cpp:83
virtual uint16_t GetRaw() const
Get the PWM value directly from the hardware.
Definition: PWM.cpp:252
void SetPeriodMultiplier(PeriodMultiplier mult)
Slow down the PWM signal for old devices.
Definition: PWM.cpp:267
Base class for most objects.
Definition: ErrorBase.h:74
virtual double GetPosition() const
Get the PWM value in terms of a position.
Definition: PWM.cpp:182
virtual void SetRaw(uint16_t value)
Set the PWM value directly to the hardware.
Definition: PWM.cpp:237
Definition: SendableBase.h:19
Definition: SendableBuilder.h:23
virtual void SetPosition(double pos)
Set the PWM value based on a position.
Definition: PWM.cpp:165
Class implements the PWM generation in the FPGA.
Definition: PWM.h:36
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: PWM.cpp:313
~PWM() override
Free the PWM channel.
Definition: PWM.cpp:65
virtual void SetDisabled()
Temporarily disables the PWM output.
Definition: PWM.cpp:295