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