blob: a1ff1b168b7ddafee59791d3685e62856ab14841 [file] [log] [blame]
Brian Silverman890a32a2018-03-11 15:41:56 -07001#include "ctre/phoenix/MotorControl/SensorCollection.h"
2#include "ctre/phoenix/CCI/MotController_CCI.h"
3
4using namespace ctre::phoenix;
5using namespace ctre::phoenix::motorcontrol;
6
7SensorCollection::SensorCollection(void * handle) {
8 _handle = handle;
9}
10
11/**
12 * Get the position of whatever is in the analog pin of the Talon, regardless of
13 * whether it is actually being used for feedback.
14 *
15 * @return the 24bit analog value. The bottom ten bits is the ADC (0 - 1023)
16 * on the analog pin of the Talon. The upper 14 bits tracks the overflows and underflows
17 * (continuous sensor).
18 */
19
20int SensorCollection::GetAnalogIn() {
21 int retval = 0;
22 c_MotController_GetAnalogIn(_handle, &retval);
23 return retval;
24}
25
26/**
27 * Sets analog position.
28 *
29 * @param newPosition The new position.
30 * @param timeoutMs
31 * Timeout value in ms. If nonzero, function will wait for
32 * config success and report an error if it times out.
33 * If zero, no blocking or checking is performed.
34 *
35 * @return an ErrorCode.
36 */
37
38ErrorCode SensorCollection::SetAnalogPosition(int newPosition, int timeoutMs) {
39 return c_MotController_SetAnalogPosition(_handle, newPosition, timeoutMs);
40}
41
42/**
43 * Get the position of whatever is in the analog pin of the Talon, regardless of whether
44 * it is actually being used for feedback.
45 *
46 * @return the ADC (0 - 1023) on analog pin of the Talon.
47 */
48
49int SensorCollection::GetAnalogInRaw() {
50 int retval = 0;
51 c_MotController_GetAnalogInRaw(_handle, &retval);
52 return retval;
53}
54
55/**
56 * Get the velocity of whatever is in the analog pin of the Talon, regardless of
57 * whether it is actually being used for feedback.
58 *
59 * @return the speed in units per 100ms where 1024 units is one rotation.
60 */
61
62int SensorCollection::GetAnalogInVel() {
63 int retval = 0;
64 c_MotController_GetAnalogInVel(_handle, &retval);
65 return retval;
66}
67
68/**
69 * Get the quadrature position of the Talon, regardless of whether
70 * it is actually being used for feedback.
71 *
72 * @return the quadrature position.
73 */
74
75int SensorCollection::GetQuadraturePosition() {
76 int retval = 0;
77 c_MotController_GetQuadraturePosition(_handle, &retval);
78 return retval;
79}
80
81/**
82 * Change the quadrature reported position. Typically this is used to "zero" the
83 * sensor. This only works with Quadrature sensor. To set the selected sensor position
84 * regardless of what type it is, see SetSelectedSensorPosition in the motor controller class.
85 *
86 * @param newPosition The position value to apply to the sensor.
87 * @param timeoutMs
88 * Timeout value in ms. If nonzero, function will wait for
89 * config success and report an error if it times out.
90 * If zero, no blocking or checking is performed.
91 *
92 * @return error code.
93 */
94
95ErrorCode SensorCollection::SetQuadraturePosition(int newPosition,
96 int timeoutMs) {
97 return c_MotController_SetQuadraturePosition(_handle, newPosition,
98 timeoutMs);
99}
100
101/**
102 * Get the quadrature velocity, regardless of whether
103 * it is actually being used for feedback.
104 *
105 * @return the quadrature velocity in units per 100ms.
106 */
107
108int SensorCollection::GetQuadratureVelocity() {
109 int retval = 0;
110 c_MotController_GetQuadratureVelocity(_handle, &retval);
111 return retval;
112}
113
114/**
115 * Gets pulse width position, regardless of whether
116 * it is actually being used for feedback.
117 *
118 * @return the pulse width position.
119 */
120
121int SensorCollection::GetPulseWidthPosition() {
122 int retval = 0;
123 c_MotController_GetPulseWidthPosition(_handle, &retval);
124 return retval;
125}
126
127/**
128 * Sets pulse width position.
129 *
130 * @param newPosition The position value to apply to the sensor.
131 * @param timeoutMs
132 * Timeout value in ms. If nonzero, function will wait for
133 * config success and report an error if it times out.
134 * If zero, no blocking or checking is performed.
135 *
136 * @return an ErrErrorCode
137 */
138ErrorCode SensorCollection::SetPulseWidthPosition(int newPosition,
139 int timeoutMs) {
140 return c_MotController_SetPulseWidthPosition(_handle, newPosition,
141 timeoutMs);
142}
143
144/**
145 * Gets pulse width velocity, regardless of whether
146 * it is actually being used for feedback.
147 *
148 * @return the pulse width velocity in units per 100ms (where 4096 units is 1 rotation).
149 */
150
151int SensorCollection::GetPulseWidthVelocity() {
152 int retval = 0;
153 c_MotController_GetPulseWidthVelocity(_handle, &retval);
154 return retval;
155}
156
157/**
158 * Gets pulse width rise to fall time.
159 *
160 * @return the pulse width rise to fall time in microseconds.
161 */
162
163int SensorCollection::GetPulseWidthRiseToFallUs() {
164 int retval = 0;
165 c_MotController_GetPulseWidthRiseToFallUs(_handle, &retval);
166 return retval;
167}
168
169/**
170 * Gets pulse width rise to rise time.
171 *
172 * @return the pulse width rise to rise time in microseconds.
173 */
174
175int SensorCollection::GetPulseWidthRiseToRiseUs() {
176 int retval = 0;
177 c_MotController_GetPulseWidthRiseToRiseUs(_handle, &retval);
178 return retval;
179}
180
181/**
182 * Gets pin state quad a.
183 *
184 * @return the pin state of quad a (1 if asserted, 0 if not asserted).
185 */
186
187int SensorCollection::GetPinStateQuadA() {
188 int retval = 0;
189 c_MotController_GetPinStateQuadA(_handle, &retval);
190 return retval;
191}
192
193/**
194 * Gets pin state quad b.
195 *
196 * @return Digital level of QUADB pin (1 if asserted, 0 if not asserted).
197 */
198
199int SensorCollection::GetPinStateQuadB() {
200 int retval = 0;
201 c_MotController_GetPinStateQuadB(_handle, &retval);
202 return retval;
203}
204
205/**
206 * Gets pin state quad index.
207 *
208 * @return Digital level of QUAD Index pin (1 if asserted, 0 if not asserted).
209 */
210
211int SensorCollection::GetPinStateQuadIdx() {
212 int retval = 0;
213 c_MotController_GetPinStateQuadIdx(_handle, &retval);
214 return retval;
215}
216
217/**
218 * Is forward limit switch closed.
219 *
220 * @return '1' iff forward limit switch is closed, 0 iff switch is open. This function works
221 * regardless if limit switch feature is enabled.
222 */
223
224int SensorCollection::IsFwdLimitSwitchClosed() {
225 int retval = 0;
226 c_MotController_IsFwdLimitSwitchClosed(_handle, &retval);
227 return retval;
228}
229
230/**
231 * Is reverse limit switch closed.
232 *
233 * @return '1' iff reverse limit switch is closed, 0 iff switch is open. This function works
234 * regardless if limit switch feature is enabled.
235 */
236
237int SensorCollection::IsRevLimitSwitchClosed() {
238 int retval = 0;
239 c_MotController_IsRevLimitSwitchClosed(_handle, &retval);
240 return retval;
241}