WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
PWM.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef PWM_H_
8 #define PWM_H_
9 
10 #include "SensorBase.h"
11 #include "LiveWindow/LiveWindowSendable.h"
12 #include "tables/ITableListener.h"
13 
14 class DigitalModule;
15 
32 class PWM : public SensorBase, public ITableListener, public LiveWindowSendable
33 {
34  friend class DigitalModule;
35 public:
36  typedef enum {kPeriodMultiplier_1X = 1, kPeriodMultiplier_2X = 2, kPeriodMultiplier_4X = 4} PeriodMultiplier;
37 
38  explicit PWM(uint32_t channel);
39  PWM(uint8_t moduleNumber, uint32_t channel);
40  virtual ~PWM();
41  virtual void SetRaw(uint8_t value);
42  virtual uint8_t GetRaw();
43  void SetPeriodMultiplier(PeriodMultiplier mult);
44  void EnableDeadbandElimination(bool eliminateDeadband);
45  void SetBounds(int32_t max, int32_t deadbandMax, int32_t center, int32_t deadbandMin, int32_t min);
46  void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min);
47  uint32_t GetChannel() {return m_channel;}
48  uint32_t GetModuleNumber();
49 
50 protected:
67  static constexpr float kDefaultPwmPeriod = 5.05;
71  static constexpr float kDefaultPwmCenter = 1.5;
75  static const int32_t kDefaultPwmStepsDown = 128;
76  static const int32_t kPwmDisabled = 0;
77 
78  virtual void SetPosition(float pos);
79  virtual float GetPosition();
80  virtual void SetSpeed(float speed);
81  virtual float GetSpeed();
82 
83  bool m_eliminateDeadband;
84  int32_t m_maxPwm;
85  int32_t m_deadbandMaxPwm;
86  int32_t m_centerPwm;
87  int32_t m_deadbandMinPwm;
88  int32_t m_minPwm;
89 
90  void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
91  void UpdateTable();
92  void StartLiveWindowMode();
93  void StopLiveWindowMode();
94  std::string GetSmartDashboardType();
95  void InitTable(ITable *subTable);
96  ITable * GetTable();
97 
98  ITable *m_table;
99 
100 private:
101  void InitPWM(uint8_t moduleNumber, uint32_t channel);
102  uint32_t m_channel;
103  DigitalModule *m_module;
104  int32_t GetMaxPositivePwm() { return m_maxPwm; };
105  int32_t GetMinPositivePwm() { return m_eliminateDeadband ? m_deadbandMaxPwm : m_centerPwm + 1; };
106  int32_t GetCenterPwm() { return m_centerPwm; };
107  int32_t GetMaxNegativePwm() { return m_eliminateDeadband ? m_deadbandMinPwm : m_centerPwm - 1; };
108  int32_t GetMinNegativePwm() { return m_minPwm; };
109  int32_t GetPositiveScaleFactor() {return GetMaxPositivePwm() - GetMinPositivePwm();}
110  int32_t GetNegativeScaleFactor() {return GetMaxNegativePwm() - GetMinNegativePwm();}
111  int32_t GetFullRangeScaleFactor() {return GetMaxPositivePwm() - GetMinNegativePwm();}
112 };
113 
114 #endif
static const int32_t kDefaultPwmStepsDown
Definition: PWM.h:75
Definition: PWM.h:32
virtual float GetPosition()
Definition: PWM.cpp:205
PWM(uint32_t channel)
Definition: PWM.cpp:81
Definition: SensorBase.h:20
static constexpr float kDefaultPwmCenter
Definition: PWM.h:71
virtual ~PWM()
Definition: PWM.cpp:92
virtual void SetPosition(float pos)
Definition: PWM.cpp:172
virtual void SetRaw(uint8_t value)
Definition: PWM.cpp:323
virtual float GetSpeed()
Definition: PWM.cpp:286
virtual uint8_t GetRaw()
Definition: PWM.cpp:336
void SetBounds(int32_t max, int32_t deadbandMax, int32_t center, int32_t deadbandMin, int32_t min)
Definition: PWM.cpp:123
static constexpr float kDefaultPwmPeriod
Definition: PWM.h:67
void EnableDeadbandElimination(bool eliminateDeadband)
Definition: PWM.cpp:107
virtual void SetSpeed(float speed)
Definition: PWM.cpp:236
void SetPeriodMultiplier(PeriodMultiplier mult)
Definition: PWM.cpp:347
Definition: DigitalModule.h:17