CTRE Phoenix C++ 5.33.1
SensorCollection.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
5
6/* forward proto's */
7namespace ctre {
8 namespace phoenix {
9 namespace motorcontrol {
10 namespace can {
11 class BaseTalon;
12 }
13 }
14 }
15}
16
17namespace ctre {
18 namespace phoenix {
19 namespace motorcontrol {
20
21 /**
22 * Collection of sensors available to a motor controller.
23 *
24 * For best performance and update-rate,
25 * we recommend using the configSelectedFeedbackSensor() and getSelectedSensor*() routines.
26 * However there are occasions where accessing raw sensor values may be useful or convenient.
27 * Particularly if you are seeding one sensor based on another, or need to circumvent sensor-phase.
28 *
29 * Use the getSensorCollection() routine inside your motor controller to create a sensor collection.
30 */
32 public:
33 /**
34 * Constructor for SensorCollection
35 * @param motorController Talon Motor Controller to connect Collection to
36 */
38
39 /**
40 * Get the position of whatever is in the analog pin of the Talon, regardless of
41 * whether it is actually being used for feedback.
42 *
43 * This method relies on the Status 4 message, which has a default period of 150ms. For more
44 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
45 *
46 * @return the 24bit analog value. The bottom ten bits is the ADC (0 - 1023)
47 * on the analog pin of the Talon. The upper 14 bits tracks the overflows and underflows
48 * (continuous sensor).
49 */
50
52
53 /**
54 * Sets analog position.
55 *
56 * @param newPosition The new position.
57 * @param timeoutMs
58 * Timeout value in ms. If nonzero, function will wait for
59 * config success and report an error if it times out.
60 * If zero, no blocking or checking is performed.
61 *
62 * @return an ErrorCode.
63 */
64
65 ErrorCode SetAnalogPosition(int newPosition, int timeoutMs = 0);
66
67 /**
68 * Get the position of whatever is in the analog pin of the Talon, regardless of whether
69 * it is actually being used for feedback.
70 *
71 * This method relies on the Status 4 message, which has a default period of 150ms. For more
72 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
73 *
74 * @return the ADC (0 - 1023) on analog pin of the Talon.
75 */
76
78
79 /**
80 * Get the velocity of whatever is in the analog pin of the Talon, regardless of
81 * whether it is actually being used for feedback.
82 *
83 * This method relies on the Status 4 message, which has a default period of 150ms. For more
84 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
85 *
86 * @return the speed in units per 100ms where 1024 units is one rotation.
87 */
88
90
91 /**
92 * Get the quadrature position of the Talon, regardless of whether
93 * it is actually being used for feedback.
94 *
95 * This method relies on the Status 3 message, which has a default period of 150ms. For more
96 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
97 *
98 * @return the quadrature position.
99 */
100
102
103 /**
104 * Change the quadrature reported position. Typically this is used to "zero" the
105 * sensor. This only works with Quadrature sensor. To set the selected sensor position
106 * regardless of what type it is, see SetSelectedSensorPosition in the motor controller class.
107 *
108 * @param newPosition The position value to apply to the sensor.
109 * @param timeoutMs
110 * Timeout value in ms. If nonzero, function will wait for
111 * config success and report an error if it times out.
112 * If zero, no blocking or checking is performed.
113 *
114 * @return error code.
115 */
116
117 ErrorCode SetQuadraturePosition(int newPosition, int timeoutMs = 0);
118
119 /**
120 * Change the quadrature reported position based on pulse width. This can be used to
121 * effectively make quadrature absolute. For rotary mechanisms with >360 movement (such
122 * as typical swerve modules) bookend0 and bookend1 can be both set to 0 and
123 * bCrossZeroOnInterval can be set to true. For mechanisms with less than 360 travel (such
124 * as arms), bookend0 and bookend1 should be set to the pulse width values at the two
125 * extremes. If the interval crosses over the pulse width value of 0 (or any multiple of
126 * 4096), bCrossZeroOnInterval should be true and otherwise should be false. An offset can
127 * also be set.
128 *
129 * @param bookend0 value at extreme 0
130 * @param bookend1 value at extreme 1
131 * @param bCrossZeroOnInterval value at extreme 1
132 * @param offset (Optional) Value to add to pulse width
133 * @param timeoutMs (Optional) How long to wait for confirmation. Pass zero so that call
134 * does not block.
135 *
136 * @return error code.
137 */
138
139 ErrorCode SyncQuadratureWithPulseWidth(int bookend0, int bookend1, bool bCrossZeroOnInterval, int offset = 0, int timeoutMs = 0);
140
141 /**
142 * Get the quadrature velocity, regardless of whether
143 * it is actually being used for feedback.
144 *
145 * This method relies on the Status 3 message, which has a default period of 150ms. For more
146 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
147 *
148 * @return the quadrature velocity in units per 100ms.
149 */
150
152
153 /**
154 * Gets pulse width position, regardless of whether
155 * it is actually being used for feedback.
156 *
157 * This method relies on the Status 8 message, which has a default period of 150ms. For more
158 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
159 *
160 * @return the pulse width position.
161 */
162
164
165 /**
166 * Sets pulse width position.
167 *
168 * @param newPosition The position value to apply to the sensor.
169 * @param timeoutMs
170 * Timeout value in ms. If nonzero, function will wait for
171 * config success and report an error if it times out.
172 * If zero, no blocking or checking is performed.
173 *
174 * @return an ErrErrorCode
175 */
176 ErrorCode SetPulseWidthPosition(int newPosition, int timeoutMs = 0);
177
178 /**
179 * Gets pulse width velocity, regardless of whether
180 * it is actually being used for feedback.
181 *
182 * This method relies on the Status 8 message, which has a default period of 150ms. For more
183 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
184 *
185 * @return the pulse width velocity in units per 100ms (where 4096 units is 1 rotation).
186 */
187
189
190 /**
191 * Gets pulse width rise to fall time.
192 *
193 * This method relies on the Status 8 message, which has a default period of 150ms. For more
194 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
195 *
196 * @return the pulse width rise to fall time in microseconds.
197 */
198
200
201 /**
202 * Gets pulse width rise to rise time.
203 *
204 * This method relies on the Status 8 message, which has a default period of 150ms. For more
205 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
206 *
207 * @return the pulse width rise to rise time in microseconds.
208 */
209
211
212 /**
213 * Gets pin state quad a.
214 *
215 * This method relies on the Status 3 message, which has a default period of 150ms. For more
216 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
217 *
218 * @return the pin state of quad a (1 if asserted, 0 if not asserted).
219 */
220
222
223 /**
224 * Gets pin state quad b.
225 *
226 * This method relies on the Status 3 message, which has a default period of 150ms. For more
227 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
228 *
229 * @return Digital level of QUADB pin (1 if asserted, 0 if not asserted).
230 */
231
233
234 /**
235 * Gets pin state quad index.
236 *
237 * This method relies on the Status 3 message, which has a default period of 150ms. For more
238 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
239 *
240 * @return Digital level of QUAD Index pin (1 if asserted, 0 if not asserted).
241 */
242
244
245 /**
246 * Is forward limit switch closed.
247 *
248 * This method relies on the Status 1 message, which has a default period of 10ms. For more
249 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
250 *
251 * @return '1' iff forward limit switch is closed, 0 iff switch is open. This function works
252 * regardless if limit switch feature is enabled. Remote limit features do not impact this routine.
253 */
254
256
257 /**
258 * Is reverse limit switch closed.
259 *
260 * This method relies on the Status 1 message, which has a default period of 10ms. For more
261 * information, see: https://phoenix-documentation.readthedocs.io/en/latest/ch18_CommonAPI.html
262 *
263 * @return '1' iff reverse limit switch is closed, 0 iff switch is open. This function works
264 * regardless if limit switch feature is enabled. Remote limit features do not impact this routine.
265 */
266
268
269 private:
270 SensorCollection(void* handle);
272 void* _handle;
273
274 };
275
276 } // namespace motorcontrol
277 } // namespace phoenix
278} // namespace ctre
Collection of sensors available to a motor controller.
Definition: SensorCollection.h:31
int GetPulseWidthRiseToFallUs()
Gets pulse width rise to fall time.
int GetPinStateQuadIdx()
Gets pin state quad index.
int GetQuadratureVelocity()
Get the quadrature velocity, regardless of whether it is actually being used for feedback.
int GetPinStateQuadB()
Gets pin state quad b.
SensorCollection(ctre::phoenix::motorcontrol::can::BaseTalon &motorController)
Constructor for SensorCollection.
int IsFwdLimitSwitchClosed()
Is forward limit switch closed.
int GetPulseWidthRiseToRiseUs()
Gets pulse width rise to rise time.
int GetAnalogInVel()
Get the velocity of whatever is in the analog pin of the Talon, regardless of whether it is actually ...
int GetQuadraturePosition()
Get the quadrature position of the Talon, regardless of whether it is actually being used for feedbac...
int IsRevLimitSwitchClosed()
Is reverse limit switch closed.
ErrorCode SetQuadraturePosition(int newPosition, int timeoutMs=0)
Change the quadrature reported position.
ErrorCode SetPulseWidthPosition(int newPosition, int timeoutMs=0)
Sets pulse width position.
int GetPulseWidthPosition()
Gets pulse width position, regardless of whether it is actually being used for feedback.
int GetPinStateQuadA()
Gets pin state quad a.
int GetPulseWidthVelocity()
Gets pulse width velocity, regardless of whether it is actually being used for feedback.
int GetAnalogIn()
Get the position of whatever is in the analog pin of the Talon, regardless of whether it is actually ...
ErrorCode SyncQuadratureWithPulseWidth(int bookend0, int bookend1, bool bCrossZeroOnInterval, int offset=0, int timeoutMs=0)
Change the quadrature reported position based on pulse width.
int GetAnalogInRaw()
Get the position of whatever is in the analog pin of the Talon, regardless of whether it is actually ...
ErrorCode SetAnalogPosition(int newPosition, int timeoutMs=0)
Sets analog position.
CTRE Talon SRX Motor Controller when used on CAN Bus.
Definition: BaseTalon.h:267
ErrorCode
Definition: ErrorCode.h:13
namespace ctre
Definition: paramEnum.h:5