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