CTRE Phoenix 6 C++ 24.2.0
CoreCANcoder.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
12
14#include <units/angle.h>
15#include <units/angular_velocity.h>
16#include <units/dimensionless.h>
17#include <units/voltage.h>
18
19namespace ctre {
20namespace phoenix6 {
21
22namespace hardware {
23namespace core {
24 class CoreCANcoder;
25}
26}
27
28namespace configs {
29
30/**
31 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
32 * relative position along with filtered velocity.
33 *
34 * This handles the configurations for the hardware#CANcoder
35 */
37{
38public:
39 /**
40 * \brief True if we should factory default newer unsupported configs,
41 * false to leave newer unsupported configs alone.
42 *
43 * \details This flag addresses a corner case where the device may have
44 * firmware with newer configs that didn't exist when this
45 * version of the API was built. If this occurs and this
46 * flag is true, unsupported new configs will be factory
47 * defaulted to avoid unexpected behavior.
48 *
49 * This is also the behavior in Phoenix 5, so this flag
50 * is defaulted to true to match.
51 */
53
54
55 /**
56 * \brief Configs that affect the magnet sensor and how to interpret
57 * it.
58 *
59 * \details Includes sensor range and other configs related to sensor.
60 */
62
63 /**
64 * \brief Modifies this configuration's MagnetSensor parameter and returns itself for
65 * method-chaining and easier to use config API.
66 * \param newMagnetSensor Parameter to modify
67 * \returns Itself
68 */
70 {
71 MagnetSensor = std::move(newMagnetSensor);
72 return *this;
73 }
74
75 /**
76 * \brief Get the string representation of this configuration
77 */
78 std::string ToString() const
79 {
80 std::stringstream ss;
81 ss << MagnetSensor.ToString();
82 return ss.str();
83 }
84
85 /**
86 * \brief Get the serialized form of this configuration
87 */
88 std::string Serialize() const
89 {
90 std::stringstream ss;
91 ss << MagnetSensor.Serialize();
92 return ss.str();
93 }
94
95 /**
96 * \brief Take a string and deserialize it to this configuration
97 */
98 ctre::phoenix::StatusCode Deserialize(const std::string& to_deserialize)
99 {
100 ctre::phoenix::StatusCode err = ctre::phoenix::StatusCode::OK;
101 err = MagnetSensor.Deserialize(to_deserialize);
102 return err;
103 }
104};
105
106/**
107 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
108 * relative position along with filtered velocity.
109 *
110 * This handles the configurations for the hardware#CANcoder
111 */
113{
115 ParentConfigurator{std::move(id)}
116 {}
117
119public:
120
121 /**
122 * Delete the copy constructor, we can only pass by reference
123 */
125
126 /**
127 * \brief Refreshes the values of the specified config group.
128 *
129 * This will wait up to #DefaultTimeoutSeconds.
130 *
131 * \details Call to refresh the selected configs from the device.
132 *
133 * \param configs The configs to refresh
134 * \returns StatusCode of refreshing the configs
135 */
136 ctre::phoenix::StatusCode Refresh(CANcoderConfiguration& configs) const
137 {
138 return Refresh(configs, DefaultTimeoutSeconds);
139 }
140
141 /**
142 * \brief Refreshes the values of the specified config group.
143 *
144 * \details Call to refresh the selected configs from the device.
145 *
146 * \param configs The configs to refresh
147 * \param timeoutSeconds Maximum amount of time to wait when performing configuration
148 * \returns StatusCode of refreshing the configs
149 */
150 ctre::phoenix::StatusCode Refresh(CANcoderConfiguration& configs, units::time::second_t timeoutSeconds) const
151 {
152 std::string ref;
153 ctre::phoenix::StatusCode ret = GetConfigsPrivate(ref, timeoutSeconds);
154 configs.Deserialize(ref);
155 return ret;
156 }
157
158 /**
159 * \brief Applies the contents of the specified config to the device.
160 *
161 * This will wait up to #DefaultTimeoutSeconds.
162 *
163 * \details Call to apply the selected configs.
164 *
165 * \param configs Configs to apply against.
166 * \returns StatusCode of the set command
167 */
168 ctre::phoenix::StatusCode Apply(const CANcoderConfiguration& configs)
169 {
170 return Apply(configs, DefaultTimeoutSeconds);
171 }
172
173 /**
174 * \brief Applies the contents of the specified config to the device.
175 *
176 * \details Call to apply the selected configs.
177 *
178 * \param configs Configs to apply against.
179 * \param timeoutSeconds Maximum amount of time to wait when performing configuration
180 * \returns StatusCode of the set command
181 */
182 ctre::phoenix::StatusCode Apply(const CANcoderConfiguration& configs, units::time::second_t timeoutSeconds)
183 {
184 return SetConfigsPrivate(configs.Serialize(), timeoutSeconds, configs.FutureProofConfigs, false);
185 }
186
187
188 /**
189 * \brief Refreshes the values of the specified config group.
190 *
191 * This will wait up to #DefaultTimeoutSeconds.
192 *
193 * \details Call to refresh the selected configs from the device.
194 *
195 * \param configs The configs to refresh
196 * \returns StatusCode of refreshing the configs
197 */
198 ctre::phoenix::StatusCode Refresh(MagnetSensorConfigs& configs) const
199 {
200 return Refresh(configs, DefaultTimeoutSeconds);
201 }
202 /**
203 * \brief Refreshes the values of the specified config group.
204 *
205 * \details Call to refresh the selected configs from the device.
206 *
207 * \param configs The configs to refresh
208 * \param timeoutSeconds Maximum amount of time to wait when performing configuration
209 * \returns StatusCode of refreshing the configs
210 */
211 ctre::phoenix::StatusCode Refresh(MagnetSensorConfigs& configs, units::time::second_t timeoutSeconds) const
212 {
213 std::string ref;
214 ctre::phoenix::StatusCode ret = GetConfigsPrivate(ref, timeoutSeconds);
215 configs.Deserialize(ref);
216 return ret;
217 }
218
219 /**
220 * \brief Applies the contents of the specified config to the device.
221 *
222 * This will wait up to #DefaultTimeoutSeconds.
223 *
224 * \details Call to apply the selected configs.
225 *
226 * \param configs Configs to apply against.
227 * \returns StatusCode of the set command
228 */
229 ctre::phoenix::StatusCode Apply(const MagnetSensorConfigs& configs)
230 {
231 return Apply(configs, DefaultTimeoutSeconds);
232 }
233
234 /**
235 * \brief Applies the contents of the specified config to the device.
236 *
237 * \details Call to apply the selected configs.
238 *
239 * \param configs Configs to apply against.
240 * \param timeoutSeconds Maximum amount of time to wait when performing configuration
241 * \returns StatusCode of the set command
242 */
243 ctre::phoenix::StatusCode Apply(const MagnetSensorConfigs& configs, units::time::second_t timeoutSeconds)
244 {
245 return SetConfigsPrivate(configs.Serialize(), timeoutSeconds, false, false);
246 }
247
248
249 /**
250 * \brief Sets the current position of the device.
251 *
252 * This will wait up to #DefaultTimeoutSeconds.
253 *
254 * This is available in the configurator in case the user wants
255 * to initialize their device entirely without passing a device
256 * reference down to the code that performs the initialization.
257 * In this case, the user passes down the configurator object
258 * and performs all the initialization code on the object.
259 *
260 * \param newValue Value to set to. Units are in rotations.
261 * \returns StatusCode of the set command
262 */
263 ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue)
264 {
265 return SetPosition(newValue, DefaultTimeoutSeconds);
266 }
267 /**
268 * \brief Sets the current position of the device.
269 *
270 * This is available in the configurator in case the user wants
271 * to initialize their device entirely without passing a device
272 * reference down to the code that performs the initialization.
273 * In this case, the user passes down the configurator object
274 * and performs all the initialization code on the object.
275 *
276 * \param newValue Value to set to. Units are in rotations.
277 * \param timeoutSeconds Maximum time to wait up to in seconds.
278 * \returns StatusCode of the set command
279 */
280 ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue, units::time::second_t timeoutSeconds)
281 {
282 std::stringstream ss;
283 char *ref;
284 c_ctre_phoenix6_serialize_double(ctre::phoenix6::spns::SpnValue::CANCoder_SetSensorPosition, newValue.to<double>(), &ref); if (ref != nullptr) { ss << ref; free(ref); }
285 return SetConfigsPrivate(ss.str(), timeoutSeconds, false, true);
286 }
287
288 /**
289 * \brief Clear the sticky faults in the device.
290 *
291 * \details This typically has no impact on the device functionality.
292 * Instead, it just clears telemetry faults that are accessible via
293 * API and Tuner Self-Test.
294 *
295 * This will wait up to #DefaultTimeoutSeconds.
296 *
297 * This is available in the configurator in case the user wants
298 * to initialize their device entirely without passing a device
299 * reference down to the code that performs the initialization.
300 * In this case, the user passes down the configurator object
301 * and performs all the initialization code on the object.
302 *
303 * \returns StatusCode of the set command
304 */
305 ctre::phoenix::StatusCode ClearStickyFaults()
306 {
308 }
309 /**
310 * \brief Clear the sticky faults in the device.
311 *
312 * \details This typically has no impact on the device functionality.
313 * Instead, it just clears telemetry faults that are accessible via
314 * API and Tuner Self-Test.
315 *
316 * This is available in the configurator in case the user wants
317 * to initialize their device entirely without passing a device
318 * reference down to the code that performs the initialization.
319 * In this case, the user passes down the configurator object
320 * and performs all the initialization code on the object.
321 *
322 * \param timeoutSeconds Maximum time to wait up to in seconds.
323 * \returns StatusCode of the set command
324 */
325 ctre::phoenix::StatusCode ClearStickyFaults(units::time::second_t timeoutSeconds)
326 {
327 std::stringstream ss;
328 char *ref;
329 c_ctre_phoenix6_serialize_double(ctre::phoenix6::spns::SpnValue::SPN_ClearStickyFaults, 0, &ref); if (ref != nullptr) { ss << ref; free(ref); }
330 return SetConfigsPrivate(ss.str(), timeoutSeconds, false, true);
331 }
332
333 /**
334 * \brief Clear sticky fault: Hardware fault occurred
335 *
336 * This will wait up to #DefaultTimeoutSeconds.
337 *
338 * This is available in the configurator in case the user wants
339 * to initialize their device entirely without passing a device
340 * reference down to the code that performs the initialization.
341 * In this case, the user passes down the configurator object
342 * and performs all the initialization code on the object.
343 *
344 * \returns StatusCode of the set command
345 */
346 ctre::phoenix::StatusCode ClearStickyFault_Hardware()
347 {
349 }
350 /**
351 * \brief Clear sticky fault: Hardware fault occurred
352 *
353 * This is available in the configurator in case the user wants
354 * to initialize their device entirely without passing a device
355 * reference down to the code that performs the initialization.
356 * In this case, the user passes down the configurator object
357 * and performs all the initialization code on the object.
358 *
359 * \param timeoutSeconds Maximum time to wait up to in seconds.
360 * \returns StatusCode of the set command
361 */
362 ctre::phoenix::StatusCode ClearStickyFault_Hardware(units::time::second_t timeoutSeconds)
363 {
364 std::stringstream ss;
365 char *ref;
366 c_ctre_phoenix6_serialize_double(ctre::phoenix6::spns::SpnValue::ClearStickyFault_Hardware, 0, &ref); if (ref != nullptr) { ss << ref; free(ref); }
367 return SetConfigsPrivate(ss.str(), timeoutSeconds, false, true);
368 }
369
370 /**
371 * \brief Clear sticky fault: Device supply voltage dropped to near
372 * brownout levels
373 *
374 * This will wait up to #DefaultTimeoutSeconds.
375 *
376 * This is available in the configurator in case the user wants
377 * to initialize their device entirely without passing a device
378 * reference down to the code that performs the initialization.
379 * In this case, the user passes down the configurator object
380 * and performs all the initialization code on the object.
381 *
382 * \returns StatusCode of the set command
383 */
384 ctre::phoenix::StatusCode ClearStickyFault_Undervoltage()
385 {
387 }
388 /**
389 * \brief Clear sticky fault: Device supply voltage dropped to near
390 * brownout levels
391 *
392 * This is available in the configurator in case the user wants
393 * to initialize their device entirely without passing a device
394 * reference down to the code that performs the initialization.
395 * In this case, the user passes down the configurator object
396 * and performs all the initialization code on the object.
397 *
398 * \param timeoutSeconds Maximum time to wait up to in seconds.
399 * \returns StatusCode of the set command
400 */
401 ctre::phoenix::StatusCode ClearStickyFault_Undervoltage(units::time::second_t timeoutSeconds)
402 {
403 std::stringstream ss;
404 char *ref;
405 c_ctre_phoenix6_serialize_double(ctre::phoenix6::spns::SpnValue::ClearStickyFault_Undervoltage, 0, &ref); if (ref != nullptr) { ss << ref; free(ref); }
406 return SetConfigsPrivate(ss.str(), timeoutSeconds, false, true);
407 }
408
409 /**
410 * \brief Clear sticky fault: Device boot while detecting the enable
411 * signal
412 *
413 * This will wait up to #DefaultTimeoutSeconds.
414 *
415 * This is available in the configurator in case the user wants
416 * to initialize their device entirely without passing a device
417 * reference down to the code that performs the initialization.
418 * In this case, the user passes down the configurator object
419 * and performs all the initialization code on the object.
420 *
421 * \returns StatusCode of the set command
422 */
423 ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable()
424 {
426 }
427 /**
428 * \brief Clear sticky fault: Device boot while detecting the enable
429 * signal
430 *
431 * This is available in the configurator in case the user wants
432 * to initialize their device entirely without passing a device
433 * reference down to the code that performs the initialization.
434 * In this case, the user passes down the configurator object
435 * and performs all the initialization code on the object.
436 *
437 * \param timeoutSeconds Maximum time to wait up to in seconds.
438 * \returns StatusCode of the set command
439 */
440 ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable(units::time::second_t timeoutSeconds)
441 {
442 std::stringstream ss;
443 char *ref;
444 c_ctre_phoenix6_serialize_double(ctre::phoenix6::spns::SpnValue::ClearStickyFault_BootDuringEnable, 0, &ref); if (ref != nullptr) { ss << ref; free(ref); }
445 return SetConfigsPrivate(ss.str(), timeoutSeconds, false, true);
446 }
447
448 /**
449 * \brief Clear sticky fault: The magnet distance is not correct or
450 * magnet is missing
451 *
452 * This will wait up to #DefaultTimeoutSeconds.
453 *
454 * This is available in the configurator in case the user wants
455 * to initialize their device entirely without passing a device
456 * reference down to the code that performs the initialization.
457 * In this case, the user passes down the configurator object
458 * and performs all the initialization code on the object.
459 *
460 * \returns StatusCode of the set command
461 */
462 ctre::phoenix::StatusCode ClearStickyFault_BadMagnet()
463 {
465 }
466 /**
467 * \brief Clear sticky fault: The magnet distance is not correct or
468 * magnet is missing
469 *
470 * This is available in the configurator in case the user wants
471 * to initialize their device entirely without passing a device
472 * reference down to the code that performs the initialization.
473 * In this case, the user passes down the configurator object
474 * and performs all the initialization code on the object.
475 *
476 * \param timeoutSeconds Maximum time to wait up to in seconds.
477 * \returns StatusCode of the set command
478 */
479 ctre::phoenix::StatusCode ClearStickyFault_BadMagnet(units::time::second_t timeoutSeconds)
480 {
481 std::stringstream ss;
482 char *ref;
483 c_ctre_phoenix6_serialize_double(ctre::phoenix6::spns::SpnValue::ClearStickyFault_CANCODER_BadMagnet, 0, &ref); if (ref != nullptr) { ss << ref; free(ref); }
484 return SetConfigsPrivate(ss.str(), timeoutSeconds, false, true);
485 }
486};
487
488}
489
490namespace hardware {
491namespace core {
492
493/**
494 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
495 * relative position along with filtered velocity.
496 */
498{
499private:
501
502
503public:
504 /**
505 * Constructs a new CANcoder object.
506 *
507 * \param deviceId ID of the device, as configured in Phoenix Tuner.
508 * \param canbus Name of the CAN bus this device is on. Possible CAN bus strings are:
509 * - "rio" for the native roboRIO CAN bus
510 * - CANivore name or serial number
511 * - SocketCAN interface (non-FRC Linux only)
512 * - "*" for any CANivore seen by the program
513 * - empty string (default) to select the default for the system:
514 * - "rio" on roboRIO
515 * - "can0" on Linux
516 * - "*" on Windows
517 */
518 CoreCANcoder(int deviceId, std::string canbus = "");
519
520 CoreCANcoder(CoreCANcoder const &) = delete;
522
523 /**
524 * \brief Gets the configurator for this CANcoder
525 *
526 * \details Gets the configurator for this CANcoder
527 *
528 * \returns Configurator for this CANcoder
529 */
531 {
532 return _configs;
533 }
534
535 /**
536 * \brief Gets the configurator for this CANcoder
537 *
538 * \details Gets the configurator for this CANcoder
539 *
540 * \returns Configurator for this CANcoder
541 */
543 {
544 return _configs;
545 }
546
547
548private:
549 std::unique_ptr<sim::CANcoderSimState> _simState{};
550public:
551 /**
552 * \brief Get the simulation state for this device.
553 *
554 * \details This function reuses an allocated simulation
555 * state object, so it is safe to call this function multiple
556 * times in a robot loop.
557 *
558 * \returns Simulation state
559 */
561 {
562 if (_simState == nullptr)
563 _simState = std::make_unique<sim::CANcoderSimState>(*this);
564 return *_simState;
565 }
566
567
568
569 /**
570 * \brief App Major Version number.
571 *
572 * Minimum Value: 0
573 * Maximum Value: 255
574 * Default Value: 0
575 * Units:
576 *
577 * Default Rates:
578 * CAN: 4.0 Hz
579 *
580 * \returns VersionMajor Status Signal Object
581 */
583
584 /**
585 * \brief App Minor Version number.
586 *
587 * Minimum Value: 0
588 * Maximum Value: 255
589 * Default Value: 0
590 * Units:
591 *
592 * Default Rates:
593 * CAN: 4.0 Hz
594 *
595 * \returns VersionMinor Status Signal Object
596 */
598
599 /**
600 * \brief App Bugfix Version number.
601 *
602 * Minimum Value: 0
603 * Maximum Value: 255
604 * Default Value: 0
605 * Units:
606 *
607 * Default Rates:
608 * CAN: 4.0 Hz
609 *
610 * \returns VersionBugfix Status Signal Object
611 */
613
614 /**
615 * \brief App Build Version number.
616 *
617 * Minimum Value: 0
618 * Maximum Value: 255
619 * Default Value: 0
620 * Units:
621 *
622 * Default Rates:
623 * CAN: 4.0 Hz
624 *
625 * \returns VersionBuild Status Signal Object
626 */
628
629 /**
630 * \brief Full Version. The format is a four byte value.
631 *
632 * \details Full Version of firmware in device. The format is a four
633 * byte value.
634 *
635 * Minimum Value: 0
636 * Maximum Value: 4294967295
637 * Default Value: 0
638 * Units:
639 *
640 * Default Rates:
641 * CAN: 4.0 Hz
642 *
643 * \returns Version Status Signal Object
644 */
646
647 /**
648 * \brief Integer representing all faults
649 *
650 * \details This returns the fault flags reported by the device. These
651 * are device specific and are not used directly in typical
652 * applications. Use the signal specific GetFault_*() methods instead.
653 *
654 *
655 * Minimum Value: 0
656 * Maximum Value: 16777215
657 * Default Value: 0
658 * Units:
659 *
660 * Default Rates:
661 * CAN: 4.0 Hz
662 *
663 * \returns FaultField Status Signal Object
664 */
666
667 /**
668 * \brief Integer representing all sticky faults
669 *
670 * \details This returns the persistent "sticky" fault flags reported
671 * by the device. These are device specific and are not used directly
672 * in typical applications. Use the signal specific GetStickyFault_*()
673 * methods instead.
674 *
675 * Minimum Value: 0
676 * Maximum Value: 16777215
677 * Default Value: 0
678 * Units:
679 *
680 * Default Rates:
681 * CAN: 4.0 Hz
682 *
683 * \returns StickyFaultField Status Signal Object
684 */
686
687 /**
688 * \brief Velocity of the device.
689 *
690 * Minimum Value: -512.0
691 * Maximum Value: 511.998046875
692 * Default Value: 0
693 * Units: rotations per second
694 *
695 * Default Rates:
696 * CAN 2.0: 100.0 Hz
697 * CAN FD: 100.0 Hz (TimeSynced with Pro)
698 *
699 * \returns Velocity Status Signal Object
700 */
702
703 /**
704 * \brief Position of the device. This is initialized to the absolute
705 * position on boot.
706 *
707 * Minimum Value: -16384.0
708 * Maximum Value: 16383.999755859375
709 * Default Value: 0
710 * Units: rotations
711 *
712 * Default Rates:
713 * CAN 2.0: 100.0 Hz
714 * CAN FD: 100.0 Hz (TimeSynced with Pro)
715 *
716 * \returns Position Status Signal Object
717 */
719
720 /**
721 * \brief Absolute Position of the device. The possible range is
722 * documented below; however, the exact expected range is determined
723 * by the AbsoluteSensorRange. This position is only affected by the
724 * MagnetSensor configs.
725 *
726 * Minimum Value: -0.5
727 * Maximum Value: 0.999755859375
728 * Default Value: 0
729 * Units: rotations
730 *
731 * Default Rates:
732 * CAN 2.0: 100.0 Hz
733 * CAN FD: 100.0 Hz (TimeSynced with Pro)
734 *
735 * \returns AbsolutePosition Status Signal Object
736 */
738
739 /**
740 * \brief The unfiltered velocity reported by CANcoder.
741 *
742 * \details This is the unfiltered velocity reported by CANcoder. This
743 * signal does not use the fusing algorithm.
744 *
745 * Minimum Value: -8000.0
746 * Maximum Value: 7999.755859375
747 * Default Value: 0
748 * Units: rotations per second
749 *
750 * Default Rates:
751 * CAN 2.0: 4.0 Hz
752 * CAN FD: 100.0 Hz (TimeSynced with Pro)
753 *
754 * \returns UnfilteredVelocity Status Signal Object
755 */
757
758 /**
759 * \brief The relative position reported by the CANcoder since boot.
760 *
761 * \details This is the total displacement reported by CANcoder since
762 * power up. This signal is relative and is not influenced by the
763 * fusing algorithm.
764 *
765 * Minimum Value: -16384.0
766 * Maximum Value: 16383.999755859375
767 * Default Value: 0
768 * Units: rotations
769 *
770 * Default Rates:
771 * CAN 2.0: 4.0 Hz
772 * CAN FD: 100.0 Hz (TimeSynced with Pro)
773 *
774 * \returns PositionSinceBoot Status Signal Object
775 */
777
778 /**
779 * \brief Measured supply voltage to the CANcoder.
780 *
781 * Minimum Value: 4
782 * Maximum Value: 16.75
783 * Default Value: 4
784 * Units: V
785 *
786 * Default Rates:
787 * CAN 2.0: 4.0 Hz
788 * CAN FD: 100.0 Hz (TimeSynced with Pro)
789 *
790 * \returns SupplyVoltage Status Signal Object
791 */
793
794 /**
795 * \brief Magnet health as measured by CANcoder.
796 *
797 * \details Magnet health as measured by CANcoder. Red indicates too
798 * close or too far, Orange is adequate but with reduced accuracy,
799 * green is ideal. Invalid means the accuracy cannot be determined.
800 *
801 *
802 * Default Rates:
803 * CAN 2.0: 4.0 Hz
804 * CAN FD: 100.0 Hz (TimeSynced with Pro)
805 *
806 * \returns MagnetHealth Status Signal Object
807 */
809
810 /**
811 * \brief Whether the device is Phoenix Pro licensed.
812 *
813 * Default Value: False
814 *
815 * Default Rates:
816 * CAN: 4.0 Hz
817 *
818 * \returns IsProLicensed Status Signal Object
819 */
821
822 /**
823 * \brief Hardware fault occurred
824 *
825 * Default Value: False
826 *
827 * Default Rates:
828 * CAN: 4.0 Hz
829 *
830 * \returns Fault_Hardware Status Signal Object
831 */
833
834 /**
835 * \brief Hardware fault occurred
836 *
837 * Default Value: False
838 *
839 * Default Rates:
840 * CAN: 4.0 Hz
841 *
842 * \returns StickyFault_Hardware Status Signal Object
843 */
845
846 /**
847 * \brief Device supply voltage dropped to near brownout levels
848 *
849 * Default Value: False
850 *
851 * Default Rates:
852 * CAN: 4.0 Hz
853 *
854 * \returns Fault_Undervoltage Status Signal Object
855 */
857
858 /**
859 * \brief Device supply voltage dropped to near brownout levels
860 *
861 * Default Value: False
862 *
863 * Default Rates:
864 * CAN: 4.0 Hz
865 *
866 * \returns StickyFault_Undervoltage Status Signal Object
867 */
869
870 /**
871 * \brief Device boot while detecting the enable signal
872 *
873 * Default Value: False
874 *
875 * Default Rates:
876 * CAN: 4.0 Hz
877 *
878 * \returns Fault_BootDuringEnable Status Signal Object
879 */
881
882 /**
883 * \brief Device boot while detecting the enable signal
884 *
885 * Default Value: False
886 *
887 * Default Rates:
888 * CAN: 4.0 Hz
889 *
890 * \returns StickyFault_BootDuringEnable Status Signal Object
891 */
893
894 /**
895 * \brief An unlicensed feature is in use, device may not behave as
896 * expected.
897 *
898 * Default Value: False
899 *
900 * Default Rates:
901 * CAN: 4.0 Hz
902 *
903 * \returns Fault_UnlicensedFeatureInUse Status Signal Object
904 */
906
907 /**
908 * \brief An unlicensed feature is in use, device may not behave as
909 * expected.
910 *
911 * Default Value: False
912 *
913 * Default Rates:
914 * CAN: 4.0 Hz
915 *
916 * \returns StickyFault_UnlicensedFeatureInUse Status Signal Object
917 */
919
920 /**
921 * \brief The magnet distance is not correct or magnet is missing
922 *
923 * Default Value: False
924 *
925 * Default Rates:
926 * CAN: 4.0 Hz
927 *
928 * \returns Fault_BadMagnet Status Signal Object
929 */
931
932 /**
933 * \brief The magnet distance is not correct or magnet is missing
934 *
935 * Default Value: False
936 *
937 * Default Rates:
938 * CAN: 4.0 Hz
939 *
940 * \returns StickyFault_BadMagnet Status Signal Object
941 */
943
944
945
946 /**
947 * \brief Control motor with generic control request object. User must make
948 * sure the specified object is castable to a valid control request,
949 * otherwise this function will fail at run-time and return the NotSupported
950 * StatusCode
951 *
952 * \param request Control object to request of the device
953 * \returns Status Code of the request, 0 is OK
954 */
955 ctre::phoenix::StatusCode SetControl(controls::ControlRequest& request)
956 {
957 controls::ControlRequest *ptr = &request;
958 (void)ptr;
959
961 }
962 /**
963 * \brief Control motor with generic control request object. User must make
964 * sure the specified object is castable to a valid control request,
965 * otherwise this function will fail at run-time and return the corresponding
966 * StatusCode
967 *
968 * \param request Control object to request of the device
969 * \returns Status Code of the request, 0 is OK
970 */
971 ctre::phoenix::StatusCode SetControl(controls::ControlRequest&& request)
972 {
973 return SetControl(request);
974 }
975
976
977 /**
978 * \brief Sets the current position of the device.
979 *
980 * \param newValue Value to set to. Units are in rotations.
981 * \param timeoutSeconds Maximum time to wait up to in seconds.
982 * \returns StatusCode of the set command
983 */
984 ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue, units::time::second_t timeoutSeconds)
985 {
986 return GetConfigurator().SetPosition(newValue, timeoutSeconds);
987 }
988 /**
989 * \brief Sets the current position of the device.
990 *
991 * This will wait up to 0.050 seconds (50ms) by default.
992 *
993 * \param newValue Value to set to. Units are in rotations.
994 * \returns StatusCode of the set command
995 */
996 ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue)
997 {
998 return SetPosition(newValue, 0.050_s);
999 }
1000
1001 /**
1002 * \brief Clear the sticky faults in the device.
1003 *
1004 * \details This typically has no impact on the device functionality.
1005 * Instead, it just clears telemetry faults that are accessible via
1006 * API and Tuner Self-Test.
1007 *
1008 * \param timeoutSeconds Maximum time to wait up to in seconds.
1009 * \returns StatusCode of the set command
1010 */
1011 ctre::phoenix::StatusCode ClearStickyFaults(units::time::second_t timeoutSeconds)
1012 {
1013 return GetConfigurator().ClearStickyFaults(timeoutSeconds);
1014 }
1015 /**
1016 * \brief Clear the sticky faults in the device.
1017 *
1018 * \details This typically has no impact on the device functionality.
1019 * Instead, it just clears telemetry faults that are accessible via
1020 * API and Tuner Self-Test.
1021 *
1022 * This will wait up to 0.050 seconds (50ms) by default.
1023 *
1024 * \returns StatusCode of the set command
1025 */
1026 ctre::phoenix::StatusCode ClearStickyFaults()
1027 {
1028 return ClearStickyFaults(0.050_s);
1029 }
1030
1031 /**
1032 * \brief Clear sticky fault: Hardware fault occurred
1033 *
1034 * \param timeoutSeconds Maximum time to wait up to in seconds.
1035 * \returns StatusCode of the set command
1036 */
1037 ctre::phoenix::StatusCode ClearStickyFault_Hardware(units::time::second_t timeoutSeconds)
1038 {
1039 return GetConfigurator().ClearStickyFault_Hardware(timeoutSeconds);
1040 }
1041 /**
1042 * \brief Clear sticky fault: Hardware fault occurred
1043 *
1044 * This will wait up to 0.050 seconds (50ms) by default.
1045 *
1046 * \returns StatusCode of the set command
1047 */
1048 ctre::phoenix::StatusCode ClearStickyFault_Hardware()
1049 {
1050 return ClearStickyFault_Hardware(0.050_s);
1051 }
1052
1053 /**
1054 * \brief Clear sticky fault: Device supply voltage dropped to near
1055 * brownout levels
1056 *
1057 * \param timeoutSeconds Maximum time to wait up to in seconds.
1058 * \returns StatusCode of the set command
1059 */
1060 ctre::phoenix::StatusCode ClearStickyFault_Undervoltage(units::time::second_t timeoutSeconds)
1061 {
1062 return GetConfigurator().ClearStickyFault_Undervoltage(timeoutSeconds);
1063 }
1064 /**
1065 * \brief Clear sticky fault: Device supply voltage dropped to near
1066 * brownout levels
1067 *
1068 * This will wait up to 0.050 seconds (50ms) by default.
1069 *
1070 * \returns StatusCode of the set command
1071 */
1072 ctre::phoenix::StatusCode ClearStickyFault_Undervoltage()
1073 {
1074 return ClearStickyFault_Undervoltage(0.050_s);
1075 }
1076
1077 /**
1078 * \brief Clear sticky fault: Device boot while detecting the enable
1079 * signal
1080 *
1081 * \param timeoutSeconds Maximum time to wait up to in seconds.
1082 * \returns StatusCode of the set command
1083 */
1084 ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable(units::time::second_t timeoutSeconds)
1085 {
1086 return GetConfigurator().ClearStickyFault_BootDuringEnable(timeoutSeconds);
1087 }
1088 /**
1089 * \brief Clear sticky fault: Device boot while detecting the enable
1090 * signal
1091 *
1092 * This will wait up to 0.050 seconds (50ms) by default.
1093 *
1094 * \returns StatusCode of the set command
1095 */
1096 ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable()
1097 {
1098 return ClearStickyFault_BootDuringEnable(0.050_s);
1099 }
1100
1101 /**
1102 * \brief Clear sticky fault: The magnet distance is not correct or
1103 * magnet is missing
1104 *
1105 * \param timeoutSeconds Maximum time to wait up to in seconds.
1106 * \returns StatusCode of the set command
1107 */
1108 ctre::phoenix::StatusCode ClearStickyFault_BadMagnet(units::time::second_t timeoutSeconds)
1109 {
1110 return GetConfigurator().ClearStickyFault_BadMagnet(timeoutSeconds);
1111 }
1112 /**
1113 * \brief Clear sticky fault: The magnet distance is not correct or
1114 * magnet is missing
1115 *
1116 * This will wait up to 0.050 seconds (50ms) by default.
1117 *
1118 * \returns StatusCode of the set command
1119 */
1120 ctre::phoenix::StatusCode ClearStickyFault_BadMagnet()
1121 {
1122 return ClearStickyFault_BadMagnet(0.050_s);
1123 }
1124};
1125
1126}
1127}
1128
1129}
1130}
1131
ii that the Software will be uninterrupted or error free
Definition: CTRE_LICENSE.txt:226
CTREXPORT int c_ctre_phoenix6_serialize_double(int spn, double value, char **str)
@ OK
No Error.
Definition: StatusCodes.h:1192
@ NotSupported
This is not supported.
Definition: StatusCodes.h:1805
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CoreCANcoder.hpp:37
MagnetSensorConfigs MagnetSensor
Configs that affect the magnet sensor and how to interpret it.
Definition: CoreCANcoder.hpp:61
ctre::phoenix::StatusCode Deserialize(const std::string &to_deserialize)
Take a string and deserialize it to this configuration.
Definition: CoreCANcoder.hpp:98
bool FutureProofConfigs
True if we should factory default newer unsupported configs, false to leave newer unsupported configs...
Definition: CoreCANcoder.hpp:52
CANcoderConfiguration & WithMagnetSensor(MagnetSensorConfigs newMagnetSensor)
Modifies this configuration's MagnetSensor parameter and returns itself for method-chaining and easie...
Definition: CoreCANcoder.hpp:69
std::string ToString() const
Get the string representation of this configuration.
Definition: CoreCANcoder.hpp:78
std::string Serialize() const
Get the serialized form of this configuration.
Definition: CoreCANcoder.hpp:88
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CoreCANcoder.hpp:113
ctre::phoenix::StatusCode Refresh(MagnetSensorConfigs &configs) const
Refreshes the values of the specified config group.
Definition: CoreCANcoder.hpp:198
ctre::phoenix::StatusCode ClearStickyFault_BadMagnet()
Clear sticky fault: The magnet distance is not correct or magnet is missing.
Definition: CoreCANcoder.hpp:462
ctre::phoenix::StatusCode ClearStickyFault_BadMagnet(units::time::second_t timeoutSeconds)
Clear sticky fault: The magnet distance is not correct or magnet is missing.
Definition: CoreCANcoder.hpp:479
ctre::phoenix::StatusCode ClearStickyFault_Undervoltage()
Clear sticky fault: Device supply voltage dropped to near brownout levels.
Definition: CoreCANcoder.hpp:384
ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable()
Clear sticky fault: Device boot while detecting the enable signal.
Definition: CoreCANcoder.hpp:423
ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable(units::time::second_t timeoutSeconds)
Clear sticky fault: Device boot while detecting the enable signal.
Definition: CoreCANcoder.hpp:440
ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue)
Sets the current position of the device.
Definition: CoreCANcoder.hpp:263
ctre::phoenix::StatusCode ClearStickyFaults()
Clear the sticky faults in the device.
Definition: CoreCANcoder.hpp:305
ctre::phoenix::StatusCode Apply(const CANcoderConfiguration &configs)
Applies the contents of the specified config to the device.
Definition: CoreCANcoder.hpp:168
ctre::phoenix::StatusCode Apply(const CANcoderConfiguration &configs, units::time::second_t timeoutSeconds)
Applies the contents of the specified config to the device.
Definition: CoreCANcoder.hpp:182
ctre::phoenix::StatusCode Refresh(CANcoderConfiguration &configs, units::time::second_t timeoutSeconds) const
Refreshes the values of the specified config group.
Definition: CoreCANcoder.hpp:150
ctre::phoenix::StatusCode ClearStickyFault_Undervoltage(units::time::second_t timeoutSeconds)
Clear sticky fault: Device supply voltage dropped to near brownout levels.
Definition: CoreCANcoder.hpp:401
ctre::phoenix::StatusCode Apply(const MagnetSensorConfigs &configs, units::time::second_t timeoutSeconds)
Applies the contents of the specified config to the device.
Definition: CoreCANcoder.hpp:243
ctre::phoenix::StatusCode ClearStickyFault_Hardware()
Clear sticky fault: Hardware fault occurred.
Definition: CoreCANcoder.hpp:346
ctre::phoenix::StatusCode Refresh(CANcoderConfiguration &configs) const
Refreshes the values of the specified config group.
Definition: CoreCANcoder.hpp:136
ctre::phoenix::StatusCode ClearStickyFault_Hardware(units::time::second_t timeoutSeconds)
Clear sticky fault: Hardware fault occurred.
Definition: CoreCANcoder.hpp:362
ctre::phoenix::StatusCode ClearStickyFaults(units::time::second_t timeoutSeconds)
Clear the sticky faults in the device.
Definition: CoreCANcoder.hpp:325
ctre::phoenix::StatusCode Refresh(MagnetSensorConfigs &configs, units::time::second_t timeoutSeconds) const
Refreshes the values of the specified config group.
Definition: CoreCANcoder.hpp:211
ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue, units::time::second_t timeoutSeconds)
Sets the current position of the device.
Definition: CoreCANcoder.hpp:280
CANcoderConfigurator(const CANcoderConfigurator &)=delete
Delete the copy constructor, we can only pass by reference.
ctre::phoenix::StatusCode Apply(const MagnetSensorConfigs &configs)
Applies the contents of the specified config to the device.
Definition: CoreCANcoder.hpp:229
Configs that affect the magnet sensor and how to interpret it.
Definition: Configs.hpp:46
std::string Serialize() const override
Definition: Configs.hpp:121
ctre::phoenix::StatusCode Deserialize(const std::string &to_deserialize) override
Definition: Configs.hpp:131
std::string ToString() const override
Definition: Configs.hpp:109
Definition: Configurator.hpp:21
ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
Definition: Configurator.hpp:37
ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
Definition: Configurator.hpp:60
units::time::second_t DefaultTimeoutSeconds
The default amount of time to wait for a config.
Definition: Configurator.hpp:26
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
Definition: DeviceIdentifier.hpp:19
Parent class for all devices.
Definition: ParentDevice.hpp:29
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CoreCANcoder.hpp:498
StatusSignal< bool > & GetFault_UnlicensedFeatureInUse()
An unlicensed feature is in use, device may not behave as expected.
ctre::phoenix::StatusCode ClearStickyFaults(units::time::second_t timeoutSeconds)
Clear the sticky faults in the device.
Definition: CoreCANcoder.hpp:1011
ctre::phoenix::StatusCode ClearStickyFault_Undervoltage()
Clear sticky fault: Device supply voltage dropped to near brownout levels.
Definition: CoreCANcoder.hpp:1072
StatusSignal< int > & GetVersionBugfix()
App Bugfix Version number.
StatusSignal< bool > & GetStickyFault_Hardware()
Hardware fault occurred.
StatusSignal< units::angular_velocity::turns_per_second_t > & GetUnfilteredVelocity()
The unfiltered velocity reported by CANcoder.
ctre::phoenix::StatusCode ClearStickyFaults()
Clear the sticky faults in the device.
Definition: CoreCANcoder.hpp:1026
configs::CANcoderConfigurator & GetConfigurator()
Gets the configurator for this CANcoder.
Definition: CoreCANcoder.hpp:530
CoreCANcoder(int deviceId, std::string canbus="")
Constructs a new CANcoder object.
StatusSignal< int > & GetStickyFaultField()
Integer representing all sticky faults.
StatusSignal< bool > & GetFault_BadMagnet()
The magnet distance is not correct or magnet is missing.
StatusSignal< units::angle::turn_t > & GetPosition()
Position of the device.
ctre::phoenix::StatusCode ClearStickyFault_Hardware(units::time::second_t timeoutSeconds)
Clear sticky fault: Hardware fault occurred.
Definition: CoreCANcoder.hpp:1037
StatusSignal< int > & GetVersionBuild()
App Build Version number.
StatusSignal< bool > & GetFault_Undervoltage()
Device supply voltage dropped to near brownout levels.
StatusSignal< int > & GetVersionMinor()
App Minor Version number.
ctre::phoenix::StatusCode ClearStickyFault_Undervoltage(units::time::second_t timeoutSeconds)
Clear sticky fault: Device supply voltage dropped to near brownout levels.
Definition: CoreCANcoder.hpp:1060
CoreCANcoder & operator=(CoreCANcoder const &)=delete
ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue)
Sets the current position of the device.
Definition: CoreCANcoder.hpp:996
StatusSignal< units::angular_velocity::turns_per_second_t > & GetVelocity()
Velocity of the device.
sim::CANcoderSimState & GetSimState()
Get the simulation state for this device.
Definition: CoreCANcoder.hpp:560
ctre::phoenix::StatusCode ClearStickyFault_BadMagnet()
Clear sticky fault: The magnet distance is not correct or magnet is missing.
Definition: CoreCANcoder.hpp:1120
ctre::phoenix::StatusCode SetControl(controls::ControlRequest &request)
Control motor with generic control request object.
Definition: CoreCANcoder.hpp:955
CoreCANcoder(CoreCANcoder const &)=delete
ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable(units::time::second_t timeoutSeconds)
Clear sticky fault: Device boot while detecting the enable signal.
Definition: CoreCANcoder.hpp:1084
StatusSignal< bool > & GetIsProLicensed()
Whether the device is Phoenix Pro licensed.
StatusSignal< signals::MagnetHealthValue > & GetMagnetHealth()
Magnet health as measured by CANcoder.
StatusSignal< bool > & GetStickyFault_BadMagnet()
The magnet distance is not correct or magnet is missing.
StatusSignal< int > & GetVersion()
Full Version.
StatusSignal< units::voltage::volt_t > & GetSupplyVoltage()
Measured supply voltage to the CANcoder.
StatusSignal< units::angle::turn_t > & GetPositionSinceBoot()
The relative position reported by the CANcoder since boot.
StatusSignal< int > & GetFaultField()
Integer representing all faults.
StatusSignal< bool > & GetStickyFault_BootDuringEnable()
Device boot while detecting the enable signal.
ctre::phoenix::StatusCode ClearStickyFault_BadMagnet(units::time::second_t timeoutSeconds)
Clear sticky fault: The magnet distance is not correct or magnet is missing.
Definition: CoreCANcoder.hpp:1108
StatusSignal< bool > & GetFault_BootDuringEnable()
Device boot while detecting the enable signal.
ctre::phoenix::StatusCode SetControl(controls::ControlRequest &&request)
Control motor with generic control request object.
Definition: CoreCANcoder.hpp:971
ctre::phoenix::StatusCode SetPosition(units::angle::turn_t newValue, units::time::second_t timeoutSeconds)
Sets the current position of the device.
Definition: CoreCANcoder.hpp:984
StatusSignal< bool > & GetStickyFault_UnlicensedFeatureInUse()
An unlicensed feature is in use, device may not behave as expected.
ctre::phoenix::StatusCode ClearStickyFault_Hardware()
Clear sticky fault: Hardware fault occurred.
Definition: CoreCANcoder.hpp:1048
StatusSignal< units::angle::turn_t > & GetAbsolutePosition()
Absolute Position of the device.
StatusSignal< int > & GetVersionMajor()
App Major Version number.
StatusSignal< bool > & GetFault_Hardware()
Hardware fault occurred.
configs::CANcoderConfigurator const & GetConfigurator() const
Gets the configurator for this CANcoder.
Definition: CoreCANcoder.hpp:542
ctre::phoenix::StatusCode ClearStickyFault_BootDuringEnable()
Clear sticky fault: Device boot while detecting the enable signal.
Definition: CoreCANcoder.hpp:1096
StatusSignal< bool > & GetStickyFault_Undervoltage()
Device supply voltage dropped to near brownout levels.
Class to control the state of a simulated hardware::CANcoder.
Definition: CANcoderSimState.hpp:32
Definition: RcManualEvent.hpp:12