Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 23.10.0-alpha-8
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 bool ApplyConfigsOnRequest{false};
28
29 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
30 {
31 if (req.get() != this)
32 {
33 auto const reqCast = dynamic_cast<StaticBrake *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<StaticBrake>(*this);
41 }
42 }
43
44 std::stringstream ss;
45
46 std::string strs{ss.str()};
47 c_ctre_phoenix6_requestConfigApply(network, deviceHash, ConfigTimeout.to<double>(), strs.c_str(), strs.length(), ApplyConfigsOnRequest);
48 ApplyConfigsOnRequest = false;
49 return c_ctre_phoenix6_RequestControlStaticBrake(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests);
50 }
51
52public:
53
54
55
56
57 /**
58 * \brief The timeout when sending configs associated with this control
59 */
60 units::time::second_t ConfigTimeout{0.1_s};
61
62 /**
63 * \brief The period at which this control will update at.
64 * This is designated in Hertz, with a minimum of 20 Hz
65 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
66 *
67 * If this field is set to 0 Hz, the control request will
68 * be sent immediately as a one-shot frame. This may be useful
69 * for advanced applications that require outputs to be
70 * synchronized with data acquisition. In this case, we
71 * recommend not exceeding 50 ms between control calls.
72 */
73 units::frequency::hertz_t UpdateFreqHz{20_Hz}; // Default to 20_Hz
74
75 /**
76 * \brief Applies full neutral-brake by shorting motor leads together.
77 *
78 */
79 StaticBrake() : ControlRequest{"StaticBrake"}
80 {}
81
82 /**
83 * \brief Sets the period at which this control will update at.
84 * This is designated in Hertz, with a minimum of 20 Hz
85 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
86 *
87 * If this field is set to 0 Hz, the control request will
88 * be sent immediately as a one-shot frame. This may be useful
89 * for advanced applications that require outputs to be
90 * synchronized with data acquisition. In this case, we
91 * recommend not exceeding 50 ms between control calls.
92 *
93 * \param newUpdateFreqHz Parameter to modify
94 * \returns Itself
95 */
96 StaticBrake &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
97 {
98 UpdateFreqHz = newUpdateFreqHz;
99 return *this;
100 }
101 /**
102 * Returns a string representation of the object.
103 *
104 * \returns a string representation of the object.
105 */
106 std::string ToString() const override
107 {
108 std::stringstream ss;
109 ss << "class: StaticBrake" << std::endl;
110
111 return ss.str();
112 }
113
114 /**
115 * \brief Forces configs to be applied the next time this is used in a setControl.
116 * This is not necessary in the majority of cases, because Phoenix will make sure configs are
117 * properly set when they are not already set
118 */
119 void ForceApplyConfigs() { ApplyConfigsOnRequest = true; }
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 std::map<std::string, std::string> controlInfo;
129 std::stringstream ss;
130 controlInfo["Name"] = GetName();
131
132 return controlInfo;
133 }
134};
135
136}
137}
138}
139
CTREXPORT int c_ctre_phoenix6_requestConfigApply(const char *canbus, uint32_t ecuEncoding, double timeoutSeconds, const char *str, uint32_t strlen, bool forceApply)
CTREXPORT int c_ctre_phoenix6_RequestControlStaticBrake(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests)
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
std::string const & GetName() const
Definition: ControlRequest.hpp:51
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:126
std::string ToString() const override
Returns a string representation of the object.
Definition: StaticBrake.hpp:106
StaticBrake()
Applies full neutral-brake by shorting motor leads together.
Definition: StaticBrake.hpp:79
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: StaticBrake.hpp:119
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: StaticBrake.hpp:60
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: StaticBrake.hpp:73
StaticBrake & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: StaticBrake.hpp:96
Definition: ManualEvent.hpp:12