forked from rbmj/wpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalogChannel.h
90 lines (73 loc) · 2.87 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
78
79
80
81
82
83
84
85
86
87
88
89
90
/*----------------------------------------------------------------------------*/
/* 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 "ChipObject.h"
#include "SensorBase.h"
#include "PIDSource.h"
#include "LiveWindow/LiveWindowSendable.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 LiveWindowSendable
{
public:
static const uint8_t kAccumulatorModuleNumber = 1;
static const uint32_t kAccumulatorNumChannels = 2;
static const uint32_t kAccumulatorChannels[kAccumulatorNumChannels];
AnalogChannel(uint8_t moduleNumber, uint32_t channel);
explicit AnalogChannel(uint32_t channel);
virtual ~AnalogChannel();
AnalogModule *GetModule();
int16_t GetValue();
int32_t GetAverageValue();
float GetVoltage();
float GetAverageVoltage();
uint8_t GetModuleNumber();
uint32_t GetChannel();
void SetAverageBits(uint32_t bits);
uint32_t GetAverageBits();
void SetOversampleBits(uint32_t bits);
uint32_t GetOversampleBits();
uint32_t GetLSBWeight();
int32_t GetOffset();
bool IsAccumulatorChannel();
void InitAccumulator();
void SetAccumulatorInitialValue(INT64 value);
void ResetAccumulator();
void SetAccumulatorCenter(int32_t center);
void SetAccumulatorDeadband(int32_t deadband);
INT64 GetAccumulatorValue();
uint32_t GetAccumulatorCount();
void GetAccumulatorOutput(INT64 *value, uint32_t *count);
void SetVoltageForPID(bool shouldUseVoltageForPID);
double PIDGet();
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitChannel(uint8_t moduleNumber, uint32_t channel);
uint32_t m_channel;
AnalogModule *m_module;
tAccumulator *m_accumulator;
INT64 m_accumulatorOffset;
bool m_shouldUseVoltageForPID;
ITable *m_table;
};
#endif