Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EmptyAnimation.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
11#include <sstream>
12
13#include <units/frequency.h>
14#include <units/time.h>
15
16namespace ctre {
17namespace phoenix6 {
18namespace controls {
19
20/**
21 * An empty animation, clearing any animation in the specified slot.
22 *
23 *
24 */
26{
27 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
28 {
29 if (req.get() != this)
30 {
31 auto const reqCast = dynamic_cast<EmptyAnimation *>(req.get());
32 if (reqCast != nullptr)
33 {
34 *reqCast = *this;
35 }
36 else
37 {
38 req = std::make_shared<EmptyAnimation>(*this);
39 }
40 }
41
42 return c_ctre_phoenix6_RequestControlEmptyAnimation(network, deviceHash, UpdateFreqHz.to<double>(), Slot);
43 }
44
45public:
46 /**
47 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
48 * store and run one animation.
49 */
50 int Slot;
51
52 /**
53 * \brief The period at which this control will update at.
54 * This is designated in Hertz, with a minimum of 20 Hz
55 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
56 *
57 * If this field is set to 0 Hz, the control request will
58 * be sent immediately as a one-shot frame. This may be useful
59 * for advanced applications that require outputs to be
60 * synchronized with data acquisition. In this case, we
61 * recommend not exceeding 50 ms between control calls.
62 */
63 units::frequency::hertz_t UpdateFreqHz{0_Hz};
64
65 /**
66 * \brief An empty animation, clearing any animation in the specified slot.
67 *
68 * \details
69 *
70 * \param Slot The slot of this animation, within [0, 7]. Each slot on the
71 * CANdle can store and run one animation.
72 */
73 EmptyAnimation(int Slot) : ControlRequest{"EmptyAnimation"},
74 Slot{std::move(Slot)}
75 {}
76
77 /**
78 * \brief Modifies this Control Request's Slot parameter and returns itself for
79 * method-chaining and easier to use request API.
80 *
81 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
82 * and run one animation.
83 *
84 * \param newSlot Parameter to modify
85 * \returns Itself
86 */
88 {
89 Slot = std::move(newSlot);
90 return *this;
91 }
92 /**
93 * \brief Sets the period at which this control will update at.
94 * This is designated in Hertz, with a minimum of 20 Hz
95 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
96 *
97 * If this field is set to 0 Hz, the control request will
98 * be sent immediately as a one-shot frame. This may be useful
99 * for advanced applications that require outputs to be
100 * synchronized with data acquisition. In this case, we
101 * recommend not exceeding 50 ms between control calls.
102 *
103 * \param newUpdateFreqHz Parameter to modify
104 * \returns Itself
105 */
106 EmptyAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
107 {
108 UpdateFreqHz = newUpdateFreqHz;
109 return *this;
110 }
111 /**
112 * \brief Returns a string representation of the object.
113 *
114 * \returns a string representation of the object.
115 */
116 std::string ToString() const override
117 {
118 std::stringstream ss;
119 ss << "Control: EmptyAnimation" << std::endl;
120 ss << " Slot: " << Slot << std::endl;
121 return ss.str();
122 }
123
124 /**
125 * \brief Gets information about this control request.
126 *
127 * \returns Map of control parameter names and corresponding applied values
128 */
129 std::map<std::string, std::string> GetControlInfo() const override
130 {
131 std::map<std::string, std::string> controlInfo;
132 std::stringstream ss;
133 controlInfo["Name"] = GetName();
134 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
135 return controlInfo;
136 }
137};
138
139}
140}
141}
142
CTREXPORT int c_ctre_phoenix6_RequestControlEmptyAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int Slot)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
An empty animation, clearing any animation in the specified slot.
Definition EmptyAnimation.hpp:26
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition EmptyAnimation.hpp:63
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition EmptyAnimation.hpp:129
std::string ToString() const override
Returns a string representation of the object.
Definition EmptyAnimation.hpp:116
EmptyAnimation(int Slot)
An empty animation, clearing any animation in the specified slot.
Definition EmptyAnimation.hpp:73
int Slot
The slot of this animation, within [0, 7].
Definition EmptyAnimation.hpp:50
EmptyAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition EmptyAnimation.hpp:87
EmptyAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition EmptyAnimation.hpp:106
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401