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