CTRE Phoenix C++ 5.33.1
CANCoder.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
4#include <cstdint>
18
19namespace ctre {
20 namespace phoenix {
21 namespace sensors {
22
23 /**
24 * Configurables available to CANCoder
25 *
26 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
27 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
28 * Phoenix 6 API. A migration guide is available at
29 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
30 *
31 * If the Phoenix 5 API must be used for this device, the device must have 22.X
32 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
33 * the firmware year dropdown.
34 */
36 /**
37 * Velocity measurement period to use
38 */
40 /**
41 * Velocity measurement window to use
42 */
44 /**
45 * Desired Sign / Range for the absolute position register.
46 * Choose unsigned for an absolute range of[0, +1) rotations, [0, 360) deg, etc.
47 * Choose signed for an absolute range of[-0.5, +0.5) rotations, [-180, +180) deg, etc.
48 */
50 /**
51 * Adjusts the zero point for the absolute position register.
52 * The absolute position of the sensor will always have a discontinuity (360 -> 0 deg) or (+180 -> -180)
53 * and a hard-limited mechanism may have such a discontinuity in its functional range.
54 * In which case use this config to move the discontinuity outside of the function range.
55 */
57 /**
58 * Choose which direction is interpreted as positive displacement.
59 * This affects both "Position"and "Absolute Position".
60 * False(default) means positive rotation occurs when magnet
61 * is spun counter - clockwise when observer is facing the LED side of CANCoder.
62 */
63 bool sensorDirection = false;
64 /**
65 * The sensor initialization strategy to use.This will impact the behavior the next time CANCoder boots up.
66 *
67 * Pick the strategy on how to initialize the CANCoder's "Position" register. Depending on the mechanism,
68 * it may be desirable to auto set the Position register to match the Absolute Position(swerve for example).
69 * Or it may be desired to zero the sensor on boot(drivetrain translation sensor or a relative servo).
70 *
71 * TIP: Tuner's self-test feature will report what the boot sensor value will be in the event the CANCoder is reset.
72 */
74 /**
75 * Scalar to multiply the CANCoder's native 12-bit resolute sensor. Defaults to 0.087890625 to produce degrees.
76 */
77 double sensorCoefficient = 360.0 / 4096.0;
78 /**
79 * String holding the unit to report in. This impacts all routines(except for ConfigMagnetOffset) and the self-test in Tuner.
80 * The string value itself is arbitrary.The max number of letters will depend on firmware versioning, but generally CANCoder
81 * supports up to eight letters.However, common units such as "centimeters" are supported explicitly despite exceeding the eight-letter limit.
82 * Default is "deg"
83 */
84 std::string unitString = "deg";
85 /**
86 * Desired denominator to report velocity in. This impacts GetVelocityand the reported velocity in self-test in Tuner.
87 * Default is "Per Second".
88 */
90
91 /**
92 * Constructor
93 */
94 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
95 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
96 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
98
99 /**
100 * @return String representation of configs
101 */
102 std::string toString() {
103 return toString("");
104 }
105
106 /**
107 * @param prependString
108 * String to prepend to configs
109 * @return String representation of configs
110 */
111 std::string toString(std::string prependString) {
112
113 std::string retstr;
114 retstr += prependString + ".velocityMeasurementPeriod = " + SensorVelocityMeasPeriodRoutines::toString(velocityMeasurementPeriod) + ";\n";
115 retstr += prependString + ".velocityMeasurementWindow = " + std::to_string(velocityMeasurementWindow) + ";\n";
116 retstr += prependString + ".absoluteSensorRange = " + std::to_string(absoluteSensorRange) + ";\n";
117 retstr += prependString + ".magnetOffsetDegrees = " + std::to_string(magnetOffsetDegrees) + ";\n";
118 retstr += prependString + ".sensorDirection = " + std::to_string(sensorDirection) + ";\n";
119 retstr += prependString + ".initializationStrategy = " + std::to_string(initializationStrategy) + ";\n";
120 retstr += prependString + ".sensorCoefficient = " + std::to_string(sensorCoefficient) + ";\n";
121 retstr += prependString + ".unitString = \"" + unitString.c_str() + "\";\n";
122 retstr += prependString + ".sensorTimeBase = " + std::to_string(sensorTimeBase) + ";\n";
123 retstr += CustomParamConfiguration::toString(prependString);
124
125 return retstr;
126 }
127
128 };// struct CANCoderConfiguration
129
130 /**
131 * Util class to help with configuring CANCoder
132 *
133 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
134 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
135 * Phoenix 6 API. A migration guide is available at
136 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
137 *
138 * If the Phoenix 5 API must be used for this device, the device must have 22.X
139 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
140 * the firmware year dropdown.
141 */
142 struct [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
143 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
144 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
146 private:
147 static CANCoderConfiguration _default;
148 public:
149 /**
150 * Determine if specified value is different from default
151 * @param settings settings to compare against
152 * @return if specified value is different from default
153 * @{
154 */
155 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
156 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
157 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
159 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
160 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
161 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
163 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
164 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
165 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
166 static bool AbsoluteSensorRangeDifferent(const CANCoderConfiguration& settings) { return (!(settings.absoluteSensorRange == _default.absoluteSensorRange)) || !settings.enableOptimizations; }
167 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
168 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
169 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
170 static bool MagnetOffsetDegreesDifferent(const CANCoderConfiguration& settings) { return (!(settings.magnetOffsetDegrees == _default.magnetOffsetDegrees)) || !settings.enableOptimizations; }
171 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
172 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
173 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
174 static bool SensorDirectionDifferent(const CANCoderConfiguration& settings) { return (!(settings.sensorDirection == _default.sensorDirection)) || !settings.enableOptimizations; }
175 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
176 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
177 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
178 static bool InitializationStrategyDifferent(const CANCoderConfiguration& settings) { return (!(settings.initializationStrategy == _default.initializationStrategy)) || !settings.enableOptimizations; }
179 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
180 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
181 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
182 static bool SensorCoefficientDifferent(const CANCoderConfiguration& settings) { return (!(settings.sensorCoefficient == _default.sensorCoefficient)) || !settings.enableOptimizations; }
183 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
184 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
185 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
186 static bool UnitStringDifferent(const CANCoderConfiguration& settings) { return (!(settings.unitString == _default.unitString)) || !settings.enableOptimizations; }
187 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
188 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
189 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
190 static bool SensorTimeBaseDifferent(const CANCoderConfiguration& settings) { return (!(settings.sensorTimeBase == _default.sensorTimeBase)) || !settings.enableOptimizations; }
191 /** @} */
192 };
193
194
195 /**
196 * CTRE CANCoder.
197 *
198 * <pre>
199 * {@code
200 * // Example usage of a CANCoder
201 * CANCoder cancoder{0}; // creates a new CANCoder with ID 0
202 *
203 * CANCoderConfiguration config;
204 * // set units of the CANCoder to radians, with velocity being radians per second
205 * config.sensorCoefficient = 2 * M_PI / 4096.0;
206 * config.unitString = "rad";
207 * config.sensorTimeBase = SensorTimeBase::PerSecond;
208 * cancoder.ConfigAllSettings(config);
209 *
210 * std::cout << cancoder.GetPosition() << std::endl; // prints the position of the CANCoder
211 * std::cout << cancoder.GetVelocity() << std::endl; // prints the velocity recorded by the CANCoder
212 *
213 * ErrorCode error = cancoder.GetLastError(); // gets the last error generated by the CANCoder
214 * CANCoderFaults faults;
215 * ErrorCode faultsError = cancoder.GetFaults(faults); // fills faults with the current CANCoder faults; returns the last error generated
216 *
217 * cancoder.SetStatusFramePeriod(CANCoderStatusFrame_SensorData, 10); // changes the period of the sensor data frame to 10ms
218 * }
219 * </pre>
220 *
221 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
222 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
223 * Phoenix 6 API. A migration guide is available at
224 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
225 *
226 * If the Phoenix 5 API must be used for this device, the device must have 22.X
227 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
228 * the firmware year dropdown.
229 */
230 class [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
231 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
232 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
233 CANCoder : public CANBusAddressable {
234 public:
235 /**
236 * Constructor.
237 * @param deviceNumber The CAN Device ID of the CANCoder.
238 * @param canbus Name of the CANbus; can be a SocketCAN interface (on Linux),
239 * or a CANivore device name or serial number
240 */
241 CANCoder(int deviceNumber, std::string const &canbus = "");
242
244
245 /**
246 * Destructs all CANCoder objects
247 */
248 static void DestroyAllCANCoders();
249
250
251 /**
252 * Gets the position of the sensor. This may be relative or absolute depending on configuration.
253 * The units are determined by the coefficient and unit-string configuration params, default is degrees.
254 * @return The position of the sensor.
255 */
256 double GetPosition();
257 /**
258 * Sets the position of the sensor.
259 * The units are determined by the coefficient and unit-string configuration params, default is degrees.
260 * @param newPosition
261 * @return ErrorCode generated by function. 0 indicates no error.
262 */
263 double GetVelocity();
264 /**
265 * Sets the position of the sensor.
266 * The units are determined by the coefficient and unit-string configuration params, default is degrees.
267 * @param newPosition
268 * @return ErrorCode generated by function. 0 indicates no error.
269 */
270 ErrorCode SetPosition(double newPosition, int timeoutMs = 0);
271 /**
272 * Sets the position of the sensor to match the magnet's "Absolute Sensor".
273 * The units are determined by the coefficient and unit-string configuration params, default is degrees.
274 * @return ErrorCode generated by function. 0 indicates no error.
275 */
277
278 /**
279 * Gets the absolute position of the sensor.
280 * The absolute position may be unsigned (for example: [0,360) deg), or signed (for example: [-180,+180) deg). This is determined by a configuration. The default selection is unsigned.
281 * The units are determined by the coefficient and unit-string configuration params, default is degrees.
282 * Note: this signal is not affected by calls to SetPosition().
283 * @return The position of the sensor.
284 */
286 /**
287 * Configures the period of each velocity sample.
288 * Every 1ms a position value is sampled, and the delta between that sample
289 * and the position sampled kPeriod ms ago is inserted into a filter.
290 * kPeriod is configured with this function.
291 *
292 * @param period Desired period for the velocity measurement.
293 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
294 * config success and report an error if it times out.
295 * If zero, no blocking or checking is performed.
296 * @return Error Code generated by function. 0 indicates no error.
297 */
299 /**
300 * Sets the number of velocity samples used in the rolling average velocity
301 * measurement.
302 *
303 * @param windowSize Number of samples in the rolling average of velocity
304 * measurement. Valid values are 1,2,4,8,16,32. If another
305 * value is specified, it will truncate to nearest support value.
306 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
307 * config success and report an error if it times out.
308 * If zero, no blocking or checking is performed.
309 * @return Error Code generated by function. 0 indicates no error.
310 */
311 ErrorCode ConfigVelocityMeasurementWindow(int windowSize, int timeoutMs = 0);
312 /**
313 * Sets the signage and range of the "Absolute Position" signal.
314 * Choose unsigned for an absolute range of [0,+1) rotations, [0,360) deg, etc...
315 * Choose signed for an absolute range of [-0.5,+0.5) rotations, [-180,+180) deg, etc...
316 * @param absoluteSensorRange
317 * Desired Sign/Range for the absolute position register.
318 * @param timeoutMs
319 * Timeout value in ms. If nonzero, function will wait for
320 * config success and report an error if it times out.
321 * If zero, no blocking or checking is performed.
322 * @return Error Code generated by function. 0 indicates no error.
323 */
325 /**
326 * Adjusts the zero point for the absolute position register.
327 * The absolute position of the sensor will always have a discontinuity (360 -> 0 deg) or (+180 -> -180)
328 * and a hard-limited mechanism may have such a discontinuity in its functional range.
329 * In which case use this config to move the discontinuity outside of the function range.
330 * @param offsetDegrees
331 * Offset in degrees (unit string and coefficient DO NOT apply for this config).
332 * @param timeoutMs
333 * Timeout value in ms. If nonzero, function will wait for
334 * config success and report an error if it times out.
335 * If zero, no blocking or checking is performed.
336 * @return Error Code generated by function. 0 indicates no error.
337 */
338 ErrorCode ConfigMagnetOffset(double offsetDegrees, int timeoutMs = 0);
339 /**
340 * Pick the strategy on how to initialize the CANCoder's "Position" register. Depending on the mechanism,
341 * it may be desirable to auto set the Position register to match the Absolute Position (swerve for example).
342 * Or it may be desired to zero the sensor on boot (drivetrain translation sensor or a relative servo).
343 *
344 * TIP: Tuner's self-test feature will report what the boot sensor value will be in the event the CANCoder is reset.
345 *
346 * @param initializationStrategy
347 * The sensor initialization strategy to use. This will impact the behavior the next time CANCoder boots up.
348 * @param timeoutMs
349 * Timeout value in ms. If nonzero, function will wait for
350 * config success and report an error if it times out.
351 * If zero, no blocking or checking is performed.
352 * @return Error Code generated by function. 0 indicates no error.
353 */
355 /**
356 * Choose what units you want the API to get/set. This also impacts the units displayed in Self-Test in Tuner.
357 * Depending on your mechanism, you may want to scale rotational units (deg, radians, rotations), or scale to a distance (inches, centimeters).
358 * @param sensorCoefficient
359 * Scalar to multiply the CANCoder's native 12-bit resolute sensor. Defaults to 0.087890625 to produce degrees.
360 * @param unitString
361 * String holding the unit to report in. This impacts all routines (except for ConfigMagnetOffset) and the self-test in Tuner.
362 * The string value itself is arbitrary. The max number of letters will depend on firmware versioning, but generally CANCoder
363 * supports up to eight letters. However, common units such as "centimeters" are supported explicitly despite exceeding the eight-letter limit.
364 * Default is "deg"
365 * @param sensortimeBase
366 * Desired denominator to report velocity in. This impacts GetVelocity and the reported velocity in self-test in Tuner.
367 * Default is "Per Second".
368 * @param timeoutMs
369 * Timeout value in ms. If nonzero, function will wait for
370 * config success and report an error if it times out.
371 * If zero, no blocking or checking is performed.
372 * @return Error Code generated by function. 0 indicates no error.
373 */
374 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
375 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
376 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
377 ErrorCode ConfigFeedbackCoefficient(double sensorCoefficient, const std::string& unitString, ctre::phoenix::sensors::SensorTimeBase sensortimeBase, int timeoutMs = 0);
378
379 /**
380 * Gets the bus voltage seen by the device.
381 *
382 * @return The bus voltage value (in volts).
383 */
385 /**
386 * Gets the magnet's health.
387 *
388 * @return The magnet health code (red/orange/green).
389 */
390 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
391 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
392 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
394
395 /**
396 * Choose which direction is interpreted as positive displacement.
397 * This affects both "Position" and "Absolute Position".
398 * @param bSensorDirection
399 * False (default) means positive rotation occurs when magnet
400 * is spun counter-clockwise when observer is facing the LED side of CANCoder.
401 * @param timeoutMs
402 * Timeout value in ms. If nonzero, function will wait for
403 * config success and report an error if it times out.
404 * If zero, no blocking or checking is performed.
405 * @return Error Code generated by function. 0 indicates no error.
406 */
407 ErrorCode ConfigSensorDirection(bool bSensorDirection, int timeoutMs = 0);
408
409 /**
410 * Call GetLastError() generated by this object.
411 * Not all functions return an error code but can
412 * potentially report errors.
413 *
414 * This function can be used to retrieve those error codes.
415 *
416 * @return The last ErrorCode generated.
417 */
419
420 /**
421 * Get the units for the signal retrieved in the last called get routine.
422 */
423 std::string GetLastUnitString();
424
425 /**
426 *Get the timestamp of the CAN frame retrieved in the last called get routine.
427 */
429
430 /**
431 * Sets the value of a custom parameter. This is for arbitrary use.
432 *
433 * Sometimes it is necessary to save calibration/duty cycle/output
434 * information in the device. Particularly if the
435 * device is part of a subsystem that can be replaced.
436 *
437 * @param newValue Value for custom parameter.
438 * @param paramIndex Index of custom parameter. [0-1]
439 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
440 * config success and report an error if it times out.
441 * If zero, no blocking or checking is performed.
442 * @return Error Code generated by function. 0 indicates no error.
443 */
444 ErrorCode ConfigSetCustomParam(int newValue, int paramIndex,
445 int timeoutMs = 0);
446 /**
447 * Gets the value of a custom parameter. This is for arbitrary use.
448 *
449 * Sometimes it is necessary to save calibration/duty cycle/output
450 * information in the device. Particularly if the
451 * device is part of a subsystem that can be replaced.
452 *
453 * @param paramIndex Index of custom parameter. [0-1]
454 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
455 * config success and report an error if it times out.
456 * If zero, no blocking or checking is performed.
457 * @return Value of the custom param.
458 */
459 int ConfigGetCustomParam(int paramIndex,
460 int timeoutMs = 0);
461 //------ Generic Param API, typically not used ----------//
462 /**
463 * Sets a parameter. Generally this is not used.
464 * This can be utilized in
465 * - Using new features without updating API installation.
466 * - Errata workarounds to circumvent API implementation.
467 * - Allows for rapid testing / unit testing of firmware.
468 *
469 * @param param Parameter enumeration.
470 * @param value Value of parameter.
471 * @param subValue Subvalue for parameter. Maximum value of 255.
472 * @param ordinal Ordinal of parameter.
473 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
474 * config success and report an error if it times out.
475 * If zero, no blocking or checking is performed.
476 * @return Error Code generated by function. 0 indicates no error.
477 */
479 uint8_t subValue, int ordinal, int timeoutMs = 0);
480 /**
481 * Gets a parameter. Generally this is not used.
482 * This can be utilized in
483 * - Using new features without updating API installation.
484 * - Errata workarounds to circumvent API implementation.
485 * - Allows for rapid testing / unit testing of firmware.
486 *
487 * @param param Parameter enumeration.
488 * @param ordinal Ordinal of parameter.
489 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
490 * config success and report an error if it times out.
491 * If zero, no blocking or checking is performed.
492 * @return Value of parameter.
493 */
494 double ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs = 0);
495
496 /**
497 * Gets a parameter by passing an int by reference
498 *
499 * @param param
500 * Parameter enumeration
501 * @param valueToSend
502 * Value to send to parameter
503 * @param valueReceived
504 * Reference to integer to receive
505 * @param subValue
506 * SubValue of parameter
507 * @param ordinal
508 * Ordinal of parameter
509 * @param timeoutMs
510 * Timeout value in ms. If nonzero, function will wait for
511 * config success and report an error if it times out.
512 * If zero, no blocking or checking is performed.
513 * @return Error Code generated by function. 0 indicates no error.
514 */
515 ErrorCode ConfigGetParameter(ParamEnum param, int32_t valueToSend,
516 int32_t& valueReceived, uint8_t& subValue, int32_t ordinal,
517 int32_t timeoutMs);
518
519
520 /**
521 * Sets the period of the given status frame.
522 *
523 * @param statusFrame Frame whose period is to be changed.
524 * @param periodMs Period in ms for the given frame.
525 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
526 * config success and report an error if it times out.
527 * If zero, no blocking or checking is performed.
528 * @return Error Code generated by function. 0 indicates no error.
529 */
530 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
531 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
532 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
534 uint8_t periodMs, int timeoutMs = 0);
535 /**
536 * Gets the period of the given status frame.
537 *
538 * @param frame Frame to get the period of.
539 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
540 * config success and report an error if it times out.
541 * If zero, no blocking or checking is performed.
542 * @return Period of the given status frame.
543 */
544 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
545 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
546 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
547 int GetStatusFramePeriod(CANCoderStatusFrame frame, int timeoutMs = 0);
548 /**
549 * Gets the firmware version of the device.
550 *
551 * @return Firmware version of device.
552 */
554 /**
555 * Returns true if the device has reset since last call.
556 *
557 * @return Has a Device Reset Occurred?
558 */
560 /**
561 * Gets the CANCoder fault status
562 *
563 * @param toFill
564 * Container for fault statuses.
565 * @return Error Code generated by function. 0 indicates no error.
566 */
567 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
568 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
569 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
571 /**
572 * Gets the CANCoder sticky fault status
573 *
574 * @param toFill
575 * Container for sticky fault statuses.
576 * @return Error Code generated by function. 0 indicates no error.
577 */
578 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
579 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
580 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
582 /**
583 * Clears the Sticky Faults
584 *
585 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
586 * config success and report an error if it times out.
587 * If zero, no blocking or checking is performed.
588 *
589 * @return Error Code generated by function. 0 indicates no error.
590 */
591 ErrorCode ClearStickyFaults(int timeoutMs = 0);
592
593 //------ All Configs ----------//
594 /**
595 * Configures all persistent settings.
596 *
597 * @param allConfigs Object with all of the persistant settings
598 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
599 * config success and report an error if it times out.
600 * If zero, no blocking or checking is performed.
601 *
602 * @return Error Code generated by function. 0 indicates no error.
603 */
604 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
605 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
606 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
608 /**
609 * Gets all persistant settings.
610 *
611 * @param allConfigs Object with all of the persistant settings
612 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
613 * config success and report an error if it times out.
614 * If zero, no blocking or checking is performed.
615 * @return Error Code generated by function. 0 indicates no error.
616 */
617 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
618 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
619 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
620 ErrorCode GetAllConfigs(CANCoderConfiguration& allConfigs, int timeoutMs = 50);
621 /**
622 * Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms).
623 *
624 * @param timeoutMs Timeout value in ms. If nonzero, function will wait for
625 * config success and report an error if it times out.
626 * If zero, no blocking or checking is performed.
627 *
628 * @return Error Code generated by function. 0 indicates no error.
629 */
630 ErrorCode ConfigFactoryDefault(int timeoutMs = 50);
631
632 /**
633 * @return object that can set simulation inputs.
634 */
635 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
636 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
637 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
639
640 private:
641 void* m_handle;
642 CANCoderSimCollection* _simCollection;
643
644 };// class CANCoder
645
646 } // namespace sensor
647 } // namespace phoenix
648} // namespace ctre
Simple address holder.
Definition: CANBusAddressable.h:9
CTRE CANCoder.
Definition: CANCoder.h:233
ErrorCode SetPositionToAbsolute(int timeoutMs=0)
Sets the position of the sensor to match the magnet's "Absolute Sensor".
int GetStatusFramePeriod(CANCoderStatusFrame frame, int timeoutMs=0)
Gets the period of the given status frame.
ErrorCode ConfigSensorInitializationStrategy(ctre::phoenix::sensors::SensorInitializationStrategy initializationStrategy, int timeoutMs=0)
Pick the strategy on how to initialize the CANCoder's "Position" register.
ErrorCode ConfigSetParameter(ParamEnum param, double value, uint8_t subValue, int ordinal, int timeoutMs=0)
Sets a parameter.
double GetLastTimestamp()
Get the timestamp of the CAN frame retrieved in the last called get routine.
ErrorCode ConfigMagnetOffset(double offsetDegrees, int timeoutMs=0)
Adjusts the zero point for the absolute position register.
ErrorCode GetFaults(CANCoderFaults &toFill)
Gets the CANCoder fault status.
ErrorCode GetLastError()
Call GetLastError() generated by this object.
int GetFirmwareVersion()
Gets the firmware version of the device.
ErrorCode ConfigVelocityMeasurementWindow(int windowSize, int timeoutMs=0)
Sets the number of velocity samples used in the rolling average velocity measurement.
CANCoderSimCollection & GetSimCollection()
double GetPosition()
Gets the position of the sensor.
ErrorCode ClearStickyFaults(int timeoutMs=0)
Clears the Sticky Faults.
double GetVelocity()
Sets the position of the sensor.
ErrorCode ConfigVelocityMeasurementPeriod(SensorVelocityMeasPeriod period, int timeoutMs=0)
Configures the period of each velocity sample.
static void DestroyAllCANCoders()
Destructs all CANCoder objects.
ctre::phoenix::sensors::MagnetFieldStrength GetMagnetFieldStrength()
Gets the magnet's health.
int ConfigGetCustomParam(int paramIndex, int timeoutMs=0)
Gets the value of a custom parameter.
double GetBusVoltage()
Gets the bus voltage seen by the device.
ErrorCode ConfigSetCustomParam(int newValue, int paramIndex, int timeoutMs=0)
Sets the value of a custom parameter.
ErrorCode ConfigFeedbackCoefficient(double sensorCoefficient, const std::string &unitString, ctre::phoenix::sensors::SensorTimeBase sensortimeBase, int timeoutMs=0)
Choose what units you want the API to get/set.
ErrorCode GetStickyFaults(CANCoderStickyFaults &toFill)
Gets the CANCoder sticky fault status.
ErrorCode ConfigSensorDirection(bool bSensorDirection, int timeoutMs=0)
Choose which direction is interpreted as positive displacement.
CANCoder(int deviceNumber, std::string const &canbus="")
Constructor.
ErrorCode ConfigAbsoluteSensorRange(ctre::phoenix::sensors::AbsoluteSensorRange absoluteSensorRange, int timeoutMs=0)
Sets the signage and range of the "Absolute Position" signal.
double GetAbsolutePosition()
Gets the absolute position of the sensor.
ErrorCode SetStatusFramePeriod(CANCoderStatusFrame statusFrame, uint8_t periodMs, int timeoutMs=0)
Sets the period of the given status frame.
ErrorCode SetPosition(double newPosition, int timeoutMs=0)
Sets the position of the sensor.
ErrorCode ConfigGetParameter(ParamEnum param, int32_t valueToSend, int32_t &valueReceived, uint8_t &subValue, int32_t ordinal, int32_t timeoutMs)
Gets a parameter by passing an int by reference.
double ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs=0)
Gets a parameter.
ErrorCode GetAllConfigs(CANCoderConfiguration &allConfigs, int timeoutMs=50)
Gets all persistant settings.
ErrorCode ConfigFactoryDefault(int timeoutMs=50)
Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms).
std::string GetLastUnitString()
Get the units for the signal retrieved in the last called get routine.
ctre::phoenix::ErrorCode ConfigAllSettings(const CANCoderConfiguration &allConfigs, int timeoutMs=50)
Configures all persistent settings.
bool HasResetOccurred()
Returns true if the device has reset since last call.
Collection of simulation functions available to a CANCoder.
Definition: CANCoderSimCollection.h:33
static std::string toString(SensorVelocityMeasPeriod value)
String representation of specified CANCoderVelocityMeasPeriod.
Definition: SensorVelocityMeasPeriod.h:58
SensorInitializationStrategy
Enum for how CANCoder should initialize its position register on boot.
Definition: SensorInitializationStrategy.h:22
@ BootToZero
On boot up, set position to zero.
Definition: SensorInitializationStrategy.h:26
MagnetFieldStrength
Indicates the magnet field strength of a magnet-based sensor.
Definition: MagnetFieldStrength.h:21
CANCoderStatusFrame
Enumerated type for status frame types.
Definition: CANCoderStatusFrame.h:23
SensorTimeBase
Velocity Measurement Periods.
Definition: SensorTimeBase.h:23
@ PerSecond
Per-Second Velocities.
Definition: SensorTimeBase.h:31
SensorVelocityMeasPeriod
Enumerate filter periods for any sensor that measures velocity.
Definition: SensorVelocityMeasPeriod.h:13
AbsoluteSensorRange
Enum for how to range the absolute sensor position.
Definition: AbsoluteSensorRange.h:22
@ Unsigned_0_to_360
Express the absolute position as an unsigned value.
Definition: AbsoluteSensorRange.h:27
ParamEnum
Signal enumeration for generic signal access.
Definition: paramEnum.h:13
ErrorCode
Definition: ErrorCode.h:13
@ Period_100Ms
100ms velocity measurement period
Definition: CANifierVelocityMeasPeriod.h:44
namespace ctre
Definition: paramEnum.h:5
Util class to help custom configs.
Definition: CustomParamConfiguration.h:53
Configurables for any custom param configs.
Definition: CustomParamConfiguration.h:11
bool enableOptimizations
Enable optimizations for ConfigAll (defaults true)
Definition: CustomParamConfiguration.h:23
std::string toString()
Definition: CustomParamConfiguration.h:34
Util class to help with configuring CANCoder.
Definition: CANCoder.h:145
static bool UnitStringDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:186
static bool SensorTimeBaseDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:190
static bool AbsoluteSensorRangeDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:166
static bool MagnetOffsetDegreesDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:170
static bool SensorDirectionDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:174
static bool VelocityMeasurementPeriodDifferent(const CANCoderConfiguration &settings)
Determine if specified value is different from default.
Definition: CANCoder.h:158
static bool InitializationStrategyDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:178
static bool VelocityMeasurementWindowDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:162
static bool SensorCoefficientDifferent(const CANCoderConfiguration &settings)
Definition: CANCoder.h:182
Configurables available to CANCoder.
Definition: CANCoder.h:35
ctre::phoenix::sensors::AbsoluteSensorRange absoluteSensorRange
Desired Sign / Range for the absolute position register.
Definition: CANCoder.h:49
int velocityMeasurementWindow
Velocity measurement window to use.
Definition: CANCoder.h:43
ctre::phoenix::sensors::SensorTimeBase sensorTimeBase
Desired denominator to report velocity in.
Definition: CANCoder.h:89
double sensorCoefficient
Scalar to multiply the CANCoder's native 12-bit resolute sensor.
Definition: CANCoder.h:77
std::string toString(std::string prependString)
Definition: CANCoder.h:111
bool sensorDirection
Choose which direction is interpreted as positive displacement.
Definition: CANCoder.h:63
double magnetOffsetDegrees
Adjusts the zero point for the absolute position register.
Definition: CANCoder.h:56
SensorVelocityMeasPeriod velocityMeasurementPeriod
Velocity measurement period to use.
Definition: CANCoder.h:39
std::string toString()
Definition: CANCoder.h:102
ctre::phoenix::sensors::SensorInitializationStrategy initializationStrategy
The sensor initialization strategy to use.This will impact the behavior the next time CANCoder boots ...
Definition: CANCoder.h:73
std::string unitString
String holding the unit to report in.
Definition: CANCoder.h:84
CANCoderConfiguration()
Constructor.
Definition: CANCoder.h:97
Faults available to CANCoderFaults.
Definition: CANCoderFaults.h:23
Sticky Faults for CANCoder (Currently has none)
Definition: CANCoderStickyFaults.h:23