CTRE Phoenix 6 C++ 24.50.0-alpha-2
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) 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 * Set to true to delay applying this control request until a timesync boundary
48 * (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 */
53
54 /**
55 * \brief The period at which this control will update at.
56 * This is designated in Hertz, with a minimum of 20 Hz
57 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
58 *
59 * If this field is set to 0 Hz, the control request will
60 * be sent immediately as a one-shot frame. This may be useful
61 * for advanced applications that require outputs to be
62 * synchronized with data acquisition. In this case, we
63 * recommend not exceeding 50 ms between control calls.
64 */
65 units::frequency::hertz_t UpdateFreqHz{20_Hz}; // Default to 20_Hz
66
67 /**
68 * \brief Applies full neutral-brake by shorting motor leads together.
69 *
70 * \param UseTimesync Set to true to delay applying this control request
71 * until a timesync boundary (requires Phoenix Pro and
72 * CANivore). This eliminates the impact of
73 * nondeterministic network delays in exchange for a
74 * larger but deterministic control latency.
75 */
76 StaticBrake(bool UseTimesync = false) : ControlRequest{"StaticBrake"},
78 {}
79
80 /**
81 * \brief Modifies this Control Request's UseTimesync parameter and returns itself for
82 * method-chaining and easier to use request API.
83 *
84 * Set to true to delay applying this control request until a timesync boundary
85 * (requires Phoenix Pro and CANivore). This eliminates the impact of
86 * nondeterministic network delays in exchange for a larger but deterministic
87 * control latency.
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 * 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 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: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:52
StaticBrake & WithUseTimesync(bool newUseTimesync)
Modifies this Control Request's UseTimesync parameter and returns itself for method-chaining and easi...
Definition: StaticBrake.hpp:92
StaticBrake(bool UseTimesync=false)
Applies full neutral-brake by shorting motor leads together.
Definition: StaticBrake.hpp:76
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: StaticBrake.hpp:65
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
Represents the state of one swerve module.
Definition: StatusCodes.h:18
Definition: span.hpp:401