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