-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalogChannel.h
77 lines (62 loc) · 2.42 KB
/
AnalogChannel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ANALOG_CHANNEL_H_
#define ANALOG_CHANNEL_H_
#include "SensorBase.h"
#include "PIDSource.h"
class AnalogModule;
/**
* Analog channel class.
*
* Each analog channel is read from hardware as a 12-bit number representing -10V to 10V.
*
* Connected to each analog channel is an averaging and oversampling engine. This engine accumulates
* the specified ( by SetAverageBits() and SetOversampleBits() ) number of samples before returning a new
* value. This is not a sliding window average. The only difference between the oversampled samples and
* the averaged samples is that the oversampled samples are simply accumulated effectively increasing the
* resolution, while the averaged samples are divided by the number of samples to retain the resolution,
* but get more stable values.
*/
class AnalogChannel : public SensorBase, public PIDSource
{
public:
static const UINT32 kAccumulatorSlot = 1;
static const UINT32 kAccumulatorNumChannels = 2;
static const UINT32 kAccumulatorChannels[kAccumulatorNumChannels];
AnalogChannel(UINT32 slot, UINT32 channel);
explicit AnalogChannel(UINT32 channel);
virtual ~AnalogChannel();
AnalogModule *GetModule();
INT16 GetValue();
INT32 GetAverageValue();
float GetVoltage();
float GetAverageVoltage();
UINT32 GetSlot();
UINT32 GetChannel();
void SetAverageBits(UINT32 bits);
UINT32 GetAverageBits();
void SetOversampleBits(UINT32 bits);
UINT32 GetOversampleBits();
UINT32 GetLSBWeight();
INT32 GetOffset();
bool IsAccumulatorChannel();
void InitAccumulator();
void SetAccumulatorInitialValue(INT64 value);
void ResetAccumulator();
void SetAccumulatorCenter(INT32 center);
void SetAccumulatorDeadband(INT32 deadband);
INT64 GetAccumulatorValue();
UINT32 GetAccumulatorCount();
void GetAccumulatorOutput(INT64 *value, UINT32 *count);
double PIDGet();
private:
void InitChannel(UINT32 slot, UINT32 channel);
UINT32 m_channel;
AnalogModule *m_module;
tAccumulator *m_accumulator;
INT64 m_accumulatorOffset;
};
#endif