CTRE Phoenix 6 C++ 26.0.0-beta-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
10#include <units/frequency.h>
11#include <units/time.h>
12
13namespace ctre {
14namespace phoenix6 {
15namespace controls {
16
17/**
18 * Applies full neutral-brake by shorting motor leads together.
19 */
20class StaticBrake final : public ControlRequest {
21 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
22
23public:
24 /**
25 * \brief Set to true to delay applying this control request until a timesync
26 * boundary (requires Phoenix Pro and CANivore). This eliminates the impact of
27 * nondeterministic network delays in exchange for a larger but deterministic
28 * control latency.
29 *
30 * This requires setting the ControlTimesyncFreqHz config in MotorOutputConfigs.
31 * Additionally, when this is enabled, the UpdateFreqHz of this request should
32 * be set to 0 Hz.
33 */
34 bool UseTimesync = false;
35
36 /**
37 * \brief The frequency at which this control will update.
38 * This is designated in Hertz, with a minimum of 20 Hz
39 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
40 * Some update frequencies are not supported and will be
41 * promoted up to the next highest supported frequency.
42 *
43 * If this field is set to 0 Hz, the control request will
44 * be sent immediately as a one-shot frame. This may be useful
45 * for advanced applications that require outputs to be
46 * synchronized with data acquisition. In this case, we
47 * recommend not exceeding 50 ms between control calls.
48 */
49 units::frequency::hertz_t UpdateFreqHz{20_Hz};
50
51 /**
52 * \brief Applies full neutral-brake by shorting motor leads together.
53 *
54 */
56 {}
57
58 constexpr ~StaticBrake() override {}
59
60 /**
61 * \brief Gets the name of this control request.
62 *
63 * \returns Name of the control request
64 */
65 constexpr std::string_view GetName() const override
66 {
67 return "StaticBrake";
68 }
69
70 /**
71 * \brief Modifies this Control Request's UseTimesync parameter and returns itself for
72 * method-chaining and easier to use request API.
73 *
74 * Set to true to delay applying this control request until a timesync boundary
75 * (requires Phoenix Pro and CANivore). This eliminates the impact of
76 * nondeterministic network delays in exchange for a larger but deterministic
77 * control latency.
78 *
79 * This requires setting the ControlTimesyncFreqHz config in MotorOutputConfigs.
80 * Additionally, when this is enabled, the UpdateFreqHz of this request should
81 * be set to 0 Hz.
82 *
83 * \param newUseTimesync Parameter to modify
84 * \returns Itself
85 */
86 constexpr StaticBrake &WithUseTimesync(bool newUseTimesync)
87 {
88 UseTimesync = std::move(newUseTimesync);
89 return *this;
90 }
91
92 /**
93 * \brief Sets the frequency at which this control will update.
94 * This is designated in Hertz, with a minimum of 20 Hz
95 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
96 * Some update frequencies are not supported and will be
97 * promoted up to the next highest supported frequency.
98 *
99 * If this field is set to 0 Hz, the control request will
100 * be sent immediately as a one-shot frame. This may be useful
101 * for advanced applications that require outputs to be
102 * synchronized with data acquisition. In this case, we
103 * recommend not exceeding 50 ms between control calls.
104 *
105 * \param newUpdateFreqHz Parameter to modify
106 * \returns Itself
107 */
108 constexpr StaticBrake &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
109 {
110 UpdateFreqHz = newUpdateFreqHz;
111 return *this;
112 }
113
114 /**
115 * \brief Returns a string representation of the object.
116 *
117 * \returns a string representation of the object.
118 */
119 std::string ToString() const override;
120
121 /**
122 * \brief Gets information about this control request.
123 *
124 * \returns Map of control parameter names and corresponding applied values
125 */
126 std::map<std::string, std::string> GetControlInfo() const override;
127};
128
129}
130}
131}
132
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Applies full neutral-brake by shorting motor leads together.
Definition StaticBrake.hpp:20
constexpr StaticBrake & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition StaticBrake.hpp:108
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
std::string ToString() const override
Returns a string representation of the object.
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition StaticBrake.hpp:34
constexpr StaticBrake & WithUseTimesync(bool newUseTimesync)
Modifies this Control Request's UseTimesync parameter and returns itself for method-chaining and easi...
Definition StaticBrake.hpp:86
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition StaticBrake.hpp:65
constexpr StaticBrake()
Applies full neutral-brake by shorting motor leads together.
Definition StaticBrake.hpp:55
constexpr ~StaticBrake() override
Definition StaticBrake.hpp:58
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition StaticBrake.hpp:49
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14