CTRE Phoenix 6 C++ 25.0.0-beta-4
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
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 * Applies full neutral-brake by shorting motor leads together.
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<StaticBrake *>(req.get());
32 if (reqCast != nullptr)
33 {
34 *reqCast = *this;
35 }
36 else
37 {
38 req = std::make_shared<StaticBrake>(*this);
39 }
40 }
41
42 return c_ctre_phoenix6_RequestControlStaticBrake(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 Applies full neutral-brake by shorting motor leads together.
73 *
74 */
75 StaticBrake() : ControlRequest{"StaticBrake"}
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 StaticBrake &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 StaticBrake &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: StaticBrake" << 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_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:29
std::string const & GetName() const
Definition ControlRequest.hpp:52
Applies full neutral-brake by shorting motor leads together.
Definition StaticBrake.hpp:26
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition StaticBrake.hpp:136
std::string ToString() const override
Returns a string representation of the object.
Definition StaticBrake.hpp:123
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition StaticBrake.hpp:56
StaticBrake()
Applies full neutral-brake by shorting motor leads together.
Definition StaticBrake.hpp:75
StaticBrake & WithUseTimesync(bool newUseTimesync)
Modifies this Control Request's UseTimesync parameter and returns itself for method-chaining and easi...
Definition StaticBrake.hpp:94
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition StaticBrake.hpp:69
StaticBrake & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition StaticBrake.hpp:113
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition StatusCodes.h:18