forked from rbmj/wpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalogPotentiometer.cpp
144 lines (128 loc) · 4.76 KB
/
AnalogPotentiometer.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "AnalogPotentiometer.h"
/**
* Class for reading analog potentiometers. Analog potentiometers read
* in an analog voltage that corresponds to a position. Usually the
* position is either degrees or meters. However, if no conversion is
* given it remains volts.
*
*/
void AnalogPotentiometer::InitPot(int slot, int channel, double scale, double offset) {
m_module = slot;
m_channel = channel;
m_scale = scale;
m_offset = offset;
m_analog_channel = new AnalogChannel(slot, channel);
}
/**
* AnalogPotentiometer constructor.
*
* Use the scaling and offset values so that the output produces
* meaningful values. I.E: you have a 270 degree potentiometer and
* you want the output to be degrees with the halfway point as 0
* degrees. The scale value is 270.0(degrees)/5.0(volts) and the
* offset is -135.0 since the halfway point after scaling is 135
* degrees.
*
* @param slot The analog module this potentiometer is plugged into.
* @param channel The analog channel this potentiometer is plugged into.
* @param scale The scaling to multiply the voltage by to get a meaningful unit.
* @param offset The offset to add to the scaled value for controlling the zero value
*/
AnalogPotentiometer::AnalogPotentiometer(int slot, int channel, double scale, double offset) {
InitPot(slot, channel, scale, offset);
}
/**
* AnalogPotentiometer constructor.
*
* Use the scaling and offset values so that the output produces
* meaningful values. I.E: you have a 270 degree potentiometer and
* you want the output to be degrees with the halfway point as 0
* degrees. The scale value is 270.0(degrees)/5.0(volts) and the
* offset is -135.0 since the halfway point after scaling is 135
* degrees.
*
* @param channel The analog channel this potentiometer is plugged into.
* @param scale The scaling to multiply the voltage by to get a meaningful unit.
* @param offset The offset to add to the scaled value for controlling the zero value
*/
AnalogPotentiometer::AnalogPotentiometer(int channel, double scale, double offset) {
InitPot(1, channel, scale, offset);
}
/**
* AnalogPotentiometer constructor.
*
* Use the scaling and offset values so that the output produces
* meaningful values. I.E: you have a 270 degree potentiometer and
* you want the output to be degrees with the halfway point as 0
* degrees. The scale value is 270.0(degrees)/5.0(volts) and the
* offset is -135.0 since the halfway point after scaling is 135
* degrees.
*
* @param channel The analog channel this potentiometer is plugged into.
* @param scale The scaling to multiply the voltage by to get a meaningful unit.
*/
AnalogPotentiometer::AnalogPotentiometer(int channel, double scale) {
InitPot(1, channel, scale, 0);
}
/**
* AnalogPotentiometer constructor.
*
* @param channel The analog channel this potentiometer is plugged into.
*/
AnalogPotentiometer::AnalogPotentiometer(int channel) {
InitPot(1, channel, 1, 0);
}
/**
* Get the current reading of the potentiomere.
*
* @return The current position of the potentiometer.
*/
double AnalogPotentiometer::Get() {
return m_analog_channel->GetVoltage() * m_scale + m_offset;
}
/**
* Implement the PIDSource interface.
*
* @return The current reading.
*/
double AnalogPotentiometer::PIDGet() {
return Get();
}
/*
* Live Window code, only does anything if live window is activated.
*/
std::string AnalogPotentiometer::GetSmartDashboardType(){
return "Analog Input";
}
ITable *m_table;
/**
* {@inheritDoc}
*/
void AnalogPotentiometer::InitTable(ITable *subtable) {
m_table = subtable;
UpdateTable();
}
/**
* {@inheritDoc}
*/
void AnalogPotentiometer::UpdateTable() {
if (m_table != NULL) {
m_table->PutNumber("Value", Get());
}
}
/**
* {@inheritDoc}
*/
ITable * AnalogPotentiometer::GetTable(){
return m_table;
}
/**
* Analog Channels don't have to do anything special when entering the LiveWindow.
* {@inheritDoc}
*/
void AnalogPotentiometer::StartLiveWindowMode() {}
/**
* Analog Channels don't have to do anything special when exiting the LiveWindow.
* {@inheritDoc}
*/
void AnalogPotentiometer::StopLiveWindowMode() {}