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