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