Loading [MathJax]/jax/output/HTML-CSS/config.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CoastOut.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 * Request coast neutral output of actuator. The bridge is disabled and the
22 * rotor is allowed to coast.
23 */
25{
26 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
27 {
28 if (req.get() != this)
29 {
30 auto const reqCast = dynamic_cast<CoastOut *>(req.get());
31 if (reqCast != nullptr)
32 {
33 *reqCast = *this;
34 }
35 else
36 {
37 req = std::make_shared<CoastOut>(*this);
38 }
39 }
40
41 return c_ctre_phoenix6_RequestControlCoastOut(network, deviceHash, UpdateFreqHz.to<double>(), UseTimesync);
42 }
43
44public:
45 /**
46 * \brief Set to true to delay applying this control request until a timesync
47 * boundary (requires Phoenix Pro and CANivore). This eliminates the impact of
48 * nondeterministic network delays in exchange for a larger but deterministic
49 * control latency.
50 *
51 * This requires setting the ControlTimesyncFreqHz config in MotorOutputConfigs.
52 * Additionally, when this is enabled, the UpdateFreqHz of this request should
53 * be set to 0 Hz.
54 */
55 bool UseTimesync = false;
56
57 /**
58 * \brief The period at which this control will update at.
59 * This is designated in Hertz, with a minimum of 20 Hz
60 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
61 *
62 * If this field is set to 0 Hz, the control request will
63 * be sent immediately as a one-shot frame. This may be useful
64 * for advanced applications that require outputs to be
65 * synchronized with data acquisition. In this case, we
66 * recommend not exceeding 50 ms between control calls.
67 */
68 units::frequency::hertz_t UpdateFreqHz{20_Hz};
69
70 /**
71 * \brief Request coast neutral output of actuator. The bridge is disabled and
72 * the rotor is allowed to coast.
73 *
74 */
75 CoastOut() : ControlRequest{"CoastOut"}
76 {}
77
78 /**
79 * \brief Modifies this Control Request's UseTimesync parameter and returns itself for
80 * method-chaining and easier to use request API.
81 *
82 * Set to true to delay applying this control request until a timesync boundary
83 * (requires Phoenix Pro and CANivore). This eliminates the impact of
84 * nondeterministic network delays in exchange for a larger but deterministic
85 * control latency.
86 *
87 * This requires setting the ControlTimesyncFreqHz config in MotorOutputConfigs.
88 * Additionally, when this is enabled, the UpdateFreqHz of this request should
89 * be set to 0 Hz.
90 *
91 * \param newUseTimesync Parameter to modify
92 * \returns Itself
93 */
94 CoastOut &WithUseTimesync(bool newUseTimesync)
95 {
96 UseTimesync = std::move(newUseTimesync);
97 return *this;
98 }
99 /**
100 * \brief Sets the period at which this control will update at.
101 * This is designated in Hertz, with a minimum of 20 Hz
102 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
103 *
104 * If this field is set to 0 Hz, the control request will
105 * be sent immediately as a one-shot frame. This may be useful
106 * for advanced applications that require outputs to be
107 * synchronized with data acquisition. In this case, we
108 * recommend not exceeding 50 ms between control calls.
109 *
110 * \param newUpdateFreqHz Parameter to modify
111 * \returns Itself
112 */
113 CoastOut &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
114 {
115 UpdateFreqHz = newUpdateFreqHz;
116 return *this;
117 }
118 /**
119 * \brief Returns a string representation of the object.
120 *
121 * \returns a string representation of the object.
122 */
123 std::string ToString() const override
124 {
125 std::stringstream ss;
126 ss << "Control: CoastOut" << std::endl;
127 ss << " UseTimesync: " << UseTimesync << std::endl;
128 return ss.str();
129 }
130
131 /**
132 * \brief Gets information about this control request.
133 *
134 * \returns Map of control parameter names and corresponding applied values
135 */
136 std::map<std::string, std::string> GetControlInfo() const override
137 {
138 std::map<std::string, std::string> controlInfo;
139 std::stringstream ss;
140 controlInfo["Name"] = GetName();
141 ss << UseTimesync; controlInfo["UseTimesync"] = ss.str(); ss.str(std::string{});
142 return controlInfo;
143 }
144};
145
146}
147}
148}
149
CTREXPORT int c_ctre_phoenix6_RequestControlCoastOut(const char *canbus, uint32_t ecuEncoding, double updateFrequency, bool UseTimesync)
Request coast neutral output of actuator.
Definition CoastOut.hpp:25
std::string ToString() const override
Returns a string representation of the object.
Definition CoastOut.hpp:123
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition CoastOut.hpp:136
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition CoastOut.hpp:68
CoastOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition CoastOut.hpp:113
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition CoastOut.hpp:55
CoastOut()
Request coast neutral output of actuator.
Definition CoastOut.hpp:75
CoastOut & WithUseTimesync(bool newUseTimesync)
Modifies this Control Request's UseTimesync parameter and returns itself for method-chaining and easi...
Definition CoastOut.hpp:94
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15