WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
Encoder.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 QUAD_ENCODER_H_
8 #define QUAD_ENCODER_H_
9 
10 #include "ChipObject.h"
11 #include "CounterBase.h"
12 #include "SensorBase.h"
13 #include "Counter.h"
14 #include "PIDSource.h"
15 #include "LiveWindow/LiveWindowSendable.h"
16 
17 class DigitalSource;
18 
28 class Encoder: public SensorBase, public CounterBase, public PIDSource, public LiveWindowSendable
29 {
30 public:
31 
32  Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection=false, EncodingType encodingType = k4X);
33  Encoder(uint8_t aModuleNumber, uint32_t aChannel, uint8_t bModuleNumber, uint32_t _bChannel, bool reverseDirection=false, EncodingType encodingType = k4X);
34  Encoder(DigitalSource *aSource, DigitalSource *bSource, bool reverseDirection=false, EncodingType encodingType = k4X);
35  Encoder(DigitalSource &aSource, DigitalSource &bSource, bool reverseDirection=false, EncodingType encodingType = k4X);
36  virtual ~Encoder();
37 
38  // CounterBase interface
39  void Start();
40  int32_t Get();
41  int32_t GetRaw();
42  void Reset();
43  void Stop();
44  double GetPeriod();
45  void SetMaxPeriod(double maxPeriod);
46  bool GetStopped();
47  bool GetDirection();
48  double GetDistance();
49  double GetRate();
50  void SetMinRate(double minRate);
51  void SetDistancePerPulse(double distancePerPulse);
52  void SetReverseDirection(bool reverseDirection);
53  void SetSamplesToAverage(int samplesToAverage);
54  int GetSamplesToAverage();
55  void SetPIDSourceParameter(PIDSourceParameter pidSource);
56  double PIDGet();
57 
58  void UpdateTable();
59  void StartLiveWindowMode();
60  void StopLiveWindowMode();
61  std::string GetSmartDashboardType();
62  void InitTable(ITable *subTable);
63  ITable * GetTable();
64 
65 private:
66  void InitEncoder(bool _reverseDirection, EncodingType encodingType);
67  double DecodingScaleFactor();
68 
69  DigitalSource *m_aSource; // the A phase of the quad encoder
70  DigitalSource *m_bSource; // the B phase of the quad encoder
71  bool m_allocatedASource; // was the A source allocated locally?
72  bool m_allocatedBSource; // was the B source allocated locally?
73  tEncoder* m_encoder;
74  uint8_t m_index;
75  double m_distancePerPulse; // distance of travel for each encoder tick
76  Counter *m_counter; // Counter object for 1x and 2x encoding
77  EncodingType m_encodingType; // Encoding type
78  PIDSourceParameter m_pidSource;// Encoder parameter that sources a PID controller
79 
80  ITable *m_table;
81 };
82 
83 #endif
84 
double GetRate()
Definition: Encoder.cpp:437
bool GetStopped()
Definition: Encoder.cpp:365
Definition: DigitalSource.h:19
int GetSamplesToAverage()
Definition: Encoder.cpp:524
void SetReverseDirection(bool reverseDirection)
Definition: Encoder.cpp:477
void Reset()
Definition: Encoder.cpp:279
void SetSamplesToAverage(int samplesToAverage)
Definition: Encoder.cpp:499
void SetDistancePerPulse(double distancePerPulse)
Definition: Encoder.cpp:465
Definition: Encoder.h:28
void SetMinRate(double minRate)
Definition: Encoder.cpp:448
virtual ~Encoder()
Definition: Encoder.cpp:193
Definition: CounterBase.h:15
Definition: SensorBase.h:20
int32_t GetRaw()
Definition: Encoder.cpp:247
void SetPIDSourceParameter(PIDSourceParameter pidSource)
Definition: Encoder.cpp:548
void SetMaxPeriod(double maxPeriod)
Definition: Encoder.cpp:343
void Stop()
Definition: Encoder.cpp:228
Definition: Counter.h:21
void Start()
Definition: Encoder.cpp:212
Definition: PIDSource.h:15
double GetDistance()
Definition: Encoder.cpp:425
double PIDGet()
Definition: Encoder.cpp:559
bool GetDirection()
Definition: Encoder.cpp:385
int32_t Get()
Definition: Encoder.cpp:269
double GetPeriod()
Definition: Encoder.cpp:301