jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame^] | 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 ANALOG_CHANNEL_H_
|
| 8 | #define ANALOG_CHANNEL_H_
|
| 9 |
|
| 10 | #include "ChipObject.h"
|
| 11 | #include "SensorBase.h"
|
| 12 | #include "PIDSource.h"
|
| 13 | #include "LiveWindow/LiveWindowSendable.h"
|
| 14 |
|
| 15 | class AnalogModule;
|
| 16 |
|
| 17 | /**
|
| 18 | * Analog channel class.
|
| 19 | *
|
| 20 | * Each analog channel is read from hardware as a 12-bit number representing -10V to 10V.
|
| 21 | *
|
| 22 | * Connected to each analog channel is an averaging and oversampling engine. This engine accumulates
|
| 23 | * the specified ( by SetAverageBits() and SetOversampleBits() ) number of samples before returning a new
|
| 24 | * value. This is not a sliding window average. The only difference between the oversampled samples and
|
| 25 | * the averaged samples is that the oversampled samples are simply accumulated effectively increasing the
|
| 26 | * resolution, while the averaged samples are divided by the number of samples to retain the resolution,
|
| 27 | * but get more stable values.
|
| 28 | */
|
| 29 | class AnalogChannel : public SensorBase, public PIDSource, public LiveWindowSendable
|
| 30 | {
|
| 31 | public:
|
| 32 | static const UINT8 kAccumulatorModuleNumber = 1;
|
| 33 | static const UINT32 kAccumulatorNumChannels = 2;
|
| 34 | static const UINT32 kAccumulatorChannels[kAccumulatorNumChannels];
|
| 35 |
|
| 36 | AnalogChannel(UINT8 moduleNumber, UINT32 channel);
|
| 37 | explicit AnalogChannel(UINT32 channel);
|
| 38 | virtual ~AnalogChannel();
|
| 39 |
|
| 40 | AnalogModule *GetModule();
|
| 41 |
|
| 42 | INT16 GetValue();
|
| 43 | INT32 GetAverageValue();
|
| 44 |
|
| 45 | float GetVoltage();
|
| 46 | float GetAverageVoltage();
|
| 47 |
|
| 48 | UINT8 GetModuleNumber();
|
| 49 | UINT32 GetChannel();
|
| 50 |
|
| 51 | void SetAverageBits(UINT32 bits);
|
| 52 | UINT32 GetAverageBits();
|
| 53 | void SetOversampleBits(UINT32 bits);
|
| 54 | UINT32 GetOversampleBits();
|
| 55 |
|
| 56 | UINT32 GetLSBWeight();
|
| 57 | INT32 GetOffset();
|
| 58 |
|
| 59 | bool IsAccumulatorChannel();
|
| 60 | void InitAccumulator();
|
| 61 | void SetAccumulatorInitialValue(INT64 value);
|
| 62 | void ResetAccumulator();
|
| 63 | void SetAccumulatorCenter(INT32 center);
|
| 64 | void SetAccumulatorDeadband(INT32 deadband);
|
| 65 | INT64 GetAccumulatorValue();
|
| 66 | UINT32 GetAccumulatorCount();
|
| 67 | void GetAccumulatorOutput(INT64 *value, UINT32 *count);
|
| 68 |
|
| 69 | double PIDGet();
|
| 70 |
|
| 71 | void UpdateTable();
|
| 72 | void StartLiveWindowMode();
|
| 73 | void StopLiveWindowMode();
|
| 74 | std::string GetSmartDashboardType();
|
| 75 | void InitTable(ITable *subTable);
|
| 76 | ITable * GetTable();
|
| 77 |
|
| 78 | private:
|
| 79 | void InitChannel(UINT8 moduleNumber, UINT32 channel);
|
| 80 | UINT32 m_channel;
|
| 81 | AnalogModule *m_module;
|
| 82 | tAccumulator *m_accumulator;
|
| 83 | INT64 m_accumulatorOffset;
|
| 84 |
|
| 85 | ITable *m_table;
|
| 86 | };
|
| 87 |
|
| 88 | #endif
|