WPILib 2012
WPILibRoboticsLibraryforFRC
|
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #ifndef PWM_H_ 00008 #define PWM_H_ 00009 00010 #include "SensorBase.h" 00011 00012 class DigitalModule; 00013 00030 class PWM : public SensorBase 00031 { 00032 friend class DigitalModule; 00033 public: 00034 typedef enum {kPeriodMultiplier_1X = 1, kPeriodMultiplier_2X = 2, kPeriodMultiplier_4X = 4} PeriodMultiplier; 00035 00036 explicit PWM(UINT32 channel); 00037 PWM(UINT8 moduleNumber, UINT32 channel); 00038 virtual ~PWM(); 00039 virtual void SetRaw(UINT8 value); 00040 virtual UINT8 GetRaw(); 00041 void SetPeriodMultiplier(PeriodMultiplier mult); 00042 void EnableDeadbandElimination(bool eliminateDeadband); 00043 void SetBounds(INT32 max, INT32 deadbandMax, INT32 center, INT32 deadbandMin, INT32 min); 00044 UINT32 GetChannel() {return m_channel;} 00045 UINT32 GetModuleNumber(); 00046 00047 protected: 00066 static const UINT32 kDefaultPwmPeriod = 774; 00067 00075 static const UINT32 kDefaultMinPwmHigh = 102; 00076 00077 static const INT32 kPwmDisabled = 0; 00078 00079 virtual void SetPosition(float pos); 00080 virtual float GetPosition(); 00081 virtual void SetSpeed(float speed); 00082 virtual float GetSpeed(); 00083 00084 bool m_eliminateDeadband; 00085 INT32 m_maxPwm; 00086 INT32 m_deadbandMaxPwm; 00087 INT32 m_centerPwm; 00088 INT32 m_deadbandMinPwm; 00089 INT32 m_minPwm; 00090 00091 private: 00092 void InitPWM(UINT8 moduleNumber, UINT32 channel); 00093 UINT32 m_channel; 00094 DigitalModule *m_module; 00095 INT32 GetMaxPositivePwm() { return m_maxPwm; }; 00096 INT32 GetMinPositivePwm() { return m_eliminateDeadband ? m_deadbandMaxPwm : m_centerPwm + 1; }; 00097 INT32 GetCenterPwm() { return m_centerPwm; }; 00098 INT32 GetMaxNegativePwm() { return m_eliminateDeadband ? m_deadbandMinPwm : m_centerPwm - 1; }; 00099 INT32 GetMinNegativePwm() { return m_minPwm; }; 00100 INT32 GetPositiveScaleFactor() {return GetMaxPositivePwm() - GetMinPositivePwm();} 00101 INT32 GetNegativeScaleFactor() {return GetMaxNegativePwm() - GetMinNegativePwm();} 00102 INT32 GetFullRangeScaleFactor() {return GetMaxPositivePwm() - GetMinNegativePwm();} 00103 }; 00104 00105 #endif